问题
I am trying to install an OpenMPI on my Ubuntu (14.04) machine, and I thought that I had succeeded, because I can run codes with mpirun
, but recently I have noticed that it's not truly running in parallel.
I installed openmpi
with the following options:
./configure CXX=g++ CC=gcc F77=gfortran \
F90=gfortran \
FC=gfortran \
--enable-mpi-f77 \
--enable-mpi-f90 \
--prefix=/opt/openmpi-1.6.5
make all
sudo make install
As I said, I have run a code ( not written by myself ) and it seemed to work in parallel, because I checked with top
and it was running in several nodes.
But now I have written a simple FORTRAN code:
PROGRAM hello_MPI
INCLUDE "mpif.h"
INTEGER :: err, size, rank
CALL MPI_INIT(err)
IF (err /= MPI_SUCCESS) STOP 'Init failed'
CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, err)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD, size, err)
PRINT*, "Hello world from process ", rank, " of ", size, " processes"
CALL MPI_FINALIZE(err)
END PROGRAM
But when I run it with
mpirun -n 4 ./hello_MPI
I get the same output 4 times, showing that it is just running the same single process in 4 different processors
Hello world from process 0 of 1 processes
Hello world from process 0 of 1 processes
Hello world from process 0 of 1 processes
Hello world from process 0 of 1 processes
I have run this same code in a different machine and I get the expected output:
Hello world from process 0 of 4 processes
Hello world from process 1 of 4 processes
Hello world from process 2 of 4 processes
Hello world from process 3 of 4 processes
回答1:
I managed to solve it. It was quite silly, to be honest. For some reason I was not using the right OpenMPI installation (I have no idea which it was using). I recompiled using the right mpif90
and run it using the right mpirun
and now I get the expected result.
Sorry for the confusion, but I am quite new to this. And thank you for the help!
来源:https://stackoverflow.com/questions/47417869/mpi-not-running-in-parallel-in-a-fortran-code