1.什么是MPI
2.第一个MPI程序
int main() { int rank; int allProcess; MPI_Comm worker_comm; MPI_Init(nullptr, nullptr); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &allProcess); MPI_Finalize(); return 0; }
下面我们来逐个介绍上例中使用的MPI函数:
一些常用函数
MPI作为一个用来传递信息的协议,核心肯定是通信,我们先介绍几组常用的通信函数
int MPI_Send (void *buf, int count, MPI_Datatype datatype,int dest, int tag,MPI_Comm comm) int MPI_Recv (void *buf, int count, MPI_Datatype datatype,int source, int tag, MPI_Comm comm,MPI_Status *status)
int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source,int tag, MPI_Comm comm, MPI_Request *request) int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag,MPI_Comm comm, MPI_Request *request)
int MPI_Wait(MPI_Request *request, MPI_Status *status)
当程序运行到时MPI_Wait,会堵塞直到MPI_Wait传入的句柄参数对应的函数被完成。
下面是一个比较完整的函数列表:
MPI_Get_library_version
#undef FUNCNAME #define FUNCNAME MPI_Get_library_version #undef FCNAME #define FCNAME MPL_QUOTE(FUNCNAME)
MPI_Graph_neighbors_count
MPI_Info_get
#undef FUNCNAME #define FUNCNAME MPI_Info_get #undef FCNAME #define FCNAME MPL_QUOTE(FUNCNAME) int MPI_Info_get(MPI_Info info, const char *key, int valuelen, char *value, int *flag)
通过key查找value
MPI_Info_get_nkeys
#undef FUNCNAME #define FUNCNAME MPI_Info_get_nkeys #undef FCNAME #define FCNAME MPL_QUOTE(FUNCNAME) int MPI_Info_get_nkeys( MPI_Info info, int *nkeys )
返回info中key的数量
MPI_Info_get_nthkey
#undef FUNCNAME #define FUNCNAME MPI_Info_get_nthkey #undef FCNAME #define FCNAME MPL_QUOTE(FUNCNAME) int MPI_Info_get_nthkey( MPI_Info info, int n, char *key )
返回info的第n个key
MPI_Info_get_valuelen
#undef FUNCNAME #define FUNCNAME MPIRInfo_get_valuelen #undef FCNAME #define FCNAME MPL_QUOTE(FUNCNAME) int MPI_Info_get_valuelen( MPI_Info info, const char *key, int *valuelen, int *flag )
检索与密钥相关联的值的长度
MPI_File_iwrite
#ifdef HAVE_MPI_GREQUEST #include "mpiu_greq.h" #endif int MPI_File_iwrite(MPI_File fh, ROMIO_CONST void *buf, int count,MPI_Datatype datatype, MPI_Request *request)
非堵塞的运用单独指针写
MPI_File_iwrite_at
#ifdef HAVE_MPI_GREQUEST #include "mpiu_greq.h" #endif int MPI_File_iwrite_at(MPI_File fh, MPI_Offset offset, ROMIO_CONST void *buf,int count, MPI_Datatype datatype, MPIO_Request *request)
非阻塞使用显式偏移写
MPI_File_iwrite_shared
#ifdef HAVE_MPI_GREQUEST #include "mpiu_greq.h" #endif int MPI_File_iwrite_shared(MPI_File fh, ROMIO_CONST void *buf, int count, MPI_Datatype datatype, MPIO_Request *request)
使用共享文件指针进行非阻塞写入
以上难免有不足或错误之处,愿大佬们能在评论区不吝赐教。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208428.html原文链接:https://javaforall.net
