1 x = 1: y = 2 2 for i = 1 to 100 3 x = x + 1 / i 4 y = y + 1 / i 5 next i program 1 |
1 x = 1: y = 2 2 for i = 1 to 100 3 x = x + 1 / i 4 y = x + y + 1 / i 5 next i program 2 |
1 x = 1 2 for i = 1 to 100 3 x = x + 1 / i 4 next i program 3 |
1 y = 2 2 for i = 1 to 100 3 y = y + 1 / i 4 next i program 4 |
1 x1(0) = a(0,0) * x0(0) + a(0,1) * x0(1) + a(0,2) * x0(2) 2 x1(1) = a(1,0) * x0(0) + a(1,1) * x0(1) + a(1,2) * x0(2) 3 x1(2) = a(2,0) * x0(0) + a(2,1) * x0(1) + a(2,2) * x0(2) 4 x0(0) = x1(0) X0(1) = x1(1) x0(2) = x1(2) |
The Visual Basic program which does that, is the following:
1 x0(0) = ? x0(1) = ? x0(2) = ? a(0,0) = ? etc 2 DO 3 For i = 0 to 2 4 x1(i) = 0 5 For j = 0 to 2 6 x1(i) = x1(i) + a(i,j) * x0(j) 7 next j 8 next i 9 For i = 0 to 2 : x0(i) = x1(i) : next i 10 LOOP UNTIL ? |
The following Visual Basic program shows how this is done in slave processor 2.
1 i = 2 2 DO 3 If state(i) = 1 then ' request from Master 4 x1(i) = 0 5 For j = 0 to 2 6 x1(i) = x1(i) + a(i,j) * x0(j) 7 next j 8 End If 9 state(i) = 2 ' done 10 LOOP UNTIL ? |
The rules involved are:
Master np = npreq Start Loop Set all STATE array variables equal to 1 perform calculations STATE(1) = 0 Wait all STATE array variables equal to 0 End Loop |
Slave 1 Start Loop If STATE(2) = 1 Then perform calculations STATE(2) = 0 End if End LOOP |
Figure 2: Synchronization |
Master np = npreq Start Slave 1, 2 Start Loop Set all STATE variables equal to 1 For i = 0 to maxi step np perform calculations next i STATE(1) = 0 Wait all STATE variables equal to 0 End Loop |
Slave 1 Start Loop If STATE(2) = 1 Then For i = 1 to maxi step np perform calculations next i STATE(2) = 0 End if End LOOP |
Slave 2 Start Loop If STATE(3) = 1 Then For i = 1 to maxi step np perform calculations next i STATE(3) = 0 End if End LOOP |
Figure 3: Load Sharing |
There are two types of cancel requests:
There are two types of hold requests:
**************** (1) ---------------------- *StartButton EH*--------------- | (4) | **************** | | | V V | ********** ********* **************** (3) ******* -->* * ******* * Slave * * NProcT EH *----->*npreq*----->* Master *----->* np *---->* * **************** (6) ******* -->* * ******* * BGW * | ********** ********* **************** (9) ******** | (2)(4)(7)(10) (5)(8) * EndButton EH *---->*cancel*-- **************** ******** Figure 4: Communication channels |
The sleep function is way to temporarily stop program (Backgroundworker) operation.
The full statement is: System.Threading.Thread.Sleep(1) . The 1 means 1 m second. In general n means n m second.
The sleep function in the programs Planet and PlanetPP are used in the Hold mode.
The DOEvents function is not used in the Slave Backgroundworkers in those DO LOOPs.
In the PlanetPP program in the Master is implemented as subroutine which is called in the StartAsyncButton Event Handler. The Master Subroutine requires two WAIT functions that means two DO LOOP statements. Each of those loops require the DOEvents statement for proper operation. In the Debug mode they are not required !. The same for the FibonacciPP program, but only once.
The planetS program requires one DOEvents function.
The Planet program does require the DOEvents function because the Master is implemented as a BackGroundWorker.
However the program requires a piece of what is called "dead code". This code is only the END statement and is required within the DO LOOP statements of the Master BackGroundWorker, If you remove the END statement the program works in the Debug mode, but not in the Publish mode. This all seems rather strange but it is true. The reason is unknown.
Created: 14 January 2010
Updated: 10 August 2012
Back to my home page Contents of This Document