Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Implementing Parallel Fox in My Application
Message
De
29/12/2013 12:55:16
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Implementing Parallel Fox in My Application
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01591059
Message ID:
01591059
Vues:
127
I am trying to incorporate Parallax Fox Code in my application, but not able to do so properly.

I have spit my table in Five parts and trying to run each part parallel to get output at the earliest.

I Have a Example of parallel Fox, but not able to implement it properly.

When I am executing my code nothing is happening . kindly Guide.

Here is my code.
nINTCONVERT=INT(RECCOUNT()/5)
Select * FROM Convert INTO CURSOR ConvertOne Where RECNO()>0 AND RECNO()<nINTCONVERT+1 READWRITE
Select * FROM Convert INTO CURSOR ConvertTwo Where RECNO()>nINTCONVERT AND RECNO()<(nINTCONVERT*2)+1 READWRITE
Select * FROM Convert INTO CURSOR ConvertThree Where RECNO()>(nINTCONVERT*2) AND RECNO()<(nINTCONVERT*3)+1 READWRITE
Select * FROM Convert INTO CURSOR ConvertFour Where RECNO()>(nINTCONVERT*3) AND RECNO()<(nINTCONVERT*4)+1 READWRITE
Select * FROM Convert INTO CURSOR ConvertFive Where RECNO()>(nINTCONVERT*4) AND RECNO()<RECCOUNT()+1 READWRITE
Local Parallel as Parallel of ParallelFox.vcx
Parallel = NewObject("Parallel", "ParallelFox.vcx")
Parallel.StartWorkers(FullPath("Convert.prg"),,.t.)
Parallel.Do("StepOne")
Parallel.Do("StepTwo")
Parallel.Do("StepThree")
Parallel.Do("StepFour")
DO StepFive
Parallel.StopWorkers()

PROCEDURE Stepone
** Convert ps files to PDF Using ps2PDF.Dll
DECLARE INTEGER _apCreate@0   IN ps2pdf.dll AS apCreate
DECLARE         _apClose@4    IN ps2pdf.dll AS apClose   INTEGER id
DECLARE INTEGER _apConvert@4  IN ps2pdf.dll AS apConvert INTEGER id
DECLARE INTEGER _apSetFunc@24 IN ps2pdf.dll AS apSetFunc INTEGER id, INTEGER code, INTEGER nOptVal1, INTEGER nOptVal2, STRING pOptVal1, STRING pOptVal2
DECLARE INTEGER _apGetFunc@24 IN ps2pdf.dll AS apGetFunc INTEGER id, INTEGER code, INTEGER nOptVal1, INTEGER nOptVal2, STRING pOptVal1, STRING pOptVal2
#define AP_Set_Output     3000
#define AP_Set_Input      3001
SELECT ConvertOne
SCAN
id = apCreate()
IF (id # 0)
iFilename=ALLTRIM(Fullpath)
oFilename=ALLTRIM(Newpath)
apSetFunc(id, AP_Set_Input , 0, 0, m.iFilename , 0)  &&input file.
apSetFunc(id, AP_Set_Output, 0, 0,m.oFilename , 0) &&output format and file.
iRet = apConvert(id)
ENDIF
WAIT WINDOW 'Converting to PDF...'+ALLTRIM(STR(RECNO())) Nowait
apClose(id)
ENDSCAN


PROCEDURE STEPTWO
* SAME AS ABOVE, JUST TABLE NAME IS CHANGED
PROCEDURE STEPTHREE
* SAME AS ABOVE, JUST TABLE NAME IS CHANGED
Here is the original Code as Provided in Parallel Fox Example
* Steps example
Local lnTimer, lnUnits
Set Path To "..;examples" Additive 
Local Parallel as Parallel of ParallelFox.vcx
Parallel = NewObject("Parallel", "ParallelFox.vcx")

Parallel.StartWorkers(FullPath("Steps_After.prg"),,.t.)

Clear 
Erase StepsLog.DBF
Create Table StepsLog (cProgram C(20), nUnits I, nSeconds N(8,2))

lnTimer = Seconds()

? "Running Step 1..."
lnUnits = Step1(4)
? "Running Step 2..."
Parallel.Do("Step2",,,lnUnits)
? "Running Step 3..."
Parallel.Do("Step3",,,lnUnits)
? "Running Step 4..."
Parallel.Do("Step4",,,lnUnits)
Parallel.Wait()
? "Running Step 5..."
Do Step5 with lnUnits

? "Total Time", Seconds() - lnTimer

If !Used("StepsLog")
	Use StepsLog In 0
EndIf 	
Select StepsLog
Browse Last NoCaption NORMAL 
Use 

Parallel.StopWorkers()

Procedure SimulateWork
	Local i

	For i = 1 to 1000000
		* Peg CPU
	EndFor
EndProc 

* Count units of work that can be done in specified seconds
Function Step1(lnSeconds)
	Local lnTimer, lnUnits

	lnUnits = 0
	lnTimer = Seconds()
	Do while Seconds() - lnTimer < lnSeconds
		lnUnits = lnUnits + 1 
		SimulateWork()
	EndDo 

	LogResults(Program(), lnUnits, Seconds() - lnTimer)
	Return lnUnits
EndFunc 

* Run twice as many units
Procedure Step2
	Lparameters lnUnits
	Local lnTimer, i, lnTotalUnits
	? Program()	
	lnTimer = Seconds()
	lnTotalUnits = lnUnits * 2
	For i = 1 to lnTotalUnits
		SimulateWork()	
	EndFor 

	LogResults(Program(), lnTotalUnits, Seconds() - lnTimer)
EndProc 

* Run half as many units
Procedure Step3
	Lparameters lnUnits
	Local lnTimer, i, lnTotalUnits
	? Program()	
	lnTimer = Seconds()
	lnTotalUnits = Round(lnUnits/2, 0)
	For i = 1 to lnTotalUnits
		SimulateWork()	
	EndFor 

	LogResults(Program(), lnTotalUnits, Seconds() - lnTimer)
EndProc 

* Run 1.5X units plus 2
Procedure Step4
	Lparameters lnUnits
	Local lnTimer, i, lnTotalUnits
	? Program()	
	lnTimer = Seconds()
	lnTotalUnits = Round(lnUnits * 1.5, 0) + 2
	For i = 1 to lnTotalUnits
		SimulateWork()	
	EndFor 

	LogResults(Program(), lnTotalUnits, Seconds() - lnTimer)
EndProc 

* Add up all previous units and divide by 3
Procedure Step5
	Lparameters lnUnits
	Local lnTimer, i, lnTotalUnits
	
	lnTimer = Seconds()

	Select Sum(lnUnits) as TotalUnits from StepsLog into cursor TotalUnits
	lnTotalUnits = Round(TotalUnits.TotalUnits/3, 0)
	Use in TotalUnits
	For i = 1 to lnTotalUnits
		SimulateWork()
	EndFor 

	LogResults(Program(), lnTotalUnits, Seconds() - lnTimer)
EndProc 

Procedure LogResults
	Lparameters lcProgram, lnUnits, lnSeconds

	If !Used("StepsLog")
		Use StepsLog In 0
	EndIf 	
	Append Blank in StepsLog
	Replace cProgram with lcProgram, nUnits with lnUnits, nSeconds with lnSeconds in StepsLog	
	Use in StepsLog
EndProc 
Harsh
Répondre
Fil
Voir

Click here to load this message in the networking platform