forked from VFPX/ParallelFox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_batch.prg
More file actions
79 lines (68 loc) · 1.87 KB
/
Copy pathvalidate_batch.prg
File metadata and controls
79 lines (68 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
* Validate USA orders in batches
Set Path To "..;EXAMPLES" Additive
Local loOrder, lcTempTable, lnBatchSize
Local Parallel as Parallel
Parallel = NewObject("Parallel", "ParallelFox.vcx")
* Get USA order data
Set Exclusive Off
Select * from Home() + "Samples\Northwind\orders.dbf" ;
where shipcountry = "USA" ;
into cursor USAOrders
Wait "Starting workers..." Window Nowait
Parallel.StartWorkers(FullPath("validate_batch.prg"))
Wait "Validating orders..." window nowait
Select USAOrders
* Create temp table
lcTempTable = Parallel.CreateTempTable("USAOrders")
* Open temp table in all workers
Parallel.Call("OpenTempTable", .t., lcTempTable)
* Validate a batch of records with each call
lnBatchSize = 10
For lnRecord = 1 to Reccount() Step (lnBatchSize)
Parallel.Call("ValidateBatch",,lnRecord, lnRecord + lnBatchSize - 1)
EndFor
Use in Select("USAOrders")
Use in Select("Orders")
* Close temp table in all workers
Parallel.Call("CloseTempTable", .t., "USAOrders")
Parallel.Wait()
Parallel.StopWorkers()
* Clean up - delete temp table
Parallel.DeleteTempTable(lcTempTable)
Wait clear
MessageBox("Code Complete.")
Procedure OpenTempTable
Lparameters lcTempTable
Set Exclusive Off
Use in Select("USAOrders")
Local Worker as Worker
Worker = NewObject("Worker", "ParallelFox.vcx")
Worker.OpenTempTable(lcTempTable, "USAOrders")
EndProc
Procedure ValidateBatch
Lparameters lnStartRecord, lnEndRecord
Local loRecord
Select USAOrders
Go lnStartRecord
Scan while Recno() <= lnEndRecord
Scatter Name loOrder Memo
ValidateOrder(loOrder)
EndScan
EndProc
Procedure ValidateOrder
Lparameters loOrder
* Simulate validation
SimulateWork()
EndProc
Procedure CloseTempTable
Lparameters lcAlias
Local Worker as Worker
Worker = NewObject("Worker", "ParallelFox.vcx")
Worker.CloseTempTable(lcAlias)
EndProc
Procedure SimulateWork
Local i
For i = 1 to 10000000
* Peg CPU
EndFor
EndProc