1
1

OSHMEM: added bunch of examples according to SPEC 1.0

fixed by Roman, reviewed by Igor/Mike

cmr=v1.8.2:reviewer=ompi-rm1.8

This commit was SVN r31449.
This commit is contained in:
Mike Dubman 2014-04-19 05:03:44 +00:00
parent 3a8d2a0421
commit daaf1d441d
11 changed files with 267 additions and 7 deletions

View File

@ -61,7 +61,13 @@ EXAMPLES = \
ring_oshmem \
ring_oshmemfh \
Ring.class \
connectivity_c
connectivity_c \
oshmem_shmalloc \
oshmem_circular_shift \
oshmem_max_reduction \
oshmem_strided_puts \
oshmem_symmetric_data
# Default target. Always build the C MPI examples. Only build the
# others if we have the appropriate Open MPI / OpenSHMEM language
@ -100,6 +106,11 @@ oshmem:
@ if oshmem_info --parsable | grep oshmem:bindings:c:yes >/dev/null; then \
$(MAKE) hello_oshmem; \
$(MAKE) ring_oshmem; \
$(MAKE) oshmem_shmalloc; \
$(MAKE) oshmem_circular_shift; \
$(MAKE) oshmem_max_reduction; \
$(MAKE) oshmem_strided_puts; \
$(MAKE) oshmem_symmetric_data; \
fi
@ if oshmem_info --parsable | grep oshmem:bindings:fort:yes >/dev/null; then \
$(MAKE) hello_oshmemfh; \
@ -143,3 +154,18 @@ ring_oshmem: ring_oshmem_c.c
ring_oshmemfh: ring_oshmemfh.f90
$(SHMEMFC) $(FCFLAGS) $? -o $@
oshmem_shmalloc: oshmem_shmalloc.c
$(SHMEMFC) $(FCFLAGS) $? -o $@
oshmem_circular_shift: oshmem_circular_shift.c
$(SHMEMCC) $(CFLAGS) $? -o $@
oshmem_max_reduction: oshmem_max_reduction.c
$(SHMEMCC) $(CFLAGS) $? -o $@
oshmem_strided_puts: oshmem_strided_puts.c
$(SHMEMCC) $(CFLAGS) $? -o $@
oshmem_symmetric_data: oshmem_symmetric_data.c
$(SHMEMCC) $(CFLAGS) $? -o $@

View File

@ -48,5 +48,10 @@ EXTRA_DIST += \
examples/ring_oshmem_c.c \
examples/ring_oshmemfh.f90 \
examples/connectivity_c.c \
examples/Hello.java \
examples/Ring.java
examples/oshmem_shmalloc.c \
examples/oshmem_circular_shift.c \
examples/oshmem_max_reduction.c \
examples/oshmem_strided_puts.c \
examples/oshmem_symmetric_data.c \
examples/Hello.java \
examples/Ring.java

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Mellanox Technologies, Inc.
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*

View File

@ -1,5 +1,5 @@
!
! Copyright (c) 2013 Mellanox Technologies, Inc.
! Copyright (c) 2014 Mellanox Technologies, Inc.
! All rights reserved.
! Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
! $COPYRIGHT$

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include <stdio.h>
#include <shmem.h>
int main (void)
{
static int aaa, bbb;
int num_pes, my_pe, peer;
start_pes(0);
num_pes = _num_pes();
my_pe = _my_pe();
peer = (my_pe + 1) % num_pes;
printf("Process %d gets message from %d (%d processes in ring)\n", my_pe, peer, num_pes);
shmem_int_get(&aaa, &bbb, 1, peer);
shmem_barrier_all();
printf("Process %d exiting\n", my_pe);
return 0;
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* reduce [0,1,2] + _my_pe() across 4 PEs with MAX()
*/
#include <stdio.h>
#include <string.h>
#include <shmem.h>
long pSync[_SHMEM_BCAST_SYNC_SIZE];
#define N 3
long src[N];
long dst[N];
long pWrk[_SHMEM_REDUCE_SYNC_SIZE];
int main(void)
{
int i;
int my_pe, num_pes;
for (i = 0; i < SHMEM_BCAST_SYNC_SIZE; i += 1) {
pSync[i] = _SHMEM_SYNC_VALUE;
}
start_pes(0);
my_pe = _my_pe();
num_pes = _num_pes();
for (i = 0; i < N; i += 1) {
src[i] = my_pe + i;
}
shmem_barrier_all();
shmem_long_max_to_all(dst, src, N, 0, 0, num_pes, pWrk, pSync);
printf("%d/%d dst =", my_pe, num_pes);
for (i = 0; i < N; i+= 1) {
printf(" %d", dst[i]);
}
printf("\n");
return 0;
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* This sample allocates (shmalloc) symmetric memory (1 long integer),
* and then frees it. Success of allocation is not checked.
*
* Produces no output.
*/
#include <shmem.h>
int main(void)
{
long *x;
start_pes(0);
x = (long *) shmalloc(sizeof(*x));
shfree(x);
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* This program is an adaptation of examples found in the man pages
* of SGIs SHMEM implementation.
*
* In this program, iput is used to select 5 elements from array source separated by
* a stride of 2 and write them to array target using a stride of 1.
*
* Given the array source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
* iput will select 5 elements from array source on PE 0, using a stride of 2:
*
* selected elements = { 1, 3, 5, 7, 9 }
*
* These elements will then be written to the array source on PE 1 using a stride of 1:
*
* target = { 1, 3, 5, 7, 9 }
*
*/
#include <stdio.h>
#include <shmem.h>
int main(void)
{
short source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
static short target[10];
int me;
start_pes(0);
me = _my_pe();
if (me == 0) {
/* put 10 words into target on PE 1 */
shmem_short_iput(target, source, 1, 2, 5, 1);
}
shmem_barrier_all(); /* sync sender and receiver */
if (me == 1) {
printf("target on PE %d is %hd %hd %hd %hd %hd\n", me,
target[0], target[1], target[2],
target[3], target[4] );
}
shmem_barrier_all(); /* sync before exiting */
return 0;
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include <stdio.h>
#include <shmem.h>
#define SIZE 16
int main(int argc, char* argv[])
{
short source[SIZE];
static short target[SIZE];
int i;
int num_pe, my_pe;
start_pes(0);
num_pe = _num_pes();
my_pe = _my_pe();
if (my_pe == 0) {
/* initialize array */
for(i = 0; i < SIZE; i++) {
source[i] = i;
}
/* local, not symmetric */
/* static makes it symmetric */
/* put "size" words into target on each PE */
for(i = 1; i < num_pe; i++) {
shmem_short_put(target, source, SIZE, i);
}
}
shmem_barrier_all(); /* sync sender and receiver */
if (my_pe != 0) {
printf("Target on PE %d is \t", my_pe);
for(i = 0; i < SIZE; i++) {
printf("%hd \t", target[i]);
}
printf("\n");
}
shmem_barrier_all(); /* sync before exiting */
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Mellanox Technologies, Inc.
* Copyright (c) 2014 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*

View File

@ -1,5 +1,5 @@
!
! Copyright (c) 2013 Mellanox Technologies, Inc.
! Copyright (c) 2014 Mellanox Technologies, Inc.
! All rights reserved.
! Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
! $COPYRIGHT$