1
1
This commit was SVN r31844.
Этот коммит содержится в:
Oscar Vega-Gisbert 2014-05-20 21:47:45 +00:00
родитель 1f017344ad
Коммит c58900da95
6 изменённых файлов: 219 добавлений и 0 удалений

12
examples/Hello_oshmem.java Обычный файл
Просмотреть файл

@ -0,0 +1,12 @@
import shmem.*;
public class Hello_oshmem
{
public static void main(String[] args)
{
ShMem.startPEs(0);
int nproc = ShMem.getNumPEs();
int proc = ShMem.getMyPE();
System.out.println("Hello, world, I am "+ proc +" of "+ nproc);
}
}

54
examples/Ring_oshmem.java Обычный файл
Просмотреть файл

@ -0,0 +1,54 @@
import shmem.*;
public class Ring_oshmem
{
public static void main(String[] args) throws ShMemException
{
ShMem.startPEs(0);
int nproc = ShMem.getNumPEs();
int proc = ShMem.getMyPE();
Addr rbuf = new Addr(4); // One integer value.
rbuf.putInt(-1);
int message = 10;
// Calculate the PE number of the next process in the ring. Use the
// modulus operator so that the last process "wraps around" to PE 0.
int next = (proc + 1) % nproc;
if(proc == 0)
{
System.out.println("Process 0 puts message "+ message +" to "+
next +" ("+ nproc +" processes in ring)");
rbuf.putInt(message, next);
}
// Pass the message around the ring. The exit mechanism works as
// follows: the message (a positive integer) is passed around the
// ring. Each time it passes PE 0, it is decremented. When each
// processes receives a message containing a 0 value, it passes the
// message on to the next process and then quits. By passing the 0
// message first, every process gets the 0 message and can quit
// normally.
while(message > 0)
{
rbuf.waitUntilInt(ShMem.CMP_EQ, message);
if(proc == 0)
{
message--;
System.out.println("Process 0 decremented value: "+ message);
}
rbuf.putInt(message, next);
if(proc != 0)
message--;
}
// All done
rbuf.free();
System.out.println("Process "+ proc +" exiting");
}
}

24
examples/oshmem_circular_shift.java Обычный файл
Просмотреть файл

@ -0,0 +1,24 @@
import shmem.*;
public class oshmem_circular_shift
{
public static void main(String[] args) throws ShMemException
{
ShMem.startPEs(0);
int numPEs = ShMem.getNumPEs(),
myPE = ShMem.getMyPE(),
peer = (myPE + 1) % numPEs;
int[] aaa = new int[1];
Addr bbb = new Addr(4);
System.out.println("Process "+ myPE +" gets message from "+
peer +" ("+ numPEs +" processes in ring)");
bbb.getInt(aaa, 1, peer);
ShMem.barrierAll();
bbb.free();
System.out.println("Process "+ myPE +" exiting");
}
}

47
examples/oshmem_max_reduction.java Обычный файл
Просмотреть файл

@ -0,0 +1,47 @@
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();
Addr src = new Addr(8 * N), // long is 8 bytes.
dst = new Addr(8 * N),
pWrk = new Addr(8 * ShMem.REDUCE_SYNC_SIZE),
pSync = new Addr(8 * ShMem.BCAST_SYNC_SIZE);
LongBuffer srcBuf = src.asLongBuffer(),
dstBuf = dst.asLongBuffer(),
pSyncBuf = pSync.asLongBuffer();
for(int i = 0; i < ShMem.BCAST_SYNC_SIZE; i++)
pSyncBuf.put(i, ShMem.SYNC_VALUE);
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();
}
}

33
examples/oshmem_strided_puts.java Обычный файл
Просмотреть файл

@ -0,0 +1,33 @@
import shmem.*;
import java.nio.*;
public class oshmem_strided_puts
{
public static void main(String[] args) throws ShMemException
{
ShMem.startPEs(0);
int me = ShMem.getMyPE();
short[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Addr target = new Addr(2 * 10); // short is 2 bytes.
if(me == 0)
{
/* put 10 words into target on PE 1 */
target.iPutShort(source, 1, 2, 5, 1);
}
ShMem.barrierAll(); // sync sender and receiver
if(me == 1)
{
ShortBuffer buf = target.asShortBuffer();
System.out.printf("target on PE %d is %d %d %d %d %d\n", me,
buf.get(0), buf.get(1), buf.get(2),
buf.get(3), buf.get(4));
}
ShMem.barrierAll(); // sync before exiting
target.free();
}
}

49
examples/oshmem_symmetric_data.java Обычный файл
Просмотреть файл

@ -0,0 +1,49 @@
import shmem.*;
import java.nio.*;
public class oshmem_symmetric_data
{
private static final int SIZE = 16;
public static void main(String[] args) throws ShMemException
{
ShMem.startPEs(0);
int numPE = ShMem.getNumPEs(),
myPE = ShMem.getMyPE();
int[] source = new int[SIZE];
Addr target = new Addr(4 * SIZE); // int is 4 bytes
if(myPE == 0)
{
// initialize array
for(int i = 0; i < SIZE; i++)
source[i] = i;
// local, not symmetric
// static makes it symmetric
// put "size" words into target on each PE
for(int i = 1; i < numPE; i++)
target.putInt(source, SIZE, i);
}
ShMem.barrierAll(); // sync sender and receiver
if(myPE != 0)
{
StringBuilder sb = new StringBuilder();
sb.append("Target on PE "+ myPE +" is \t");
IntBuffer buf = target.asIntBuffer();
for(int i = 0; i < SIZE; i++)
sb.append(buf.get(i) +" \t");
sb.append('\n');
System.out.print(sb);
}
ShMem.barrierAll(); // sync before exiting
target.free();
}
}