
Chapter 7. Interprocess communication 69
CALL PVMFpack(INTEGER8, j, msglen, stride, rc)
to=j
CALL PVMFsend(to, tag, rc)
END DO
END IF
from = 0
CALL PVMFrecv(from, tag, rc)
CALL PVMFunpack(INTEGER8, message, msglen, stride, rc)
WRITE (*,*) ’PE#’,mype,’: message=’,message
END PROGRAM main
Compile, link and run the program as follows (on three processors):
t3e% f90 -o pvmprog.x pvmprog.f90
t3e% mpprun -n 3 ./pvmprog.x
PE# 2 : tid= 393218 nproc= 3
PE# 0 : tid= 393216 nproc= 3
PE# 1 : tid= 393217 nproc= 3
PE# 0 : message= 0
PE# 2 : message= 2
PE# 1 : message= 1
The same program in C is as follows:
#include <stdio.h>
#include <pvm3.h>
main()
{
int mytid = pvm_mytid();
int mype = pvm_get_PE(mytid); /* CRAY MPP specific */
int nproc = pvm_gsize(NULL); /* Default group */
int tag, len, stride;
int from, message;
printf("PE#%d: tid=%d nproc=%d\n", mype, mytid, nproc);
if (mype == 0) {
int to, j;
for (j=0; j<nproc; j++) {
pvm_initsend(PvmDataRaw);
pvm_pkint(&j,len=1,stride=1);
pvm_send(to=j,tag=100);
}
}
pvm_recv(from=0, tag=100);
pvm_upkint(&message, len=1, stride=1);
printf("PE#%d: message=%d\n", mype, message);
}
Compile, link and run the program as follows (3 processors):
t3e% cc -o pvmprog.x pvmprog.c
t3e% mpprun -n 3 ./pvmprog.x
Comentarios a estos manuales