mpi understanding isend and irecv -
i have 2 processes (0 , 1), 0 gets random number, if not mod(number,2)==0 , if bigger previous ones, sends (isend) process 1.
process 1 recives number (recv) , has calculate if prime number. if prime number, process 1 sends (isend) process 0. process 0 saves highest prime number (not final prime number, generates amount of random numbers have checked).
so in meanwhile process 1 checking if number received prime number, process 0 on random number. point process 0 may overwrite data in isend because process 1 on own work , not receiving. , want this.
program mpi_nonblocking use mpi implicit none integer :: ierr, myid ,npe, istatus(mpi_status_size), num, num_copy, best_prime=1, resto, i, n, now(3), req11 integer,parameter :: seed = 86456, numbers=200 integer :: req1(numbers), req2(numbers) logical :: flag, res call mpi_init(ierr) call mpi_comm_rank(mpi_comm_world,myid,ierr) call mpi_comm_size(mpi_comm_world,npe,ierr) if (npe/=2) write(*,*)'avviare il programma con 2 processi (-np 2 ./mpi_nonblocking)' else if (myid == 0) open(22,file='uomo_0.txt', status="unknown", form= "formatted") open(24,file='uomo_00.txt', status="unknown", form= "formatted") call itime(now) write(*,*) call srand(now(3)) n=1, numbers req1(n)=0 req2(n)=0 num=irand() write(24,*)'random number',num if (num>best_prime) resto=mod(num,2) if (resto==0 .and. num/=2) write(24,*)'cycle' cycle end if end if write(22,*)'uomo 0 send',num,'non-blocking' write(24,*)'uomo 0 send',num,'non-blocking' call mpi_isend(num,1,mpi_integer,1,1,mpi_comm_world,req1(n),ierr) write(24,*)num,req1(n) call mpi_irecv(best_prime,1,mpi_integer,1,0,mpi_comm_world,req2(n),ierr) end close(22) call mpi_send(-1,1,mpi_integer,1,1,mpi_comm_world,ierr) print *,'best_prime is',best_prime !do i=1, numbers !write(24,*)'test isend',i,'flag value',req2(i) !call mpi_test(req2(i),flag,istatus,ierr) !if (flag .eqv. .false.) !write(24,*)'uomo 0 recv',i,'non-blocking fail' !else if (flag .eqv. .true.) !write(24,*)'uomo 0 recv',i,'non-blocking success' !end if !end close(24) else open(23,file='uomo_1.txt', status="unknown", form= "formatted") open(25,file='uomo_11.txt', status="unknown", form= "formatted") n=1, numbers call mpi_recv(num,1,mpi_integer,0,myid,mpi_comm_world,istatus,ierr) write(23,*)'uomo 1 recv',num write(25,*)'uomo 1 recv',num if (num==-1) write(23,*)'abort' write(25,*)'abort' call exit(0) end if res=.true. num_copy=nint(sqrt(real(num))) write(25,*)'sqrt',num_copy,'di num',num i=3, num_copy, +2 resto=mod(num,i) if (resto==0) res= .false. write(25,*)'num',num,'no numero primo' exit !not numero primo end if end if (res .eqv. .true.) write(25,*)'num',num,'primo' write(25,*)'uomo 1 send',num,'non-blocking' call mpi_isend(num,1,mpi_integer,0,0,mpi_comm_world,req11,ierr) end if end close(23) close(25) end if end if call mpi_finalize(ierr) end program
the problem is, overwite happens, process 1 continues receive last number, sent process 0, multiple times: continues receive until reaches number of isend calls of process 0.
105) uomo 0 send 1310474405 non-blocking 106) uomo 0 send 551041203 non-blocking 107) uomo 0 send 1400012957 non-blocking 108) uomo 0 send 907501537 non-blocking 109) uomo 0 send 949471365 non-blocking 61) uomo 1 recv 792320847 62) uomo 1 recv 2137864129 63) uomo 1 recv 1888232175 64) uomo 1 recv 4829859 65) uomo 1 recv 2082851615 66) uomo 1 recv 949471365 67) uomo 1 recv 949471365 68-109) uomo 1 recv 949471365 110) uomo1 recv -1 111) abort
Comments
Post a Comment