You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL2中MPI_Alltoallw调用无输出问题排查求助

问题
  • 我用C++编写了一个调用MPI_Alltoallw的MPI程序,在多台机器运行时出现不一致:
    • 搭载Intel i5-4590T CPU的Fedora机器:程序正常,输出缓冲区被正确填充
    • 运行Ubuntu 22.04的WSL2 Windows机器(主机CPU为i7-7820x):MPI_Alltoallw调用未修改输出缓冲区,编译和运行阶段均无报错
  • 两台机器环境一致点:均使用mpic++编译,WSL2上g++版本为11.3.0,Fedora上为11.3.1;OpenMPI版本均为4.1.4
  • 额外测试结果:
    • 在HPC系统(RHEL 8.4,g++ 11.3.0,OpenMPI 4.1.4)上测试相同代码,运行正常
    • WSL2上的简单MPI调用(如通信器初始化、MPI_Bcast)可正常工作
  • 疑问:该问题是WSL2的已知问题,还是我的代码存在错误?
代码最小示例(使用Eigen库)
#include <iostream>
#include <Eigen/Dense>
#include <unsupported/Eigen/CXX11/Tensor>
#include <cmath>
#include <complex>
#include <mpi.h>

int main() {

    MPI_Init(NULL, NULL);

    const int nc = 8;
    const int nzc = 8;
    const int nz2 = nzc*nc/2;
    const int nzd = 3*nz2;
    const int nxs2 = 32;
    const int ny = 128;
    const int nyc = ny/nc;

    const int nbytes_cmplxd = 16;

    Eigen::TensorFixedSize<std::complex<double>, Eigen::Sizes<ny, nxs2 + 1, nzc>> xc;
    Eigen::TensorFixedSize<std::complex<double>, Eigen::Sizes<nyc, nxs2+1, nzd>> buf2;

    xc.setRandom(); //xc is set to some values
    buf2.setZero(); 

    int count[nc];
    //initialize counts to 1
    for (int i = 0; i < nc; i++) {
        count[i] = 1;
    }

    //first initializes mpi types and displacements for the transposition from xc to buf2
    //init simple datatypes
    MPI_Datatype sendloc1; 
    MPI_Datatype recvloc1;

    MPI_Type_vector(nzc*(nxs2+1), nyc, ny, MPI_DOUBLE_COMPLEX, &sendloc1);
    MPI_Type_commit(&sendloc1);

    MPI_Type_vector(nzc*(nxs2+1)*nyc, 1, 1, MPI_DOUBLE_COMPLEX, &recvloc1);
    MPI_Type_commit(&recvloc1);

    int senddisp1[nc];
    int recvdisp1[nc];
    MPI_Datatype sendtypev1[nc];
    MPI_Datatype recvtypev1[nc];

    for (int i = 0; i<nc; i++) {
        senddisp1[i] = nbytes_cmplxd * i * (nyc); //displacement due to column major ordering

        if (i<(nc/2)) {
            recvdisp1[i] = nbytes_cmplxd * i * (nzc*(nxs2+1)*nyc); //displacement equal to entire size of recvtype
        } else { //add displacement to introduce padding (equal to 1/3 of the array size)
            recvdisp1[i] = nbytes_cmplxd * (i * (nzc*(nxs2+1)*nyc) + nz2*(nxs2+1)*nyc);
        }

        sendtypev1[i] = sendloc1; 
        recvtypev1[i] = recvloc1;
    } 

    //committing the MPI_Datatype vectors is not needed

    MPI_Alltoallw(xc.data(), count, senddisp1, sendtypev1, 
                  buf2.data(), count, recvdisp1, recvtypev1, MPI_COMM_WORLD);

    std::cout << buf2 << std::endl; //buf2 is zero after the call

    MPI_Finalize();

    return 0;
}

内容的提问来源于stack exchange,提问作者davideperrone

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 06:15:32