Cloud computing and big data - MPI cluster configuration

What is an MPI cluster?

MPI (Message Passing Interface) is a standard for writing parallel programs that allows communication and collaboration across multiple computing nodes. MPI cluster configuration refers to setting up an MPI environment on one or more computing nodes to achieve parallel computing.

Steps for MPI cluster configuration:

Hardware selection: Choose hardware devices that suit your needs, including master nodes and computing nodes. The master node is responsible for coordinating the communication and task distribution between the computing nodes, while the computing nodes perform the actual computing tasks.

Operating system installation: Install an operating system for each node. Common options include Linux, Windows servers, etc. Make sure all nodes are reachable to each other and have network connectivity.

MPI software installation: choose an MPI implementation, such as OpenMPI, MPICH, etc., and install the corresponding MPI software on each node according to the requirements of the operating system. The MPI library provides a set of functions and tools for parallel computing to communicate and synchronize between nodes.

Configure the master node: Edit the MPI configuration file of the master node, usually the configuration file of mpiexec or mpirun, to specify the way to run the MPI program. This can include options for specifying the number of compute nodes, startup scripts, process assignments, and more.

Configure compute nodes: For compute nodes, edit their MPI configuration file to specify the location of the master node and other necessary information. Also, make sure the compute nodes have access to the master node and other compute nodes for communication.

Test an MPI cluster: Write a simple MPI program and test it on an MPI cluster. Ensure that MPI programs can be correctly executed in parallel on multiple nodes, and data exchange and synchronization between nodes can be realized through message passing.

Expand the cluster size (optional): If you need more computing power, you can add more computing nodes to the cluster. Make sure that the corresponding MPI software is also installed on the new node and configured according to steps 4 and 5.

Let's make a simple MPI cluster configuration below, hoping to help you learn cloud computing and related MPI cluster knowledge.

1. Configure the virtual machine with VMware Workstation Pro and open it

Here we choose to log in as a normal user
insert image description here

1. Make sure the network is smooth, set the fixed IP of each node, and restart the network service.

Configure the master network service:

sudo vim /etc/sysconfig/network-scripts/ifcfg-ens33

insert image description here
Successfully configure the network
to ping www.baidu.com successfully!

insert image description here
Configure host1 network service:

sudo vim /etc/sysconfig/network-scripts/ifcfg-ens33

insert image description here

Successfully configure the network
to ping www.baidu.com successfully!

insert image description here
Configure the host2 network service:

sudo vim /etc/sysconfig/network-scripts/ifcfg-ens33

insert image description here
Successfully configured network
ping www.baidu.comSuccess!
insert image description here
2. Configure the hosts files of the two machines: the host names are master, host1 and host2 respectively

Order:

vim /etc/hosts

insert image description here
Order:

vim /etc/hosts

insert image description here
Modify the master host name:

vim /etc/hosname

insert image description here
Command: vim /etc/hosts
insert image description here
modify host1 host name:

vim /etc/hosname

insert image description here
Order:

vim /etc/hosts

insert image description here
Modify the host2 hostname:

vim /etc/hosname

insert image description here
insert image description here

2. SSH password-free login

ssh-keygen –t rsa Enter all the way
on master, host1, host2 respectively
2. Append the public key to the authorized_keys file, command:

  cat  ~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys

In master, host1, host2 respectively,
all nodes must be set
3. Copy the public key to other machines
(1) master

 ssh-copy-id -i  ~/.ssh/id_rsa.pub host1
ssh-copy-id  -i  ~/.ssh/id_rsa.pub host2

insert image description here

Restart the ssh service:

sudo systemctl restart sshd

insert image description here
The master successfully logs in to host1 without password:

ssh host1

insert image description here
(2)host1

ssh-copy-id  -i  ~/.ssh/id_rsa.pub master
ssh-copy-id  -i  ~/.ssh/id_rsa.pub host2

insert image description here
Restart the ssh service:

sudo systemctl restart sshd

insert image description here
Host1 successfully logs in to host2 without password:

ssh host2

insert image description here
(3)host2

ssh-copy-id  -i  ~/.ssh/id_rsa.pub master
ssh-copy-id  -i  ~/.ssh/id_rsa.pub host1

insert image description here

Restart the ssh service:

sudo systemctl restart sshd

insert image description here
Host2 successfully logs in to host1 without password:

 ssh host1

insert image description here

CentOS 7 automatically installed the ssh package and configured the SSH service during installation.
The ssh service status of the three machines:

systemctl status sshd

insert image description here
insert image description here
insert image description here
Note that the ssh password-free login is user-to-user, so it is necessary to ensure that the terminal of the master node and the terminal of the child node are corresponding during operation.
1) Close the firewall of each node and Selinux
Close: sudo systemctl stop firewalld
Power on disable: sudo systemctl disable firewalld
Close Selinux: sudo setenforce 0
insert image description here
insert image description here
insert image description here
2) Server (master, it is recommended to take the first host)
(1) sudo yum -y install nfs -utils rpcbind #Install software
(2) mkdir -p /opt/modules/mpi_share #Create shared directory
(3) chmod 777 /opt/modules/mpi_share -R #Grant permissions
insert image description here
(4) sudo vi /etc/exports #Modify configuration write:

