MPI_File_open针对特定文件挂起问题求助
MPI_File_open调用挂起问题排查请求
环境信息
- 操作系统:Debian 12.2.0
- MPI版本:mpiexec(OpenRTE) 4.1.4
- 执行命令:
mpiexec -n 1 DM_2D_code/DiMo2d/code/dipha-2d-thresh/build/dipha --upper_dim 2 --pixel_threshold 255 scratch_1/39/dipha_inputfile scratch_1/39/diagram_filename scratch_1/39/dipha_edge_filename 57 336
问题描述
执行上述命令时,程序调用MPI_File_open打开文件scratch_1/39/dipha_edge_filename出现挂起:
- 文件已被创建为空白文件,但程序卡在
ret = MPI_File_open(MPI_COMM_WORLD, filename1, access, MPI_INFO_NULL, &file);行无法继续执行 - 此前使用只读模式(
file_open_read_only)调用MPI_File_open可正常工作
相关代码
inline MPI_File file_open(const std::string& filename, int access) { int ret; // MPI_Barrier(MPI_COMM_WORLD); std::cout << "MPI filename: " << filename << std::endl; std::cout << "Rank: " << get_rank() << std::endl; MPI_File file; std::cout << "File: " << file << std::endl; char *filename1 = const_cast<char *>(filename.c_str()); // char *filename2 = "scratch_1/39/filename1"; // std::cout << "MPI filename new: " << filename1 << std::endl; // std::cout << "MPI filename type: " << typeid(filename1).name() << std::endl; // std::cout << "MPI filename type: " << typeid(filename2).name() << std::endl; ret = MPI_File_open(MPI_COMM_WORLD, filename1, access, MPI_INFO_NULL, &file); std::cout << "Return: " << ret << std::endl; if ( ret != 0) { std::cerr << "Entering IS_ROOT " << filename << std::endl; if (mpi_utils::is_root()) { std::cerr << "Error while opening file " << filename << std::endl; MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); } } return file; } inline MPI_File file_open_read_only(const std::string& filename) { return file_open(filename, MPI_MODE_RDONLY); } inline MPI_File file_open_write_only(const std::string& filename) { return file_open(filename, MPI_MODE_WRONLY | MPI_MODE_CREATE); } inline MPI_File file_open_read_write(const std::string& filename) { return file_open(filename, MPI_MODE_RDWR | MPI_MODE_CREATE); }
程序输出(挂起前最后输出)
MPI filename: scratch_1/39/dipha_edge_filename Rank: 0 File: 0x63e600000000
可能的排查方向
- MPI-IO模式兼容性:尽管是单进程运行,
MPI_File_open是集体操作,部分MPI实现对写模式(MPI_MODE_WRONLY|MPI_MODE_CREATE)的单进程处理存在异常,可尝试替换为MPI_MODE_RDWR|MPI_MODE_CREATE测试,或检查MPI实现是否支持单进程写模式的原子操作 - 文件系统权限/特性:文件虽已创建,但可能存在父目录权限限制、文件系统不支持MPI-IO所需的锁机制或原子写入特性(如NFS挂载的目录可能存在此类问题)
- MPI实现bug:OpenRTE 4.1.4版本的
MPI_File_open可能存在写模式下的单进程挂起问题,可尝试升级至最新版本或切换至MPICH等其他MPI实现验证 - 字符串指针问题:代码中使用
const_cast<char*>(filename.c_str())转换文件名指针,虽单进程下生命周期足够,但部分MPI实现可能要求传入非const的可修改缓冲区,可尝试将文件名复制到本地char数组后传入测试
内容的提问来源于stack exchange,提问作者Samik Banerjee
相关产品推荐
相关产品推荐

