Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Sending, receiving result in deadlock

anishtain4
Beginner
516 Views
I'm trying to solve a simple problem with MPI but when I comment all the PRINT lines the program gets into a deadlock, when I uncomment one of them then the programm proceeds smoothly!!!! I can't understand what is wrong with this? I'm using blocking send and receive so time difference that print makes should not has any effect on the overal performance!
The idea of IF is that odd processes first send and evens recieve then vice versa, so there should not be any deadlock even if there don't be any buffer on the way!
What is wrong with my algorithm that makes it break?

[bash]integer,parameter	::IM=100,JM=100
REAL,ALLOCATABLE  ::T(:,:),TF(:,:)
..
 CALL MPI_COMM_RANK(MPI_COMM_WORLD,RNK,IERR)
 CALL MPI_COMM_SIZE(MPI_COMM_WORLD,SIZ,IERR)
..
prv = rnk-1
nxt = rnk+1
LIM = INT(IM/SIZ)
IF (rnk==0)	THEN
	ALLOCATE(TF(IM,JM))
	prv	= MPI_PROC_NULL
ELSEIF(rnk==siz-1) THEN
	NXT	= MPI_PROC_NULL
	LIM	= LIM+MOD(IM,SIZ)
END IF
ALLOCATE(T(LIM+2,JM+2))

IF (MOD(RNK,2)==0) THEN
		CALL MPI_SEND(T(2,:),JM+2,MPI_REAL,PRV,10,MPI_COMM_WORLD,IERR)
		!PRINT*,RNK,'SENT'
		CALL MPI_RECV(T(1,:),JM+2,MPI_REAL,PRV,20,MPI_COMM_WORLD,STAT,IERR)
		!PRINT*,RNK,'RECIEVED'
	ELSE
		CALL MPI_RECV(T(LIM+2,:),JM+2,MPI_REAL,NXT,10,MPI_COMM_WORLD,STAT,IERR)
		PRINT*,RNK,'RECIEVED'
		CALL MPI_SEND(T(LIM+1,:),JM+2,MPI_REAL,NXT,20,MPI_COMM_WORLD,IERR)
		!PRINT*,RNK,'SENT'
	END IF[/bash]
0 Kudos
5 Replies
TimP
Honored Contributor III
516 Views
There's more MPI expertise on the HPC forum than here.
Did you try setting optimize(0) for this procedure?
0 Kudos
anishtain4
Beginner
516 Views
Thanks I will ask them there too.
well think I'm using optimization because I compile with the command:
mpif90 -o RB RB.f90
trying to turn it off I tired the following but it gave me a lot of errors:
mpif90 -o0 RB RB.f90
I'm not quiet used to commands since in windows all these stuff were visual options, am I doing it wrong?
0 Kudos
Kevin_D_Intel
Employee
516 Views
Yes, the first command-line results in default optimization, -O2. The second command line is incorrect. The optimization option uses a capital "O" (e.g."-O0"). The lower-case "o" names the output file.
0 Kudos
Ron_Green
Moderator
516 Views
You did not specify which MPI you are using. From your compilation line, I would assume you are NOT using Intel MPI with the Intel compilers - Intel MPI's compilation command to use Intel Fortran would be mpiifort. If you are using MPICH or OpenMPI make sure you built them using Intel Fortran and not gfortran, G95 or g77. We have a knowledge base articles on build those 2 packages with Intel compilers. Pass the -V option to mpif90 and see the verbose output to make sure you're building with ifort.

It's also important that when you run the executable, the shell env has sourced ifortvars.sh - if you are running under PBS or some batch system, make sure your env vars are propagated to your remote shells OR your batch script sources ifortvars.sh

Since you're not using Intel MPI, I would say double check how you built the MPI package to make sure the package was built with Intel Fortran. Next, Intel MPI is available for 30 day evaluation, try that package and see if the problem persists.

ron
0 Kudos
anishtain4
Beginner
516 Views
The problem was with the optimization, I added the -O0 and it runs good now. I'm using ifort to compile with mpich since I have just installed ifort on my linux, there is no gfortran.
0 Kudos
Reply