MPI_SendRecv定时

MPI_SendRecv定时,c,mpi,openmpi,C,Mpi,Openmpi,当我通过更改不同的缓冲区大小来使用以下代码时,无论我设置的Dim有多大,我都会得到类似的MPI\u SendRecvAPI调用时间(大约0.5s) MPI调用的计时方法是否有问题? 或 是MPI API调用的异步化(调用后立即返回)吗? #包括 #包括 #包括 int main(int argc,char*argv[]) { 浮球*d_味精; 如果(argc

当我通过更改不同的缓冲区大小来使用以下代码时,无论我设置的
Dim
有多大,我都会得到类似的
MPI\u SendRecv
API调用时间(大约0.5s)

MPI调用的计时方法是否有问题?
是MPI API调用的异步化(调用后立即返回)吗?

#包括
#包括
#包括
int main(int argc,char*argv[])
{
浮球*d_味精;
如果(argc<3){
printf(“./exe ndevices Dim\n”);
出口(-1);
}
int myrank,tag=0;
MPI_状态;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_Comm_WORLD和myrank);
如果(myrank==0)
printf(“\n\n=MPI开始=;
const int numu GPUs=2;
常数int Dim=100;
Cudamaloc((无效**)和d_msg,尺寸*尺寸(浮动));
双t1,t2;
t1=MPI_Wtime();
MPI_Sendrecv(数据单元消息,Dim,MPI_浮点,(myrank+1)%num_GPU,标记,数据单元消息,Dim,MPI_浮点,(myrank-1+num_GPU)%num_GPU,标记,MPI_通信世界和状态);
t2=MPI_Wtime();
printf(“经过的时间是%f\n”,t2-t1);
MPI_Finalize();
printf(“--*--MPI排名:%d结束--*--\n”,myrank);
返回0;
}

这可能是等待时间。在测量
t1
之前,先调用
MPI\u Barrier
。在某些MPI实现中,某些设置是在第一次通信期间执行的,因此您可能在此处测量此开销。正确的基准测试方法是运行几次预热迭代,然后不仅运行一次,还运行几次
MPI\u Sendrecv()
(比
MPI\u Wtick()
计时器分辨率要长得多)。
#include <stdio.h>
#include <string.h>
#include <mpi.h>

int main(int argc, char *argv[])
{
    float *d_msg;

    if (argc < 3){
        printf("./exe ndevices Dim\n");
        exit(-1);
    }

    int myrank, tag=0;
    MPI_Status status;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
    if (myrank == 0)
        printf("\n\n===== MPI Start =====\n");
        
    const int num_GPUs = 2;
    const int Dim = 100;

    cudaMalloc((void**)&d_msg, Dim*sizeof(float)); 

    double t1, t2; 
    t1 = MPI_Wtime(); 

    MPI_Sendrecv(d_msg, Dim, MPI_FLOAT, (myrank + 1)%num_GPUs, tag, d_msg, Dim, MPI_FLOAT, (myrank - 1 + num_GPUs)%num_GPUs, tag, MPI_COMM_WORLD, &status);

    t2 = MPI_Wtime(); 
    printf( "Elapsed time is %f\n", t2 - t1 ); 

    MPI_Finalize();
    printf("--*-- MPI Rank: %d END--*--\n", myrank);


    return 0;
}