gpt4 book ai didi

c - MPI 段错误(信号 11)

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:13 25 4
gpt4 key购买 nike

我已经尝试了两天多,想看看我犯了什么错误,但我找不到任何东西。我不断收到以下错误:

= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES

= EXIT CODE: 139

= CLEANING UP REMAINING PROCESSES

= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES

YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)

This typically refers to a problem with your application.

Please see the FAQ page for debugging suggestions

make: *** [run] Error 139

所以问题在 MPI_BCAST 和我有 MPI_GATHER 的另一个函数中很明显。你能帮我找出问题所在吗?当我编译代码时,我输入以下内容:

/usr/bin/mpicc  -I/usr/include   -L/usr/lib  z.main.c  z.mainMR.c  z.mainWR.c  -o  1dcode -g  -lm

对于运行:

usr/bin/mpirun -np 2 ./1dcode dat.txt o.out.txt

例如我的代码包含这个函数:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include "functions.h"
#include <mpi.h>
/*...................z.mainMR master function............. */
void MASTER(int argc, char *argv[], int nPROC, int nWRs, int mster)
{

/*... Define all the variables we going to use in z.mainMR function..*/
double tend, dtfactor, dtout, D, b, dx, dtexpl, dt, time;
int MM, M, maxsteps, nsteps;
FILE *datp, *outp;
/*.....Reading the data file "dat" then saving the data in o.out.....*/
datp = fopen(argv[1],"r"); // Open the file in read mode
outp = fopen(argv[argc-1],"w"); // Open output file in write mode
if(datp != NULL) // If data file is not empty continue
{
fscanf(datp,"%d %lf %lf %lf %lf %lf",&MM,&tend,&dtfactor,&dtout,&D,&b); // read the data
fprintf(outp,"data>>>\nMM=%d\ntend=%lf\ndtfactor=%lf\ndtout=%lf\nD=%lf\nb=%lf\n",MM,tend,dtfactor,dtout,D,b);
fclose(datp); // Close the data file
fclose(outp); // Close the output file
}
else // If the file is empty then print an error message
{
printf("There is something wrong. Maybe file is empty.\n");
}

/*.... Find dx, M, dtexpl, dt and the maxsteps........*/
dx = 1.0/ (double) MM;
M = b * MM;
dtexpl = (dx * dx) / (2.0 * D);
dt = dtfactor * dtexpl;
maxsteps = (int)( tend / dt ) + 1;

/*...Pack integers in iparms array, reals in parms array...*/
int iparms[2] = {MM,M};
double parms[4] = {dx, dt, D, b};
MPI_BCAST(iparms,2, MPI_INT,0,MPI_COMM_WORLD);
MPI_BCAST(parms, 4, MPI_DOUBLE,0, MPI_COMM_WORLD);
}

最佳答案

运行时错误是由于 MPICH 的特定特性和 C 语言的特性的不幸组合造成的。

MPICH 在单个库文件中同时提供 C 和 Fortran 接口(interface)代码:

000000000007c7a0 W MPI_BCAST
00000000000cd180 W MPI_Bcast
000000000007c7a0 W PMPI_BCAST
00000000000cd180 T PMPI_Bcast
000000000007c7a0 W mpi_bcast
000000000007c7a0 W mpi_bcast_
000000000007c7a0 W mpi_bcast__
000000000007c7a0 W pmpi_bcast
000000000007c7a0 T pmpi_bcast_
000000000007c7a0 W pmpi_bcast__

Fortran 调用以各种别名导出,以便同时支持许多不同的 Fortran 编译器,包括全部大写的 MPI_BCASTMPI_BCAST 本身未在 mpi.h 中声明,但 ANSI C 允许调用函数而无需预先声明原型(prototype)。通过将 -std=c99 传递给编译器来启用 C99 会导致关于 MPI_BCAST 函数的隐式声明的警告。 -Wall 也会导致警告。代码将无法与 Open MPI 链接,Open MPI 在单独的库中提供 Fortran 接口(interface),mpicc 未链接到该库。

即使代码编译和链接正确,Fortran 函数也期望它们的所有参数都通过引用传递。此外,Fortran MPI 调用采用一个额外的输出参数,用于返回错误代码。因此段错误。

为防止以后出现此类错误,请使用-Wall -Werror 进行编译,这样可以尽早捕获类似问题。

关于c - MPI 段错误(信号 11),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33283681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com