MPI函數
最近幾天開始接觸MPI編程了,雖然還是一頭霧水,沒有入門,但是先把自己整理的一些函數貼出來,方便以後查看。
管理函數
Int MPI(int *argc,char **argv)
Int MPI_Finalize(void) 清除MPI的所有狀態
Int MPI_Inilialized(int flag) 檢查是否調用了MPI_INIT
Int MPI_Error_String(int errorcode,char *string ,int *len) 檢查MPI函數錯誤
進程組操作函數
1. Int MPI_Comm_group(MPI_Comm comm,MPI_Group *group)
IN comm 通信子
OUT group 對應comm的進程組
用來建立一個通信子對應的新進程組,之後就可以對此進程組進行需要的操作
2. Int MPI_group_free(MPI_Group *group)
INOUT group 釋放進程組並返回MPI_Group_NULL
調用MPI_Group_free之後,任何關於此進程組的操作都視為無效
3. Int MPI_Group_size(MPI_Group group,int *size)
IN Group 進程組
OUT size 進程組中的進程個數
如果進程組是MPI_Group_Empty,則返回值size為0
4. Int MPI_Group_rank(MPI_Group group,int *rank)
IN Group 進程組
OUT Rank 進程在進程組中的編號
如果進程不是進程組中的成員,則返回值RANK為MPI_UNDEFINED
5. Int MPI_Group_translate_ranks(MPI_Group group1,int n,int *ranks1,MPI_Group group2,int *ranks2)
IN Group1 進程組1
IN n ranks1和ranks2中數組元素的個數
IN ranks1 進程組1中有效編號組成的數組
IN group2 進程組2
OUT ranks2 ranks1中的元素在進程組2中的對應編號
如果屬於進程組1的某個進程可以在ranks1中找到,而這個進程不屬於進程組2,則在ranks2中對應ranks1的位置返回值為MPI_UNDEFINED
6. Int MPI_Group_incl(MPI_Group group,int n,int *ranks,MPI_Group new group)
IN Group 進程組
IN n ranks數組中元素的個數和新進數組的大小
IN ranks 將在新進程組中出現的舊進程組中的編號
OUT newgroup 有ranks定義的順序導出的新進程組
7. Int MPI_Group_excl(MPI_Group group,int n,int *ranks,MPI_Group newgroup)
IN group 進程組
IN N ranks數組中元素的個數
IN ranks 在新進程組中不出現的舊進程組中的編號
OUT newgroup 舊進程組中不在ranks裏的元素組成的新進程組
8. Int MPI_Group_union(MPI_Group group1,MPI_Group group2,MPI_Group newgroup)
IN group1 進程組1
IN group2 進程組2
OUT newgroup 進程組1和進程組2的並
9. Int MPI_Group_intersection(MPI_Group group1,MPI_Group group2,MPI_Group newgroup)
IN group1 進程組1
IN group2 進程組2
OUT newgroup 進程組1和進程組2的交
10. Int MPI_Group_difference(MPI_Group group1,MPI_Group group2,MPI_Group newgroup)
IN group1 進程組1
IN group2 進程組2
OUT newgroup 進程組1和進程組2的差
MPI通信子操作
1. int MPI_Comm_Size(MPI_Comm comm,int *size)
IN comm 通信子
OUT size 通信子中的進程個數
2. int MPI_Comm_rank(MPI_Comm comm,int *rank)
IN comm 通信子
OUT rank 通信子中的進程編號
3. int MPI_Comm_dup(MPI_Comm comm,MPI_Comm *newcomm)
IN comm 通信子
OUT newcomm comm通信子的複製
4. int MPI_Comm_Create(MPI_Comm comm,MPI_Group group,MPI_Comm *newcomm)
IN comm 通信子
IN group 通信子comm的一個子集
OUT newcomm 對應group的一個新通信子
5. int MPI_Comm_Split(MPI_Comm comm,int color,int key,MPI_Comm *newComm)
IN comm 通信子
IN color 子集控製值
IN key 子集進程編號的順序
OUT newcomm 由此產生的新通信子
劃分comm所對應的進程組為不相交的子進程組,每個子進程組有一個共同的值color
6. int MPI_Comm_free(MPI_Comm *Comm)
INOUT comm 通信子
點到點通信函數
一對進程之間的數據轉換,也就是說一邊發送數據另一邊接收數據,點到點通信是MPI通信機製的基礎,它分為同步通信和異步通信二種機製。
阻塞式通信函數
1. int MPI_send(void *buf,int count,MPI_Datatype datatype,int dest,int tag,MPI_Comm comm)
IN buf 所要發送消息數據的首地址
IN count 發送消息數組元素的個數
IN datatype 發送消息的數據類型
IN dest 接收消息的進程編號
IN tag 消息標簽
IN comm 通信子
2. int MPI_Recv(void *buf,int count,MPI_Datatype datatype,int source,int tag,MPI_Comm comm,MPI_Status *status)
OUT buf 接收消息數據的首地址
IN Count 接收消息數組元素的最大個數
IN datatype 接收消息的數據類型
IN source 發送消息的進程編號
IN tag 消息標簽
IN comm 通信子
OUT status 接收消息時返回的狀態
3. int MPI_Get_Count(MPI_Status status,MPI_Datatype datatype,int *count)
IN status 接收消息時返回的狀態
IN datatype 接收消息時返回的類型
OUT Count 接收消息時數組元素的個數
4. int MPI_Sendrecv(void *sendbuf,int sendcount,MPI_Datatype sendtype,int dest,int sendtag,void *recvbuf,int recvcount,MPI_Datatype recvtype,int source,int recvtag,MPI_Comm comm,MPI_Status *status)
IN sendbuf 所要發送消息數據的首地址
IN sendcount 發送消息數組元素的個數
IN sendtype 發送消息的數據類型
IN dest 接收消息的進程編號
IN sendtag 發送消息標簽
OUT recvbuf 接收消息數據的首地址
IN recvcount 接收消息數組元素的最大個數
IN recvtype 接收消息的數據類型
IN Source 發送消息的進程編號
IN recvtag 接收消息標簽
IN comm 通信子
OUT status 接收消息時返回的狀態
5. int MPI_Sendrecv_replace(void *sendbuf,int count,MPI_Datatype datatype,int dest,int sendtag,int source,int recving,MPI_Comm comm,MPI_Status *status)
OUT buf 發送和接收消息數據的首地址
IN Count 發送和接收消息數組元素的個數
IN dest 接收消息的進程編號
IN sendtag 發送消息標簽
IN source 發送消息的進程編號
IN recvtag 接收消息標簽
IN comm 通信子
OUT status 接收消息時返回的狀態
6. int MPI_probe(int source,int tag,MPI_Comm comm,MPI_Status *status)
IN source 發送消息進程的編號
IN tag 接收消息的標簽
IN comm 通信子
OUT status 返回到消息的狀態
7. int MPI_Iprobe(int source,int tag,MPI_Comm comm,int *flag,MPI_Status *status)
IN source 發送消息進程的編號
IN tag 接收消息的標簽
IN comm 通信子
OUT flag 如果指定消息已經到達,flag返回值為true
OUT status 返回到達消息的狀態
非阻塞式通信函數
非阻塞式通信函數是指在通信過程中,不需要等待通信結束就返回,通常這種通信過程交由計算機的後台來處理,如果計算機係統提供硬件支持非阻塞式通信函數,就可以使計算與通信在時間上的重疊,從而提高並行計算的效率。
1. int MPI_Isend(void *buf,int count,MPI_Datatype datatype,int dest,int tag,MPI_Comm comm,MPI_Request *request)
IN buf 所要發送消息數據的首地址
IN count 發送消息數組元素的個數
IN datatype 發送消息的數據類型
IN dest 接收消息的進程編號
IN tag 消息標簽
IN comm 通信子
OUT request 請求句柄一杯將來查詢
2. int MPI_Irecv(void *buf,int count,MPI_Datatype datatype,int source,int tag,MPI_Comm comm,MPI_Request *request)
OUT buf 接收消息數據的首地址
IN Count 接收消息數組元素的個數
IN datatype 接收消息的數據類型
IN source 發送消息的進程編號
IN tag 消息標簽
IN comm 通信子
OUT request 請求句柄以北將來查詢
MPI_Isend和MPI_Irecv不需要等待發送或接收消息完成就可以執行其他任務
3. Int MPI_wait(MPI_Request *request,MPI_Status *status)
INOUT request 請求句柄
OUT status 發送或接收消息的狀態
如果request所指的操作已經完成,MPI_Wait將結束等待狀態
4. Int MPI_Test(MPI_Request *request,int *flag,MPI_Status *status)
INOUT request 請求句柄
OUT flag request所指的操作已經完成返回值為true
OUT status 發送或接收消息的狀態
5. Int MPI_Request_free(MPI_Request *request)
INOUT request 請求句柄,返回值為MPI_Request_null
對單個request進行查詢
6. Int MPI_Waitany(int count,MPI_Request *array_of_requests,int *index,MPI_Status *status)
IN count 請求句柄的個數
INOUT array_of_requests 請求句柄數組
OUT index 已經完成通信操作的句柄指標
OUT status 消息的狀態
當所有請求句柄中至少有一個已經完成通信操作,就返回,如果有多於一個請求句柄已經完成,MPI_waitany將隨機選擇其中的一個並立即返回
7. Int MPI_Testany(int Count,MPI_Request *array)
IN count 請求句柄個數
INOUT array_of_requests 請求句柄數組
OUT index 已經完成通信操作的句柄指標
OUT flag 如果有一個已經完成,則flag=true
OUT status 消息的狀態
無論有沒有通信操作完成都將立即返回
8. Int MPI_Waitall(int Count,MPI_Request *array_of_requests)
IN count 請求句柄的個數
INOUT array_of_requests 請求句柄數組
INOUT array_of_status 所有消息的狀態數組
所有通信操作完成之後才返回,否則將一直等待
9. Int MPI_Testall(int Count,MPI_Request *array_of_requests,int *flag,MPI_Status *array_of_status)
IN count 請求句柄的個數
INOUT array_of_requests 請求句柄數組
OUT flag 如果有一個沒完成,則flag=false
INOUT array_of_status 所有消息的狀態數組
無論所有通信操作是否完成都立即返回
10. Int MPI_Cancel(MPI_Request *request)
INOUT request 請求句柄
取消一個發送或接收操作
11. Int MPI_Test_cancelled(MPI_Status *status,int *flag)
IN status 消息的狀態
OUT flag 如果已經取消,則flag=true
特殊的點到點通信函數
1. Int MPI_Send_init(void *buf,int count,MPI_Datatype datatype,int dest,int tag,MPI_Comm comm,MPI_Request *request)
IN buf 所要發送消息數據的首地址
IN count 發送消息數組元素的個數
IN datatype 發送消息的數據類型
IN dest 接收消息的進程編號
IN tag 消息標簽
IN comm 通信子
OUT request 請求句柄以備將來查詢
2. Int MPI_Recv_init(void *buf,int count,MPI_Datatype datatype,int source,int tag,MPI_Comm comm,MPI_Request *request)
OUT buf 接收消息數據的首地址
IN count 接收消息數組元素的個數
IN datatype 接收消息的數據類型
IN Source 發送消息的進程編號
IN tag 消息標簽
IN comm 通信子
OUT request 請求句柄以備將來查詢
3. Int MPI_Start(MPI_Request *request)
INOUT request 請求句柄
4. Int MPI_Startall(int count,MPI_Request *array_of_request)
IN Count 需要激活的請求句柄個數
INOUT array_of_request 請求句柄數組
最後更新:2017-04-02 06:52:19