A Concurrent Matrix Transpose Algorithm The Verification Presented
















- Slides: 16
A Concurrent Matrix Transpose Algorithm, The Verification Presented by Pourya Jafari
Algorithm Review: Determine preprocessing Intra-process shift = row index After Intra-process; every column index is equal to original row index n n n j” = j + i’ = i i’: Row index after pre-processing i’ = i - L i-L+j=i Now we can determine preprocess shift-up L = - j
Algorithm Review: Determine Post Processing Change of indices so far n (i - j, j) → (i - j, i - j + j) → (i - j, i) = (m, n) One operation to change row index to j n n - m = (i - j))= j
Algorithm Review: : All Steps Pre-process inside each thread n Shift rows Intra-process/thread communication n Shift columns Post-process inside each thread n Shift rows again 00 01 02 03 00 11 22 33 10 11 12 13 10 21 32 03 20 21 22 23 20 31 02 13 30 31 32 33 30 01 12 23 00 11 22 33 10 21 32 03 03 10 21 32 20 31 02 13 20 31 30 01 12 23 30 00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
UML Diagram
CProcess: Heart of Concurrency Might send/receive multiple items n n n Determines the indices that need to be shifted Packs them in form of a message Sends the message to the next CProcess and receive from the previous process in the shift chain Unpack the received message Assign the items inside to the same indices determined in the first step
Running Launcher under JPF navy 310 % jpf -c. /jpf. properties Launcher | more Java. Pathfinder v 4. 1 - (C) 1999 -2007 RIACS/NASA Ames Research Center =============== system under test application: /cs/home/pourya/6490/Launcher. java ======= search started: 11/27/07 1: 24 PM Launcher : start threads CProcess 0: starts CProcess 1: starts MProcess : initate intraprocess stage CProcess CProcess 0: 0: 1: 1: 1: finished step 0 0 0 1 1000000 done! finished step 0 0 1 1 1000001 CProcess 1: done! MProcess : done! Launcher : all threads done! ============= error #1 gov. nasa. jpf. jvm. Not. Deadlocked. Property deadlock encountered: thread index=0, name=main, status=TERMINATED, this=null, target=null, priority=5, lock. C ount=0 thread index=1, name=CProcess@ab 6 b, status=WAITING, this=org. jcsp. la ng. Par. Thread@518 , priority=5, lock. Count=1 thread index=2, name=CProcess@aa 76, status=WAITING, this=org. jcsp. la ng. Par. Thread@550 , priority=5, lock. Count=1 ============= trace #1
Simple JCSP test import org. jcsp. lang. *; Public class test { public static void main(String[] args) { public class TCSP implements CSProcess { public TCSP(){ } new Parallel { new CSProcess[] { new TCSP(), new TCSP() } ). run(); System. out. print("Test done!n"); } } //@Override public void run() { System. out. printf("TCSP done!n"); } }
Simple JCSP test under JPF navy 313 % jpf -c. /jpf. properties test | more Java. Pathfinder v 4. 1 - (C) 1999 -2007 RIACS/NASA Ames Research Center =========================== system under test application: /cs/home/pourya/6490/test. java =========================== search started: 11/27/07 1: 43 PM TCSP done! Test done! =========================== error #1 gov. nasa. jpf. jvm. Not. Deadlocked. Property deadlock encountered: thread index=0, name=main, status=TERMINATED, this=null, target=null, priority=5, loc k. C ount=0 thread index=1, name=TCSP@ab 6 c, status=WAITING, this=org. jcsp. lang. Par. Thread@177, p ri ority=5, lock. Count=1=========================== = trace #1
Deadlock cause Threads are still alive at least under JPF environment We should force thread termination the end of run Two solutions n n System. exit(0) in the end of MProcess Use release mechanism in Parallel under JCSP: release. All. Threads();
Modification to test and Results import org. jcsp. lang. *; class test { public static void main(String[] args) { Parallel P = new Parallel ( new CSProcess[] { new TCSP(), new TCSP() } ); P. run(); System. out. print("Test done!n"); P. release. All. Threads(); } } navy 317 % jpf -c. /jpf. properties test Java. Pathfinder v 4. 1 - (C) 1999 -2007 RIACS/NASA Ames Research Center =========== system under test application: /cs/home/pourya/6490/test. java ==== search started: 11/27/07 1: 06 PM TCSP done! Test done!. . . TCSP done! Test done! ================= results no errors detected =========inished: 11/27/07 1: 06 PM
Verifying Launcher No deadlocks after the release. Thread fix Precision Racing Test n No racing warning or errors Underlying mechanisms in JCSP use synchronized blocks Functional verification?
Functional verification Each thread initially generate values using following line of code for(int i=0; i<N; i++) column[i] = PID*1000000 + i; After transpose the first and last digit will be swapped
We use a for-loop which sets a Boolean value and, then a assertion to verify results Boolean correct. So. Far = true; for(i=0; i<N && correct. So. Far; i++) { if (column[i] != i*1000000 + PID) correct. So. Far = false; } assert (correct. So. Far) : "CProcess value incorrect”);
Final Results navy 310 % jpf -c. /jpf. properties Launcher | more Java. Pathfinder v 4. 1 - (C) 1999 -2007 RIACS/NASA Ames Research Center =============== system under test application: /cs/home/pourya/6490/Launcher. java ======= search started: 11/27/07 1: 35 PM Launcher : start threads CProcess 0: starts CProcess 1: starts MProcess : initate intraprocess stage CProcess CProcess 0: 0: 1: 1: 1: 0: 0: finished step 0 0 0 starts starts CProcess 1: done! MProcess : done! Launcher. . CProcess CProcess CProcess : all threads done! 1: 1: 0: 0: 0: starts starts starts ====================== results no errors detected ========= search finished: 11/27/07 1: 37 PM
Future work We could break the cycle on a first-come first-served basis Locking mechanism needed n Racing might rise with a faulty lock Racing verification required