First, install gcc, gfortran and make. Here's how to check if it's already installed. (... is omitted)
gcc
$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
....
make
$ make --version
GNU Make 4.2.1
....
gfortran
$ gfortran -v
Using built-in specs.
....
If gcc, gfortran and make versions come out like this, they are installed for the time being. If it is not installed, do the following, buykd-essential will install both gcc and make. Let's also install gfortran (for some reason gfotran was not included as standard in Ubuntu 20)
make&gcc
$ sudo apt install build-essential
$ sudo apt-get install gfortran
After the installation is complete, type the above gcc and make commands again and see if a similar screen appears.
Next, download the openMPI main unit. https://www.open-mpi.org/software/ompi/v4.0/ (At the time of writing this article, I downloaded openmpi-4.0.4.tar.gz. There is no doubt if I download ~ .tar.gz) Download storage location /home/Qiita/Downloads/openmpi-4.0.4.tar.gz will do. (The user is "Qiita")
Enter the command as follows to move and unzip to the root of the downloaded openMPI. If you do not specify the decompression location, it will be in the same directory. (After this, you can specify the installation destination of openMPI, so you can unzip it anywhere.)
cd&tar
$ cd /home/Qiita/Downloads
$ tar -xvf openmpi-4.0.4.tar.gz
Then you will have a new /home/Qiita/Downloads/openmpi-4.0.4 in / home / Qiita / Downloads. Next, let's actually install openMPI. Install openMPI in / opt / openMPI. Create a directory called / opt / openMPI and specify it for installation.
cd&tar
$ sudo mkdir /opt/openMPI #1
$ ./configure --prefix=/opt/openMPI CC=gcc CXX=g++ F77=gfortran FC=gfortran #2
$ make #3
$ sudo make install #4
Create the above directory with # 1 Compile the installer with # 2. It's like creating a leader to instruct the installation in advance. The command --prefix = / opt / openMPI tells this leader to tell his subordinates to install in / opt / openMPI for the actual installation. In # 3, the leader actually gives instructions to his subordinates.
** Also, if you execute # 2, a long sentence will appear and it will take a long time. Same for # 3 **
Finally pass the path. Tell me where you installed openMPI on your computer. Write these in a file called .bashrc that describes the terminal default settings. That way, every time you start a terminal, it will load this .bashrc, so don't forget where your computer installed openMPI.
PATH
# sudo gedit ~/.bashrc #1
------The following is.Write to bashrc-------
PATH=/opt/openMPI/bin:$PATH
LD_LIBRARY_PATH=/opt/openMPI/lib:$LD_LIBRARY_PATH
MANPATH=/opt/openMPI/share/man:$MANPATH
export PATH LD_LIBRARY_PATH MANPATH
---------------------------------
#sudo source ~/.bashrc #2
I'm not sure about the PATH, but if you installed it according to the above procedure, this should be okay ... (# 1 will open .bashrc in an editor called gedit. Next, copy and paste the above) After writing, save, close gedit and type # 2 to reflect the contents of .bashrc in the terminal.
Once you're done, let's test. The test compile file is taken from the following site. http://discexuno.wp.xdomain.jp/hpc/setup_mpi/
sample.cpp
$ cd #1
$ touch sample.cpp #2
$ gedit sample.cpp
Return to your home directory (/ home / Qiita) with # 1 In # 2, create a new file with the touch command. Let's specify the name in "sample.cpp". Open sample.cpp using gedit in # 3, copy and paste the following contents and save.
sample.cpp
//sample.cpp
#include "mpi.h"
#include <stdio.h>
int
main(int argc, char *argv[])
{
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("Hello, World. I am %d of %d\n", rank, size);
MPI_Finalize();
return 0;
}
Finally, type the following command, and if the final "Hello world ...." is displayed, openMPI is working normally.
test
$ mpic++ sample.cpp #1
$ mpirun -np 2 a.out #2
Hello, World. I am 0 of 2
Hello, World. I am 1 of 2
In # 1, sample.cpp is compiled with c ++ and a.out is output. (I don't understand the meaning of the program in this sample.cpp. It's a very rudimentary part, and I haven't studied enough ....) In # 2, "-np 2" is used to specify 2 cores of the CPU and openMPI is made to execute a.out. From the result, you can see that the letters Hello world were written using 2 cores. I mean .... From the result, it feels like two people wrote Hello world ...
This completes the installation of openMPI. Very rudimentary, but a little difficult for beginners crying Thank you for reading.
Recommended Posts