/opt/modules/mpi_share 192.168.95.25(rw,sync,no_root_squash) /opt/modules/mpi_share 192.168.95.26(rw,sync,no_root_squash)

insert image description here

192.168.95.25 is the address of the child node, and it can also be the host name. The rw in the permission option means that reading and writing is allowed, and the input depends on the specific IP address of the host; ro is read-only; sync means synchronous writing, and no_root_squash means that when the client starts with Grant local root privileges when accessing as root.

sudo exportfs -rv

insert image description here
(5)sudo systemctl start rpcbind

sudo systemctl start nfs #启动nfs,或者设置为开机启动

insert image description here(6)sudo systemctl enable rpcbind

sudo systemctl enable nfs
showmount -e #查看NFS服务器端的共享目录

insert image description here
3) Client (host1)
(1) sudo yum -y install nfs-utils rpcbind
(2) mkdir -p /opt/modules/mpi_share #Set the shared directory location and name of each node to the same
(3) sudo systemctl start rpcbind
sudo systemctl start nfs #It can also be set to boot
(4) sudo systemctl enable rpcbind
(5) sudo mount -t nfs 192.168.95.20:/opt/modules/mpi_share /opt/modules/mpi_share #Mount the server-side shared directory Upload to a local folder
(6) or permanently mount (optional)
vim /etc/fstab
add 192.168.95.20:/home/mpi_share /home/mpi_share nfs rw 0 0
insert image description here
4) client (host2)
(1) sudo yum -y install nfs-utils rpcbind
(2) mkdir -p /opt/modules/mpi_share #Set the shared directory location and name of each node to be the same (3)
sudo systemctl start rpcbind
sudo systemctl start nfs #You can also set the startup
(4) sudo systemctl enable rpcbind
(5) sudo mount -t nfs 192.168.95.20:/opt/modules/mpi_share /opt/modules/mpi_share #Mount the server-side shared directory to a local folder
(6) or permanently mount (optional)
vim /etc /fstab
add 192.168.95.20:/home/mpi_share /home/mpi_share nfs rw 0 0
insert image description here
5. Install and configure mpich
1) Install compiler
yum install gcc gcc-c++ gcc-fortran kernel-devel -y # https://blog. csdn.net/wangzhouf/article/details/108222704
(yum install gcc g++ #mpich's default compilers are gcc, g++ and gfortran, but the yum command cannot find the gfortran installation package
#You can find the method to install the gfortran compiler by yourself Author : Air-dried orange peel - https://www.bilibili.com/read/cv15215061 Source: bilibili)
insert image description here
2) Download and install the mpi installation package
(1) Create a directory and download the package

mkdir -p /opt/softwares
cd softwares
wget http://www.mpich.org/static/downloads/3.4.1/mpich-3.4.1.tar.gz

insert image description here
(2) Unzip

tar -zxvf mpich-3.4.1.tar.gz

insert image description here
(3) Create a new installation directory

mkdir -p /opt/modules/mpich-install

insert image description here
(4) Enter the download directory and compile and install

cd /opt/softwares/mpich-3.4.1
./configure --disable-fortran --prefix=/opt/modules/mpich-install --with-device=ch4:ofi 2>&1 | tee c.txt

Or:
./configure --disable-fortran //Author: Dried Orange Peel- https://www.bilibili.com/read/cv15215061 Source: bilibili
insert image description here

make

insert image description here

make install

insert image description here
3) Configure the environment
(1)

vim ~/.bashrc
export MPICH=/opt/modules/mpich-install
export PATH=$MPICH/bin:$PATH

insert image description here
insert image description here
(2) Make environment variables take effect

source ~/.bashrc

insert image description here
4) Check the installation

mpirun -version

insert image description here
6. Compile the C program on each host
1) Upload the C program code helloWorld.c to the /opt/modules/mpi_share directory of each host
2) cd /opt/modules/mpi_share`
3) Write a helloWorld.c first and a helloWorld2.c:
insert image description here

mpicc -o helloWorld helloWorld.c

insert image description here
Writing another helloWorld2.c:

#include "mpi.h" 
#include <stdio.h> 
#include <math.h> 
void main(argc,argv) 
int argc;
char *argv[]; 
{
    
    
  int myid, numprocs; 
  int namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME]; 
  MPI_Init(&argc,&argv);
  MPI_Comm_rank(MPI_COMM_WORLD,&myid); 
  MPI_Comm_size(MPI_COMM_WORLD,&numprocs); 
  MPI_Get_processor_name(processor_name,&namelen);
  fprintf(stderr,"Hello World! Process %d of %d on %s\n", myid, numprocs, processor_name);
  MPI_Finalize();
}

insert image description here
7. Run on master:

mpirun -n 3 -host master,host1,host2 ./helloWorld

mpirun -n 3 -host master,host1,host2 ./helloWorld2

insert image description here
insert image description here
insert image description here
When we face our main contradiction, if we can look at the problem from a higher dimension and a higher level, we will discover a new world, and there will be a feeling of spring breeze coming overnight, thousands of pear trees blooming, This is another huge improvement to our personal thinking level, but this process requires us to continue to learn and practice. When we reach a certain level, quantitative changes will undergo qualitative changes.

Guess you like

Origin blog.csdn.net/Myx74270512/article/details/131742900