Problem with OpenMPI using DEM method

Dear all,

I would like to compile a shortcode in the usr3_des.f document.
Before that, I make a test code and feel a little confused about the results. I attach it here


image

You can see that all the processors print the value one by one
However, my code does not follow this logic, and it should be a random print.
It seems that the processors are not parallel, on the contrary, they work one by one.

Kind regards,

It looks like you are getting the correct behavior in that

  1. a random number is generated by the IO processor
  2. the value is broadcast to the other processes
  3. the processes all print the same value

I assume you are confused that the print statements are coming back grouped by processes. This is likely based on the system you are using (especially if you are running on a single multi-core CPU). You may have to run on physically separate compute cores before you start seeing it come back in a jumbled mess.


Note that MFIX has wrapper functions for MPI_Barrier and MPI_Bcast I would suggest using those over directly calling MPI APIs. For example, your above code could be written as below where the MFIX MPI wrapper functions are used, and only a single communication is needed as all integers are packed into a single array.

subroutine usr3_des

use compar,         only: mype, pe_io
use mpi_utility,    only: bcast

use error_manager

implicit none

real    :: rrand
integer :: irand(5), lc

! Create an array of random integers on pe_io
if(mype == pe_io) then
   do lc=1,5
      call random_number(rrand)
      irand(lc) = nint(rrand*10)
   end do
end if

! Broadcast array to all other processes
call bcast(irand, PE_IO)

do lc=1,5
   write(6,"('random number',2(2x,a))") &
      trim(ival(myPE)), trim(ival(irand(lc)))
enddo

return
end subroutine usr3_des
1 Like

Dear Dr. Musser,
Your guess about my confuse is right and I am sorry for not explain clearly.
I appreciate your answer and understand your advice. After I use the cluster, I found the codes worked as I imagined. Many thanks and I can understand the codes deeply.
Kind regards
Jia