Hello,

I'm having trouble with some MPI programming in Fortran, using openmpi.
It seems that my program doesn't work unless I print some unrelated text to the screen. For example, if I have this situation:

*** hundreds of lines cut ***
IF (irank .eq. 0) THEN
    CALL print_results1(variable)
    CALL print_results2(more_variable)
END IF
print *, "done", irank
CALL MPI_FINALIZE(ierr)
END PROGRAM calculation

The results are not printed unless I include this "print done irank" penultimate line.
Also, despite seeing that all ranks reach the print statement, the program hangs, as if they have not all reached MPI_FINALIZE.

Can anyone help me? Why does it do this?

I also had many times where the program would crash if I didn't include a print statement in a loop. I've been doing Fortran programming for a while, and this is my nightmare debugging scenario since I've never been able to figure out why the simple printing of statements magically fixes the program, and I usually end up having to go back to a serial solution, which is really slow.

If anyone might be able to help me, I would be really really grateful!!

Thank you.

Tom