Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

6. Seminar - Parallel programing for DMS (C language + MPI)

Task to practice on seminar: EN: 06_seminar_assignment-en.pdf CZ: 06_cviceni_zadani.pdf

Open-MPI specification and documentation

Wes Kendall's tutorial

Program for task 2 (test program):

#include <stdio.h>
#include "mpi.h"
 
int main(int argc, char *argv[]) {
  int numprocs, rank, namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];
 
  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Get_processor_name(processor_name, &namelen);
 
  printf("Hello from process %d out of %d on %s\n",
          rank, numprocs, processor_name);
 
  MPI_Finalize();
  return 0;
}


Linux:

Compilation:

mpiCC program.c -lm -o program

mpirun
wrapper is used to run the program an next steps are required to run program on multiple computers:

1. Generate ssh key

 /usr/bin/ssh-keygen -N "" -t ecdsa -f ~/.ssh/id_ecdsa
 cd ~/.ssh/
 cat id_ecdsa.pub >> authorized_keys
 chmod -c 600 authorized_keys

or simpler variant

ssh-keygen
ssh-copy-id login@localhost

ssh-copy-id ensures that default public key file ~/.ssh/id_rsa.pub or ~/.ssh/id_ecdsa content is copied to ~/.ssh/authorized_keys file on the target computer. In our case, the copy target is SSH on same computer as we are logged in. You need to login by your password. It is not necessary to copy public key because all computers in the laboratory mounts your home directory from same NFS volume export. ABut your home directory is mounted on each computer after first login of given user. This means that first login requires password authentization. That is why you should keep one remote shell connection to each computer which should be automatically used by MPI. Laboratory computer addresses are from range 192.168.202.101 to 192.168.202.120.

2. Connect through ssh to all computers/nodes inteded for your program execution

3. Run

 
mpirun --host 192.168.202.101,192.168.202.102 -np 2 ./program

To suppress hidden infinite wait for target system signature by SSH use

 
mpirun --mca plm_rsh_args "-oStrictHostKeyChecking=no"

How to find IP address of computer where is given process of MPI program run:
You can use the following code to determine the IP address of the computer where program is run. Thanks to Martinov Velekov for providing solution. Remark: Pointer returned bygetenv() use only to immediately read string pointed by it. Next getenv() call can change content of memory location returned by previous call.

#include <string.h>
char* remote_ip = getenv("SSH_CONNECTION");
char localhost[] = "localhost";
char * pch;
if(NULL != remote_ip)
{
   pch=strchr(remote_ip,' ');
   pch=strchr(++pch,' ');
   remote_ip = ++pch;
}
else remote_ip = localhost;



Windows:

Compilation:

NetBeans setup for programs compilation:

File → Project Properties:
C Compiler:
  - Include directories: .../Program Files/MPICH2/include
Linker:
  - Additional Library directories: .../Program Files/MPICH2/lib
  - Libraries: mpi.lib

program.c compilation from Cygwin command line “Cygwin Bash Shell” (without NetBeans use) using g++ (gcc, mpiCC):

  g++ program.c -I"C:\Program Files\MPICH2\include" -L"C:\Program Files\MPICH2\lib"  -lmpi



mpiexec.exe wrapper is used to run MPICH2 programs. smpd.exe manager has to be run/available on each computer(it is MPICH2 processes manager). Program mpiexec.exe can be controlled from command line or from interactive wmpiexec.exe console. Following figure shows example how to run program.



Availability and names of available neighborhood computers can be obtained from wmpiconfig.exe as is shown on the next figure (entries emphasized by green color are available). Click to Get Hosts first and then to Scan Hosts.

Remark: Do not forget check availability or copy required libraries to the executable file directory (usual file names: cyggcc_s-1.dll, cyggomp-1.dll, cygstdc++-6.dll, cygwin1.dll).

courses/b4m35pap/tutorials/06/start.txt · Last modified: 2021/11/26 00:14 by pisa