2014-05-21 01:47:45 +04:00
|
|
|
import shmem.*;
|
|
|
|
import java.nio.*;
|
|
|
|
|
|
|
|
public class oshmem_max_reduction
|
|
|
|
{
|
|
|
|
private static final int N = 3;
|
|
|
|
|
|
|
|
public static void main(String[] args) throws ShMemException
|
|
|
|
{
|
|
|
|
ShMem.startPEs(0);
|
|
|
|
|
|
|
|
int numPEs = ShMem.getNumPEs(),
|
|
|
|
myPE = ShMem.getMyPE();
|
|
|
|
|
2014-06-01 19:09:30 +04:00
|
|
|
Addr src = new Addr(8 * N), // long is 8 bytes.
|
|
|
|
dst = new Addr(8 * N),
|
|
|
|
pWrk = new Addr(8 * ShMem.REDUCE_SYNC_SIZE);
|
|
|
|
PSync pSync = new PSync(ShMem.BCAST_SYNC_SIZE);
|
2014-05-21 01:47:45 +04:00
|
|
|
|
2014-06-01 19:09:30 +04:00
|
|
|
LongBuffer srcBuf = src.asLongBuffer(),
|
|
|
|
dstBuf = dst.asLongBuffer();
|
2014-05-21 01:47:45 +04:00
|
|
|
|
|
|
|
for(int i = 0; i < N; i++)
|
|
|
|
srcBuf.put(i, myPE + i);
|
|
|
|
|
|
|
|
ShMem.barrierAll();
|
|
|
|
dst.maxToAllLong(src, N, 0, 0, numPEs, pWrk, pSync);
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(myPE +"/"+ numPEs +" dst =");
|
|
|
|
|
|
|
|
for(int i = 0; i < N; i++)
|
|
|
|
sb.append(" "+ dstBuf.get(i));
|
|
|
|
|
|
|
|
sb.append("\n");
|
|
|
|
System.out.print(sb);
|
|
|
|
|
|
|
|
src.free();
|
|
|
|
dst.free();
|
|
|
|
pWrk.free();
|
|
|
|
pSync.free();
|
|
|
|
}
|
|
|
|
}
|