Upload
yoko
View
24
Download
1
Embed Size (px)
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
A Concurrent Matrix A Concurrent Matrix Transpose Algorithm, Transpose Algorithm, The The
VerificationVerification
PresentedPresented
byby
Pourya JafariPourya Jafari
Algorithm Review: Determine Algorithm Review: Determine preprocessingpreprocessing
Intra-process shift = row indexIntra-process shift = row index
After Intra-process; every column index is After Intra-process; every column index is equal to original row index equal to original row index j” = j + i’ = i j” = j + i’ = i i’: Row index after pre-processing i’ = i - Li’: Row index after pre-processing i’ = i - L i - L + j = i i - L + j = i
Now we can determine preprocess shift-up L = - j Now we can determine preprocess shift-up L = - j
Algorithm Review: Determine Post Algorithm Review: Determine Post ProcessingProcessing
Change of indices so farChange of indices so far (i - j, j) → (i - j, i - j + j) → (i - j, i) = (m, n)(i - j, j) → (i - j, i - j + j) → (i - j, i) = (m, n)
One operation to change row index to jOne operation to change row index to j n - m = (i - (i - j))= jn - m = (i - (i - j))= j
Algorithm Review: : All StepsAlgorithm Review: : All Steps
Pre-process inside Pre-process inside each threadeach thread Shift rowsShift rows
Intra-process/thread Intra-process/thread communicationcommunication Shift columnsShift columns
Post-process inside Post-process inside each threadeach thread Shift rows againShift rows again
0000 0101 0202 0303
1010 1111 1212 1313
2020 2121 2222 2323
3030 3131 3232 3333
0000 1010 2020 3030
0101 1111 2121 3131
0202 1212 2222 3232
0303 1313 2323 3333
0000 1111 2222 3333
0303 1010 2121 3232
0202 1313 2020 3131
0101 1212 2323 3030
0000 1111 2222 3333
1010 2121 3232 0303
2020 3131 0202 1313
3030 0101 1212 2323
0000 1111 2222 3333
1010 2121 3232 0303
2020 3131 0202 1313
3030 0101 1212 2323
UML DiagramUML Diagram
-PID : int-N : int-ch0 : One2OneChannel-ch1 : Any2OneChannel-ch2 : One2AnyChannel
CProcess
+run()
CSProcess
+In()+Out()
One2OneChannel
+In()+Out()
One2AnyChannel
+In()+Out()
Any2OneChannel
-N : int-ch1 : Any2OneChannel-ch2 : One2AnyChannel
MProcess -N : int-ch0 : One2OneChannel-ch1 : Any2OneChannel-ch2 : One2AnyChannel-CPs : CSProcess
Launcher
CProcess: Heart of ConcurrencyCProcess: Heart of Concurrency
Might send/receive multiple itemsMight send/receive multiple items Determines the indices that need to be shifted Determines the indices that need to be shifted Packs them in form of a messagePacks them in form of a message Sends the message to the next CProcess and Sends the message to the next CProcess and
receive from the previous process in the shift receive from the previous process in the shift chainchain
Unpack the received messageUnpack the received message Assign the items inside to the same indices Assign the items inside to the same indices
determined in the first stepdetermined in the first step
Running Launcher under JPFRunning Launcher under JPF
navy 310 % jpf -c ./jpf.properties Launcher | moreJavaPathfinder v4.1 - (C) 1999-2007 RIACS/NASA Ames Research Center
============================= system under testapplication: /cs/home/pourya/6490/Launcher.java
============== search started: 11/27/07 1:24 PMLauncher : start threadsCProcess 0: startsCProcess 1: startsMProcess : initate intraprocess stage
CProcess 0: finished step 0CProcess 0: 0 0CProcess 0: 1 1000000CProcess 0: done!CProcess 1: finished step 0CProcess 1: 0 1CProcess 1: 1 1000001
CProcess 1: done!MProcess : done!
Launcher : all threads done!
========================== error #1gov.nasa.jpf.jvm.NotDeadlockedPropertydeadlock encountered: thread index=0,name=main,status=TERMINATED,this=null,target=null,priority=5,lockCount=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
Simple JCSP testSimple 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 JPFSimple JCSP test under JPF
navy 313 % jpf -c ./jpf.properties test | moreJavaPathfinder v4.1 - (C) 1999-2007 RIACS/NASA Ames Research Center
====================================================== system under testapplication: /cs/home/pourya/6490/test.java====================================================== search started: 11/27/07 1:43 PMTCSP done!
TCSP done!
Test done!
====================================================== error #1gov.nasa.jpf.jvm.NotDeadlockedPropertydeadlock encountered: thread index=0,name=main,status=TERMINATED,this=null,target=null,priority=5,lockCount=0 thread index=1,name=TCSP@ab6c,status=WAITING,this=org.jcsp.lang.ParThread@177,priority=5,lockCount=1====================================================== trace #1
Deadlock causeDeadlock cause
Threads are still alive at least under JPF Threads are still alive at least under JPF environmentenvironment
We should force thread termination the We should force thread termination the end of runend of run
Two solutionsTwo solutions System.exit(0) in the end of MProcessSystem.exit(0) in the end of MProcess Use release mechanism in Parallel under Use release mechanism in Parallel under
JCSP: releaseAllThreads();JCSP: releaseAllThreads();
Modification to test and ResultsModification 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 testapplication: /cs/home/pourya/6490/test.java======== search started: 11/27/07 1:06 PMTCSP done!
TCSP done!
Test done!Test done!...TCSP done!
Test done!
================================== resultsno errors detected=================inished: 11/27/07 1:06 PM
Verifying LauncherVerifying Launcher
No deadlocks after the releaseThread fixNo deadlocks after the releaseThread fix
Precision Racing TestPrecision Racing Test No racing warning or errorsNo racing warning or errors
Underlying mechanisms in JCSP use synchronized Underlying mechanisms in JCSP use synchronized blocksblocks
Functional verification?Functional verification?
Functional verificationFunctional verification
Each thread initially generate values using Each thread initially generate values using following line of codefollowing line of code
After transpose the first and last digit will After transpose the first and last digit will be swappedbe swapped
for(int i=0; i<N; i++)column[i] = PID*1000000 + i;
We use a for-loop which sets a Boolean We use a for-loop which sets a Boolean value and, then a assertion to verify value and, then a assertion to verify resultsresults
Boolean correctSoFar = true;
for(i=0; i<N && correctSoFar; i++){
if (column[i] != i*1000000 + PID)correctSoFar = false;
}assert (correctSoFar) : "CProcess value incorrect”);
Final ResultsFinal Results
navy 310 % jpf -c ./jpf.properties Launcher | moreJavaPathfinder v4.1 - (C) 1999-2007 RIACS/NASA Ames Research Center
============================= system under testapplication: /cs/home/pourya/6490/Launcher.java
============== search started: 11/27/07 1:35 PMLauncher : start threadsCProcess 0: startsCProcess 1: startsMProcess : initate intraprocess stage
CProcess 0: finished step 0CProcess 0: 0 0CProcess 1: startsCProcess 1: startsCProcess 1: startsCProcess 0: startsCProcess 0: starts
CProcess 1: done!MProcess : done!
Launcher : all threads done!..CProcess 1: startsCProcess 1: startsCProcess 1: startsCProcess 1: startsCProcess 0: startsCProcess 0: startsCProcess 0: startsCProcess 0: startsCProcess 0: starts
============================================ resultsno errors detected
================== search finished: 11/27/07 1:37 PM
Future workFuture work
We could break the cycle on a first-come We could break the cycle on a first-come first-served basisfirst-served basis
Locking mechanism neededLocking mechanism needed Racing might rise with a faulty lockRacing might rise with a faulty lock
Racing verification requiredRacing verification required
76543210 8