Let's start MPI.
What you will get
- to compile
*.cor*.cppusingmpiccormpic++. - to run outputs using
mpirun -npormpiexec -np.
OpenMP와 MPI
병렬 알고리즘을 작성하는 방법에는 크게 2가지가 있다.
위의 2가지를 구분짓는 가장 큰 차이점은 병렬화 실행단위(?)가 thread와 process라고 생각한다.
(아무런 사전 조치가 없다면) thread끼리는 메모리를 공유할 수 있고, process끼리는 memory를 공유할 수 없다.3
메모리를 공유할 수 없다는 사실 대해서 자세하게 많은 이야기가 있다. (필자가 아는게 아니고, 많은 이야기가 있다는 사실을 알 뿐이다.)
병렬코드를 작성하는 필자의 목적은 클러스터 컴퓨터 최대한 사용하기이다. 일반 컴퓨터는 물리적으로 보드 1개, CPU 1개가 보편적이다. 하지만 클러스터 컴퓨터는 보드가 여러장 꽂혀있고, 그 보드마다 CPU가 꽂혀있다.
결국 클러스터 컴퓨터를 사용하려면, 2가지를 혼용해야 한다. 2가지의 사용기준은 보드 내부 병렬화는 OpenMP, 보드사이 병렬화는 MPI이다.
MPI의 샘플 코드
오늘의 목표는 아래의 샘폴 코드를 컴파일하고 실행하기이다.
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hello world from processor %s, rank %d"
" out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
- 컴파일
gcc test.c -o testmpicc test.c -o test
- 실행
./testmpiexec –np 16 ./testORmpirun –np 16 ./test
-
Multi Processing (see OpenMP Official Website). ↩
-
Message Passing Interface (see OpenMPI Official Website). ↩