program shmemf implicit none include 'mpif.h' integer iam,nprocs,isize,ierr,other,orank integer shmem_ptr, shmem_create, shmem_get, shmem_put, shmem_free integer shmem_mem_alloc, shmem_mem_free, ilen integer locmem,itmp(100),i c Initiate MPI processes call MPI_Init(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, iam, ierr) call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr) print *,' iam and size ',iam,nprocs C allocate some memory and return a pointer to that memory ilen=10000 locmem=shmem_mem_alloc(MPI_COMM_WORLD, MPI_DOUBLE_PRECISION, ilen) if (iam.eq.0)print *,' address of memory ',locmem C create an integer shared array of isize on each processor isize=100 ierr=shmem_create(MPI_COMM_WORLD, isize, MPI_INTEGER, shmem_ptr) C put some data into your local array do i=1,100 itmp(i)=iam enddo ierr=shmem_put(shmem_ptr, 1, 100, iam, itmp) C synchronize to ensure everyone has put their data call MPI_Barrier(MPI_COMM_WORLD,ierr) C read one data item from the next processor other=mod(nprocs+iam-1,nprocs)+1 if (other.gt.nprocs)other=other-nprocs ierr=shmem_get(shmem_ptr, other, 1, other-1, orank) print *,' iam, orank ',iam,orank C remove the shared array ierr=shmem_free(shmem_ptr) C free all allocated memory ierr=shmem_mem_free() C end the MPI process call MPI_Finalize(ierr) stop end