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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
package mpi.perf ;
import mpi.*;
public class WaitAnyKiller {
public static int NUM = 1000 ;
public static int NRA=NUM; /* number of rows in matrix A */
public static int NCA=NUM; /* number of columns in matrix A */
public static int NCB=NUM; /* number of columns in matrix B */
static final int loops = 500 ;
Thread threadA = null ;
final byte[][] recvArray = new byte[loops][1] ;
final byte[][] sendArray = new byte[loops][1] ;
public static void main(String args[]) throws Exception {
WaitAnyKiller matrixCalc = new WaitAnyKiller(args) ;
}
public WaitAnyKiller() {
}
public WaitAnyKiller (String args[]) throws Exception {
System.out.println("starting wait any killler" );
//System.setProperty("ibis.name","nio") ;
int rank ;
int size ;
int partner ;
int tag = 998 ;
int l,m,n ;
//for(l=0 ; l<loops ; l++) {
//sendArray[l] = new byte[1] ;
//recvArray[l] = new byte[1] ;
//}
MPI.Init(args) ;
System.out.println("Name ="+MPI.Get_processor_name());
rank = MPI.COMM_WORLD.Rank() ;
size = MPI.COMM_WORLD.Size() ;
//partner = (rank == 0 ? 1 : 0) ;
if(rank == 0) {
Runnable waitAnyThread = new Runnable() {
public void run() {
try {
Request [] request = new Request[loops] ;
int l=0 ;
//for(int l=0 ; l<loops ; l++) {
request[l] = MPI.COMM_WORLD.Irecv(recvArray[l],0,1,MPI.BYTE,1,l);
//}
System.out.println(" Process 0 calling waitAny") ;
//request[0].Wait() ;
Request.Waitany(request) ;
System.out.println(" Process 1 called waitAny") ;
} catch(MPIException e){
e.printStackTrace() ;
}
}
};
threadA = new Thread(waitAnyThread) ;
threadA.start() ;
int numtasks, /* number of tasks in partition */
taskid, /* a task identifier */
numworkers, /* number of worker tasks */
source, /* task id of message source */
dest, /* task id of message destination */
nbytes, /* number of bytes in message */
mtype, /* message type */
rows, /* rows of matrix A sent to each worker */
averow, extra, offset, /* used to determine rows sent to each worker */
i, j, k, /* misc */
count;
double a[][] = new double[NRA][];//NCA /* matrix A to be multiplied */
double b[][] = new double[NCA][];//NCB /* matrix B to be multiplied */
double c[][] = new double[NRA][];//NCB /* result matrix C */
for (i=0; i<NRA; i++) {
a[i] = new double[NCA];
for (j=0; j<NCA; j++) {
a[i][j]= i+j;
}
}
for (i=0; i<NCA; i++) {
b[i] = new double[NCB];
for (j=0; j<NCB; j++) {
b[i][j]= i*j;
}
}
for (i=0; i<NRA; i++) {
c[i] = new double[NCB];
for (j=0; j<NCB; j++) {
c[i][j]= 0d;
}
}
long start = System.nanoTime() ;
/* Compute */
for (k=0; k<NCB; k++) {
for (i=0; i<NRA; i++) {
c[i][k] = 0.0;
for (j=0; j<NCA; j++)
c[i][k] = c[i][k] + a[i][j] * b[j][k];
}
}
long stop = System.nanoTime() ;
System.out.println("time ="+ ((double)stop-start)/(1000*1000*1000));
MPI.COMM_WORLD.Barrier() ;
threadA.join() ;
} else if(rank == 1) {
MPI.COMM_WORLD.Barrier() ;
l =0 ;
//for(l=0 ; l<loops ; l++) {
MPI.COMM_WORLD.Send(sendArray[l],0,1,MPI.BYTE,0,l);
//}
}
MPI.Finalize() ;
}
}//end of class
|