123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- program nf_basic_ring
- use iso_c_binding
- use fstarpu_mod
- use fstarpu_mpi_mod
- implicit none
- integer(c_int) :: ncpu
- integer(c_int) :: ret
- integer(c_int) :: rank,sz
- integer(c_int),target :: token = 42
- integer(c_int) :: nloops = 32
- integer(c_int) :: loop
- integer(c_int) :: tag
- integer(c_int) :: world
- integer(c_int) :: src,dst
- type(c_ptr) :: token_dh, st
- ret = fstarpu_mpi_init(1)
- print *,"fstarpu_mpi_init status:", ret
- if (ret /= 0) then
- stop 1
- end if
- ret = fstarpu_init(C_NULL_PTR)
- if (ret == -19) then
- stop 77
- else if (ret /= 0) then
- stop 1
- end if
-
- ncpu = fstarpu_cpu_worker_get_count()
- if (ncpu == 0) then
- call fstarpu_shutdown()
- ret = fstarpu_mpi_shutdown()
- stop 77
- end if
- world = fstarpu_mpi_world_comm()
- rank = fstarpu_mpi_world_rank()
- sz = fstarpu_mpi_world_size()
- write(*,*) "rank=", rank,"size=",sz,"world=",world
- if (sz < 2) then
- call fstarpu_shutdown()
- ret = fstarpu_mpi_shutdown()
- stop 77
- end if
- call fstarpu_variable_data_register(token_dh, 0, c_loc(token), c_sizeof(token))
- st = fstarpu_mpi_status_alloc()
- do loop=1,nloops
- tag = loop*sz+rank
- token = 0
- if (loop == 1.and.rank == 0) then
- write(*,*) "rank=", rank,"token=",token
- else
- src = modulo((rank+sz-1),sz)
- write(*,*) "rank=", rank,"recv--> src =", src, "tag =", tag
- ret = fstarpu_mpi_recv(token_dh, src, tag, world, st)
- if (ret /= 0) then
- write(*,*) "fstarpu_mpi_recv failed"
- stop 1
- end if
- write(*,*) "rank=", rank,"recv<--","token=",token
- token = token+1
- end if
- if (loop == nloops.and.rank == (sz-1)) then
- call fstarpu_data_acquire(token_dh, FSTARPU_R)
- write(*,*) "finished: rank=", rank,"token=",token
- call fstarpu_data_release(token_dh)
- else
- dst = modulo((rank+1),sz)
- write(*,*) "rank=", rank,"send--> dst =", dst, "tag =", tag+1
- ret = fstarpu_mpi_send(token_dh, dst, tag+1, world)
- if (ret /= 0) then
- write(*,*) "fstarpu_mpi_recv failed"
- stop 1
- end if
- write(*,*) "rank=", rank,"send<--"
- end if
- end do
- call fstarpu_mpi_status_free(st)
- call fstarpu_data_unregister(token_dh)
- call fstarpu_shutdown()
- ret = fstarpu_mpi_shutdown()
- print *,"fstarpu_mpi_shutdown status:", ret
- if (ret /= 0) then
- stop 1
- end if
- end program nf_basic_ring
|