[mpich-discuss] How to handle complex variables

Antonin@LPS bourgeois at lps.u-psud.fr
Mon Nov 8 08:57:54 CST 2010


Hi everyone,

I've been using Fortran90 + MPICH2 for a while and I'm trying now to 
broadcast complex variables amongst the processes. I've just learned 
about the MPI_DOUBLE_COMPLEX datatype, but I'm not able to use it 
properly... Here is the simple test program I've been using:

program MPI_cmplx

use MPI
implicit none
integer    :: MPI_ID, MPI_size, MPI_err
complex(8) :: z1, z2

! Initialize 
------------------------------------------------------------------

call MPI_INIT(MPI_err)
call MPI_COMM_RANK(MPI_COMM_WORLD,MPI_ID,MPI_err)
call MPI_COMM_SIZE(MPI_COMM_WORLD,MPI_size,MPI_err)

! Broadcast 
------------------------------------------------------------------- <<< 
THIS WORKS

z1 = (0.0d0,0.0d0)
if(MPI_ID == 0) then
   z1 = (1.5d0,0.5d0)
   write(*,*) "BCAST with count=1*MPI_DOUBLE_COMPLEX:", z1
endif
call MPI_BCAST(z1,1,MPI_DOUBLE_COMPLEX,0,MPI_COMM_WORLD,MPI_err)
call MPI_BARRIER(MPI_COMM_WORLD,MPI_err)
if(MPI_ID /= 0) then
   write(*,*) "Proc.", MPI_ID, " received", z1
endif
call MPI_BARRIER(MPI_COMM_WORLD,MPI_err)

! Reduce 
---------------------------------------------------------------------- 
<<< THIS DOESN'T WORK

if(MPI_ID == 0) then
   write(*,*)
   write(*,*) "REDUCE with count=1*MPI_DOUBLE_COMPLEX"
endif
z1 = (1.5d0,0.5d0)
z1 = z1 + cmplx(MPI_ID,MPI_ID)
z2 = (0.0d0,0.0d0)
call MPI_BARRIER(MPI_COMM_WORLD,MPI_err)
write(*,*) "Proc.", MPI_ID, " has", z1
call MPI_BARRIER(MPI_COMM_WORLD,MPI_err)
if(MPI_ID == 0) then
   call MPI_REDUCE(z1,z2,1,MPI_DOUBLE_COMPLEX,MPI_SUM,0,MPI_COMM_WORLD)
   write(*,*) "Sum is", z2
endif

! End 
-------------------------------------------------------------------------

call MPI_FINALIZE(MPI_err)
end program MPI_cmplx


Could anyone help me on this please?
Thanks in advance,

Antonin



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20101108/ce3913ba/attachment.htm>


More information about the mpich-discuss mailing list