[mpich-discuss] How to handle complex variables

Jayesh Krishna jayesh at mcs.anl.gov
Mon Nov 8 09:24:59 CST 2010


Hi,
 Are you using MPICH2 on windows or unix ? Which version of MPICH2 are you using ?
 Are you getting an error message when you run your code (What is the error message)? I am not a fortran expert but shouldn't you be using complex(16) (instead of complex(8)) for MPI_DOUBLE_COMPLEX ?

Regards,
Jayesh
----- Original Message -----
From: Antonin at LPS <bourgeois at lps.u-psud.fr>
To: mpich-discuss at mcs.anl.gov
Sent: Mon, 08 Nov 2010 08:57:54 -0600 (CST)
Subject: [mpich-discuss] How to handle complex variables

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.




More information about the mpich-discuss mailing list