
Chapter 7. Interprocess communication 77
INCLUDE ’mpp/shmem.fh’
INTEGER, PARAMETER ::n=4
INTEGER, DIMENSION(n), SAVE :: &
source_pe = (/1,2,3,4/), &
target_pe = (/5,6,7,8/)
INTEGER, DIMENSION(n) :: c
INTEGER :: i, mype
INTEGER, EXTERNAL :: shmem_my_pe
mype = shmem_my_pe()
IF (mype == 0) THEN
CALL shmem_put(target_pe, source_pe, n, 1)
ENDIF
CALL barrier()
DOi=1,n
c(i) = 2*target_pe(i)
END DO
WRITE (*,’(i2,a7,8i3)’) mype,’:c=’,c
END PROGRAM shmemex
Here is the same example program in C:
#include <stdio.h>
#include <mpp/shmem.h>
main() {
static long source[4] = {1,2,3,4};
static long target[4] = {5,6,7,8};
long c[4];
int i;
if(_my_pe() == 0)
shmem_put(target,source,4,1);
barrier();
for(i=0; i<4; ++i)
c[i] = 2*target[i];
printf("PE:%d c is: %d %d %d %d \n",
_my_pe(), c[0], c[1], c[2], c[3]);
}
Above, we have used the function _my_pe to find out the task id number.
The Fortran 90 program can be compiled with the command
f90 -o shmemex shmemex.f90
and the C program with the command
cc -o shmemex shmemex.c
After this, the program is started on two PEs by typing
mpprun -n 2 ./shmemex
The result of the Fortran 90 program will be
Comentarios a estos manuales