170 likes | 300 Vues
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 j” = j + i’ = i
E N D
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 • 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 • (i - j, j) → (i - j, i - j + j) → (i - j, i) = (m, n) • One operation to change row index to j • n - m = (i - (i - j))= j
Pre-process inside each thread Shift rows Intra-process/thread communication Shift columns Post-process inside each thread Shift rows again Algorithm Review: : All Steps
CProcess: Heart of Concurrency • Might send/receive multiple items • 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 CProcess 1: done! MProcess : done! Launcher : all threads done! ========================== error #1 gov.nasa.jpf.jvm.NotDeadlockedProperty deadlock encountered: thread index=0,name=main,status=TERMINATED,this=null,target=null,priority=5,lockC ount=0 thread index=1,name=CProcess@ab6b,status=WAITING,this=org.jcsp.lang.ParThread@518 ,priority=5,lockCount=1 thread index=2,name=CProcess@aa76,status=WAITING,this=org.jcsp.lang.ParThread@550 ,priority=5,lockCount=1 ========================= trace #1 navy 310 % jpf -c ./jpf.properties Launcher | more JavaPathfinder v4.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 0: finished step 0 CProcess 0: 0 0 CProcess 0: 1 1000000 CProcess 0: done! CProcess 1: finished step 0 CProcess 1: 0 1 CProcess 1: 1 1000001
Simple JCSP test import org.jcsp.lang.*; Public class test { public static void main(String[] args) { new Parallel { new CSProcess[] { new TCSP(), new TCSP() } ).run(); System.out.print("Test done!\n"); } } import org.jcsp.lang.*; public class TCSP implements CSProcess { public TCSP(){ } //@Override public void run() { System.out.printf("TCSP done!\n"); } }
Simple JCSP test under JPF navy 313 % jpf -c ./jpf.properties test | more JavaPathfinder v4.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! TCSP done! Test done! ====================================================== error #1 gov.nasa.jpf.jvm.NotDeadlockedProperty deadlock encountered: thread index=0,name=main,status=TERMINATED,this=null,target=null,priority=5,lockC ount=0 thread index=1,name=TCSP@ab6c,status=WAITING,this=org.jcsp.lang.ParThread@177,pri ority=5,lockCount=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 • System.exit(0) in the end of MProcess • Use release mechanism in Parallel under JCSP: releaseAllThreads();
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.releaseAllThreads(); } } navy 317 % jpf -c ./jpf.properties test JavaPathfinder v4.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! TCSP done! Test done! Test done! . . . TCSP done! Test done! ================================== results no errors detected =================inished: 11/27/07 1:06 PM
Verifying Launcher • No deadlocks after the releaseThread fix • Precision Racing Test • 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 • After transpose the first and last digit will be swapped for(int i=0; i<N; i++) column[i] = PID*1000000 + i;
We use a for-loop which sets a Boolean value and, then a assertion to verify results Boolean correctSoFar = true; for(i=0; i<N && correctSoFar; i++) { if (column[i] != i*1000000 + PID) correctSoFar = false; } assert (correctSoFar) : "CProcess value incorrect”);
Final Results navy 310 % jpf -c ./jpf.properties Launcher | more JavaPathfinder v4.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 0: finished step 0 CProcess 0: 0 0 CProcess 1: starts CProcess 1: starts CProcess 1: starts CProcess 0: starts CProcess 0: starts CProcess 1: done! MProcess : done! Launcher : all threads done! . . CProcess 1: starts CProcess 1: starts CProcess 1: starts CProcess 1: starts CProcess 0: starts CProcess 0: starts CProcess 0: starts CProcess 0: starts CProcess 0: 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 • Racing might rise with a faulty lock • Racing verification required