# Error trying to use MPI

**URL:** https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863
**Category:** Help
**Created:** [December 6, 2022, 9:19pm UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863 "2022-12-06T21:19:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jaoc12](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jaoc12](https://fortran-lang.discourse.group/u/jaoc12)
#### Post date: [December 6, 2022, 9:19pm UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863/1 "2022-12-06T21:19:21Z")

</div>

Dear Community,

I recently installed OpenMPI with.

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

```

I’ve an Ubuntu machine with gfortran installed.

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

```

, while my conda distribution is,

```auto
which conda
/home/usuario/anaconda3/bin/conda

```

When trying to run this test program,

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

```

I get the following error

```auto
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

---

<div class="post-metadata">

### Author: ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)
#### Post date: [December 6, 2022, 10:22pm UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863/2 "2022-12-06T22:22:28Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jaoc12](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jaoc12](https://fortran-lang.discourse.group/u/jaoc12)
#### Post date: [December 9, 2022, 10:50am UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863/3 "2022-12-09T10:50:24Z")

</div>

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

```auto
HYDRA build details:
    Version: 3.3.2

```

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

```auto
mpirun (Open MPI) 4.1.2

```

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

---

<div class="post-metadata">

### Author: ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)
#### Post date: [December 9, 2022, 2:54pm UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863/4 "2022-12-09T14:54:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)
#### Post date: [December 10, 2022, 9:52am UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863/5 "2022-12-10T09:52:40Z")

</div>

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

```auto
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

```auto
sudo apt install gfortran openmpi

```

also works.

---

<div class="post-metadata">

### Author: ![jaoc12](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jaoc12](https://fortran-lang.discourse.group/u/jaoc12)
#### Post date: [December 10, 2022, 11:57am UTC](https://fortran-lang.discourse.group/t/error-trying-to-use-mpi/4863/6 "2022-12-10T11:57:30Z")

</div>

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
