c Parameter c --------- integer*4 zrecv ! number of simultaneous receive messages parameter(zrecv = 512) c Local c ----- integer*4 m_stat(MPI_STATUS_SIZE) integer*4 m_slave logical*4 m_flag integer*4 m_request(zrecv) ! request identifier for assynchonous receives character cbuff(zrecv)*(zbuf) ! character buffer for receiving messages logical*4 continua continua = .true. kont = 0 c Pre-post RECVs c -------------- do irecv = 1, zrecv call MPI_IRECV(cbuff(irecv), zbuf, MPI_CHARACTER, . MPI_ANY_SOURCE, MPI_ANY_TAG, M_COMM_ALL, . m_request(irecv), m_ierr ) if( m_ierr .ne. 0 ) then write(idpy,1001) 'MPI_IRECV' write(iprn,1001) 'MPI_IRECV' call fexit(m_ierr) end if end do !irecv do while( continua ) c Wait for any of the pre-posted requests to arrive c ------------------------------------------------- if( kont .lt. npro-2 ) then call MPI_WAITANY(zrecv, m_request, irecv, m_stat, m_ierr) if( m_ierr .ne. 0 ) then write(idpy,1001) 'MPI_WAITANY' write(iprn,1001) 'MPI_WAITANY' call fexit(m_ierr) end if end if if( m_stat(MPI_TAG) .eq. M_RECCSV ) then c Get message size, unpack information and call output c ---------------------------------------------------- call MPI_GET_COUNT(m_stat,MPI_CHARACTER,isize,m_ierr) isize = isize - 8 clu_irec(1:8) = cbuff(irecv)(isize+1:isize+8) lu = ilu_irec(1) irec = ilu_irec(2) call output( lu, irec, isize, cbuff(irecv) ) else if( m_stat(MPI_TAG) .eq. M_FIMCSV ) then kont = kont + 1 else write(iprn,*) ' Unexpected message received.' write(idpy,*) ' Unexpected message received.' call sfexit( rotina, 001 ) end if c Re-post RECV c ------------ call MPI_IRECV(cbuff(irecv), zbuf, MPI_CHARACTER, . MPI_ANY_SOURCE, MPI_ANY_TAG, M_COMM_ALL, . m_request(irecv), m_ierr ) if( m_ierr .ne. 0 ) then write(idpy,1001) 'MPI_IRECV' write(iprn,1001) 'MPI_IRECV' call fexit(m_ierr) end if c Check end of process c -------------------- if( kont .eq. npro-2 ) then c Check if there is a pending RECCSV message to be received c --------------------------------------------------------- call MPI_TESTANY(zrecv, m_request, irecv, m_flag, . m_stat, m_ierr) if( m_ierr .ne. 0 ) then write(idpy,1001) 'MPI_TESTANY' write(iprn,1001) 'MPI_TESTANY' call fexit(m_ierr) end if continua = m_flag ! if there is some pending message, the process continues end if end do c Cancel unused RECVs c ------------------- do irecv = 1, zrecv call MPI_CANCEL( m_request(irecv), m_ierr ) if( m_ierr .ne. 0 ) then write(idpy,1001) 'MPI_CANCEL' write(iprn,1001) 'MPI_CANCEL' call fexit(m_ierr) end if end do !irecv 1001 format(1x,'Error calling MPI function: ',a,' routine: ',a)