- message passing model
- the Message Passing Interface (MPI) - standard interface
- MPI is only a definition for an interface
几个重要的概念
- communicator: 由一系列进程组成,拥有沟通的能力
- 每个进程都有 rank 沟通交流靠秩 + tag(标记信息)
- point-to-point communications | collective communications
编程篇
假设有个.c 文件 mpi
mpicc mpi_hello_world.c -o hello_world
mpirun -np 4 -f host_file hello_world //np 是processing的数量
//host_file 记录着集群的信息
host_file
Ailab1
Ailab2
Ailab3
如果不想平均分,想根据核数来
host_file
Ailab1:2
Ailab2:2
Ailab3:2
即可 有限Ailab1的两核,用完了再下一个
- Sending and receiving are the two foundational concepts of MPI.
- MPI allows senders and receivers to also specify message IDs with the message (known as tags)
send 和 recive 的原型
MPI_Send(
void* data,
int count, // 送出了这么多 exactly
MPI_Datatype datatype,
int destination,
int tag,
MPI_Comm communicator)
MPI_Recv(
void* data,
int count, // 最多接受这么多 at most
MPI_Datatype datatype,
int source,
int tag,
MPI_Comm communicator,
MPI_Status* status)
mpi datatype
MPI datatype | C equivalent |
---|---|
MPI_SHORT | short int |
MPI_INT | int |
MPI_LONG | long int |
MPI_LONG_LONG | long long int |
MPI_UNSIGNED_CHAR | unsigned char |
MPI_UNSIGNED_SHORT | unsigned short int |
MPI_UNSIGNED | unsigned int |
MPI_UNSIGNED_LONG | unsigned long int |
MPI_UNSIGNED_LONG_LONG | unsigned long long int |
MPI_FLOAT | float |
MPI_DOUBLE | double |