我看到有很多与此相关的问题,但我没有找到与我相似的问题。我在 LSF 平台上运行一个用 C 和 Fortran 混合编写的模型。连线的事情是我的模型运行良好,直到上周它开始抛出这个错误。甚至连线都是错误不会每次都发生:有时,模型可以运行(没有错误),有时在尝试读取输入文件时作业会中止。错误指向我从未修改过的代码到目前为止我已经尝试过:
1)重新编译源代码并使用新创建的可执行文件;
2)从另一个运行良好的目录复制可执行文件;
3)删除整个目录,新建一个目录,重复以上两步;
4)从新登录开始
5)每次只运行1个作业,排除同节点上运行的其他作业影响的可能性
6)更改工作名称
7)改变运行长度(车型年)
并且错误仍然发生 90% 的时间。错误指向 inpakC.c 文件(我在下面附加了文件的一部分)'free(line)' 部分。我看不出有什么问题,因为它是预先编写的代码。任何帮助或建议将不胜感激!
#ifdef MPI
int ipck_LoadF(char *filename, MPI_Comm comm)
#else
int ipck_LoadF(char *filename)
#endif
{
/*local variables */
FILE *fileptr; /*pointer to the file */
int bsize; /*buffer size (this was the default used in
int maxLsize; /*max line size(this was the default used in
char *line; /*the next line in the file */
int n, m, clrt;
int my_address;
int c;
my_address =0;
#ifdef MPI
MPI_Comm_rank(comm, &my_address);
#endif
if(my_address == 0){
bsize = 0;
maxLsize = 0;
clrt = 1; /*current line running total set to zero*/
/*open the file */
/*if the file was not opened, exit and return 1 */
if ((fileptr = fopen(filename, "r")) == NULL)
{
return 1;
}
/*go through file and count the number of elements - used to know how much mem to allocate*/
while ((c = fgetc(fileptr)) != EOF)
{
bsize++;
clrt++;
/*get length of longest line*/
if (c == '\n')/*end of the line has been reached*/
{
if (clrt > maxLsize)/*line contains the most char so far*/
{
maxLsize = clrt;
clrt = 1;
}
else /*line has less char than the record so just reset the counter*/
{
clrt = 1;
}
}
}
/*allocate mem for the buffer*/
buffer = (char *) calloc(bsize, sizeof(char));
/*postion pointer back to the begining*/
rewind(fileptr);
/*read the contents of the file into the buffer variable */
while (!feof(fileptr))
{
/*allocate memory to hold the line to read into and the trimmed line */
line = (char *) calloc(maxLsize, sizeof(char));
/*get the next line */
fgets(line, maxLsize, fileptr);
/*see if the next line is blank; if so skip the rest
and continue retrieving lines*/
if( strcmp(line, "\n")==0) continue;
/*get the position of the comment character.
if one does not exist, it will return the length of the string*/
n=strcspn(line,"#");
m=n-2;
while (*(line+m)==' ' || *(line+m)=='/' || *(line+m)=='\n'){
n--;
m--;
}
if (n > 0){
/*cat n-1 chars to the buffer */
strncat(buffer,line,n-1);
}
/*put a padded space after the new line added to the buffer */
strcat(buffer, " ");
/*clean up strings and flush */
free(line);
fflush(fileptr);
}
/*close the file */
fclose(fileptr);
}
/*broadcast to all of the nodes*/
#ifdef MPI
MPI_Bcast(&bsize,1,MPI_INT,0,comm);
if (my_address != 0)
buffer = (char *) calloc(bsize, sizeof(char));
MPI_Bcast(buffer,bsize,MPI_CHAR,0,comm);
#endif
return 0;
}