MPI几个API函数介绍

Catalog 目录

1 - 1.1  int MPI_Init(int *argv,char **argc);

    1.2   int MPI_Finalize(void);

    1.3   int MPI_Comm_size(MPI_Comm comm, int *size);

    1.4   int MPI_Comm_rank(MPI_Comm comm, int *rank);

    1.5   int MPI_Send(void* buf, int count, MPI_Datatype datatype,  int dest,int tag, MPI_Comm comm);

    1.6   int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, inttag, MPI_Comm comm, MPI_Status *status);

    1.7   int MPI_Get_count(MPI_Status status, MPI_Datatype datatype,int* count);

    1.8   int MPI_Comm_size(MPI_Comm comm,int &size);

    1.9   int MPI_Get_processor_name(char *name, char *resultlen);

    1.10 int MPI_Wtime(void);

1.1 int MPI_Init(int *argv,char **argc); 

        初始化MPI环境。

        通信域(通信空间):MPI_COMM_WORLD:。一个通信空间是一个进程组和一个上下文的组合。上下文可看作为组的超级标签,用于区分不同的通信域。在执行函数MPI_Init之后,一个MPI程序的所有进程形成一个缺省的组,这个组的通信域即被写作MPI_COMM_WORLD。该参数是MPI通信操作函数中必不可少的参数,用于限定参加通信的进程的范围。这类似于namespace,但是通信域不仅包括了组的标示符,还包括组里面的进程。

1.2 int MPI_Finalize(void); 

        结束MPI程序的运行。这里只是告知该MPI的并行代码执行结束,而不是整个程序结束执行退出。在MPI_Finalize之后的代码还是会继续串行执行。

1.3 int MPI_Comm_size(MPI_Comm comm, int *size); 

        获取进程个数,大小给size。

1.4 int MPI_Comm_rank(MPI_Comm comm, int *rank); 

        获取当前进程编号rank,该值范围[0,p-1],p为并行进程个数。

1.5 int MPI_Send(void* buf, int count, MPI_Datatype datatype,  int dest,int tag, MPI_Comm comm);   

        发送消息:intMPI_Send(void* buf, int count, MPI_Datatype datatype,  int dest,int tag, MPI_Comm comm);  

        IN buf           发送缓冲区的起始地址

        IN count       要发送信息的元素个数(元素个数不一定等于字节个数,因为一个元素可能包含多个字节)

        IN datatype  发送信息的数据类型

        IN dest         接收消息进程的rank值

        IN tag           消息标签(标识消息)

        IN comm      通信域

1.6 int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, inttag, MPI_Comm comm, MPI_Status *status); 

        接收消息:intMPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, inttag, MPI_Comm comm, MPI_Status *status);  

        OUT buf        接收缓冲区的起始地址,接收缓存应>=count*sizeof(datatype),否则将造成溢出

        IN count        要接收信息的元素个数

        IN datatype   接收信息的数据类型

        IN source     发送消息进程的rank值。使用MPI_ANY_SOURCE,可以接收来自任意进程的消息

        IN tag           消息标签(只接收与发送消息中tag值相同的消息)。使用MPI_ANY_TAG,可以接收任意标签的消息

        IN comm      通信域

        OUTstatus status对象,包含实际接收到的消息的有关信息。可以通过status.MPI_SOURCE,status.MPI_TAG分别获取发送消息的进程和消息标签

1.7 int MPI_Get_count(MPI_Status status, MPI_Datatype datatype,int* count); 

        获取实际接收到消息的长度:intMPI_Get_count(MPI_Status status, MPI_Datatype datatype,int* count);

        INstatus         接收操作的返回值.

        INdatatype     接收缓冲区中元素的数据类型.

        OUTcount      接收消息中的元素个数.

1.8 int MPI_Comm_size(MPI_Comm comm,int &size); 

        获取指定通信域中的进程数:int MPI_Comm_size(MPI_Comm comm,int &size);

        INcomm        通信域

        OUTsize        通信域中的进程数

1.9 int MPI_Get_processor_name(char *name, char *resultlen);

        返回当前进程所在处理器的名称。该名称根据网络地址命名地,name缓冲区的大小必须大于MPI_MAX_PROCESSOR_NAME,真正的长度返回在resultlength变量中。

        MPI_Get_processor_name(*name,*resultlength);

1.10 int MPI_Wtime(void);

        返回调用进程已执行过的时间,单位秒,双精度。

猜你喜欢

转载自blog.csdn.net/qq_39478139/article/details/106373923
mpi