c - 从 MPI 中的文本文件中读取
问题描述
我正在尝试从 txt 文件中读取 int 和 double 。当我在控制台中运行该进程时,一切正常,但是当我使用单个进程通过 MPI 工作时,它给了我一个错误:
$ ./a.out
job aborted:
rank: node: exit code [: error message]
0: DESKTOP-QUJB667: -1073740791: process 0 exited without calling finalize
我只使用了两个命令从文件中读取:
FILE * file = fopen ("pixel.txt", "r");
fscanf (file, "% d", & numOfPixelsInFile);
从文件读取的问题只是我必须做的更广泛任务的初始阶段。
#include <mpi.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct Pixel
{
int id;
int x;
int y;
float rgb[3];
};
int main(int argc, char *argv[])
{
int namelen, numprocs, myid;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Get_processor_name(processor_name, &namelen);
if (myid == 0)
{
FILE* file = fopen("pixel.txt", "r");
//Pixel arguments
int id, x, y;
float rgb1;
float rgb2;
float rgb3;
int numOfPixelsInFile = 0;
fscanf(file, "%d", &numOfPixelsInFile);
printf("Num of pixels: %d\n", numOfPixelsInFile);
for (int i = 0; i < numOfPixelsInFile; i++)
{
fscanf(file, "%d %d %d %e %e %e", &id,
&x, &y, &rgb1, &rgb2, &rgb3);
printf("%d %d %d %e %e %e\n", id, x, y, rgb1, rgb2, rgb3);
}
fclose(file);
}
else
{
}
MPI_Finalize();
return 0;
}
解决方案
推荐阅读
- cassandra - Java驱动程序中CQL count() 的等价物是什么
- python - 检测来自物理源的特定声音并记录日期/时间
- kubernetes - CronJob 的 Kubernetes pod 生命周期通知
- json - 导出 Google 跟踪代码管理器数据?
- javascript - 如何在不获取子组件 Next.js 的情况下更改路线
- css - Protractor E2E:失败,使用定位器找不到元素:By(css选择器)
- scala - 将带有 json 字符串的数据框列转换为不同的列
- python - python dataframe中将excel文件读取为csv文件时的日期格式问题
- django - 在 Kubernetes 上安装 CVAT
- java - 是否可以在 kotlin 中创建一个 ByteArray 的 ByteArray 作为元素?