Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parallel Fox: Performance Not Increased Greatly
Message
From
27/01/2014 13:38:10
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01592451
Message ID:
01592457
Views:
104
Thanks, I have made correction accordingly. But was not the limiting factor for my speed. I found it to be Parallel.Wait(.T.).
If I remove Parallel.Wait(.T.) from my code, the speed becomes four fold. But Parallel.Wait is required as it halts the program until the entire process on all CPU is completed.

I think that Parallel.Wait(.T.) is to be written/put somewhere else in code.

Here is the detail about Parallel.Wait(.T.) from Parallelfox Documentation. Can you please suggest something on this basis


parallel::Wait
Wait until workers have finished processing queued commands.
Parallel.Wait([lAllWorkers])
Parameters
lAllWorkers (optional)
By default, wait only for commands sent from the current instance of the Parallel object.
Pass .T. to wait for commands from ALL instances of the Parallel object.


Remarks
It is possible for commands to be sent to workers from multiple instances of the Parallel object. For example, a long-running background process started with one instance of Parallel may be running on one worker. While that is running, the user may start another program (with a separate instance of Parallel) that does parallel processing on the remaining workers. Parallel.Wait() is scoped to the current instance of the Parallel object, and that is usually what you want. If for some reason, you want to wait until all commands from all instances are complete, pass .T. to the method.

Example
For i = 1 to 100
Parallel.Do("MyProgram",,,i)
EndFor
* Wait until commands are complete
Parallel.Wait()
* Continue rest of program in main process











Harsh, I've never used ParallelFox, but there is something that does not look good to me in your code, like setting the worker count and binding the events inside the scan loop, and also I would set the number of workers before starting them, seems more reasonable, the MainProcess would look like this:
>
>
>PROCEDURE Mainprocess
>	Local Parallel as Parallel
>	
>	Parallel = NewObject("Parallel", "ParallelFox.vcx")
>	Parallel.SetWorkerCount(Parallel.CPUCount)
>	Parallel.BindEvent("UpdateProgress", _Screen.oMyHandler, "DisplayProgress")
>	Parallel.StartWorkers()
>
>	SCAN
>		iFilename=ALLTRIM(Fullpath)
>		oFilename=ALLTRIM(Newpath)
>		RCNON=RCNO
>		*Parallel.do("PS2PDF",'convert.prg',,iFilename,oFilename)
>		Parallel.CallMethod("ps2pdf", This.Class, This.ClassLibrary,,,iFilename,oFilename,RCNON)
>	ENDSCAN
>
>	Parallel.Wait(.T.)
>	Parallel.StopWorkers()
>ENDPROC
>
>
>>I have incorporated Parallel Fox in my VFP Code. Using a Single core in my I7 Machine I am able to process 2000 Records in 123 Seconds. Using parallel fox and using all cores of my CPU (i.e 8) I can do the same job with 96 Seconds.
>>
>>Seems not very great performance using 7 more Cores. Any body having idea, please throw light on the issue.
>>
>>Here is my code.
>>
>>
>>nRECCOUNTCONVERT=ALLTRIM(STR(RECCOUNT()))
>>cRECCOUNTCONVERT=' of '+ALLTRIM(STR(RECCOUNT()))
>>
>>T1=TIME()
>>Local loMyObject
>>loMyObject = CreateObject("MyObject")
>>_Screen.AddObject("oMyHandler", "MyHandler")
>>loMyObject.Mainprocess()
>>T2=TIME()
>>WAIT WINDOW T2-T1
>>Return
>>
>>Define Class MyHandler as Custom
>>Procedure DisplayProgress
>>Lparameters lnPercent, lcMessage
>>_VFP.StatusBar =  " ("  + "%)"
>>EndProc 
>>EndDefine 
>>
>>DEFINE CLASS MyObject AS Custom
>>PROCEDURE Mainprocess
>>Local Parallel as Parallel
>>Parallel = NewObject("Parallel", "ParallelFox.vcx")
>>Parallel.StartWorkers()
>>SCAN
>>iFilename=ALLTRIM(Fullpath)
>>oFilename=ALLTRIM(Newpath)
>>RCNON=RCNO
>>Parallel.SetWorkerCount(Parallel.CPUCount)
>>Parallel.BindEvent("UpdateProgress", _Screen.oMyHandler, "DisplayProgress")
>>*Parallel.do("PS2PDF",'convert.prg',,iFilename,oFilename)
>>Parallel.CallMethod("ps2pdf", This.Class, This.ClassLibrary,,,iFilename,oFilename,RCNON)
>>ENDSCAN
>>Parallel.Wait(.T.)
>>Parallel.StopWorkers()
>>ENDPROC
>>** Convert ps files to PDF Using ps2PDF.Dll
>>PROCEDURE ps2PDF
>>PARAMETERS iFilename,oFilename,RCNON
>>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
>>id=apCreate()
>>IF (id # 0)
>>apSetFunc(id, AP_Set_Input , 0, 0,iFilename, 0)  &&input file.
>>apSetFunc(id, AP_Set_Output, 0, 0,oFilename, 0) &&output format and file.
>>apConvert(id)
>>apClose(id)
>>Sys(2335, 1)	&& disable unattended mode, allow UI
>>WAIT WINDOW RCNON NOWAIT
>>*Worker.UpdateProgress(RECNO(), "Converting..")
>>ENDIF
>>ENDPROC
>>ENDDEFINE
>>
>>
>>
>>
>>
>>
Harsh
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform