Error trying to use MPI

Dear Community,

I recently installed OpenMPI with.

sudo apt install openmpi-bin openmpi-common openmpi-doc libopenmpi3 libopenmpi-dev

I’ve an Ubuntu machine with gfortran installed.

gfortran --version
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

, while my conda distribution is,

which conda
/home/usuario/anaconda3/bin/conda

When trying to run this test program,

program main
    use mpi_f08
    call MPI_Init()
    print *, "test"
    call MPI_Finalize()
end program main

I get the following error

mpif90 main.f90
/home/usuario/anaconda3/bin/mpif90: line 376: x86_64-conda_cos6-linux-gnu-gfortran: command not found

Any advice would be very welcomed.

Kind rgds
Jose

Hi @jaoc12 , welcome to the Discourse and Fortran.

I think I see the issue. You’ve installed openmpi with your system package manager, but you’re using the Conda installed mpif90, but don’t seem to have installed gfortran via Conda. Basically, a mix-up of different installation and execution environments. I’d suggest you probably don’t need Conda just yet, as the system installed openmpi and gfortran should work just fine together.

Many thanks @everythingfunctional .
Indeed, when I launch the terminal, I’m inside a conda environment by default (==>(base) user@xxx: ~/).
Inside such environemnt, when I run mpirun --version, I get

HYDRA build details:
    Version:                                 3.3.2

However, if I exit the conda environemnt (conda deactivate) ==> user@xxx: ~/), and run mpirun --version`, I get

mpirun (Open MPI) 4.1.2

Question now, how do I change the MPI that conda is using? In its .bashrc file?

I don’t use Conda, so I’m not sure. Perhaps someone else can help with that. For now you can probably just exit the Conda environment and things will work.

I think on ubuntu, you only need one command like below

sudo apt install gfortran mpich

then it will automatically install gfortran and configure it correctly with MPI. It never fails me. You may try.

Perhaps

sudo apt install gfortran openmpi

also works.

Thxs both
Indeed, I installed MPICH as part of a hydrodynamic simulation package. (GADGET4) That may be the reason why is the default MPI compiler when in a conda environment.

Kind rgds
Jose