msmpi 高性能并行计算 移植并行细胞自动机报错

本文主要是介绍msmpi 高性能并行计算 移植并行细胞自动机报错,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

报错情况如图

 代码来源

元胞自动机生命游戏C语言并行实现 – OmegaXYZ

稍微修改,因为相对路径在 msmpi 10.1.1 中失效

Microsoft Windows [版本 10.0.22000.2538]
(c) Microsoft Corporation。保留所有权利。C:\Users\ASUS>mpiexec -n 9 "C:\Users\ASUS\Desktop\testMPI\MPIS.exe"job aborted:
[ranks] message[0] terminated[1] fatal error
Fatal error in MPI_Recv: Message truncated, error stack:
MPI_Recv(buf=0x000002F82B501D6C, count=0, MPI_INT, src=0, tag=1, MPI_COMM_WORLD, status=0x00007FF66B1CD0A0) failed
Message from rank 0 and tag 1 truncated; 12 bytes received but buffer size is 0[2-8] terminated---- error analysis -----[1] on LAPTOP-MUD6OOHE
mpi has detected a fatal error and aborted C:\Users\ASUS\Desktop\testMPI\MPIS.exe---- error analysis -----C:\Users\ASUS>

windows msmpi 移植 linux  代码如下

#include <stdio.h>
#include <string.h>
#include <mpi/mpi.h>
#include <stdlib.h>
#include <io.h>
//https://www.omegaxyz.com/2022/01/26/c_game_of_life/?utm_source=tuicool&utm_medium=referral
static int MAX_M;
static int MAX_N;
static int epoch;
static int DEAD = 0;
static int ALIVE = 1;double exe_time;
int size, myid, s, ver, row, col, dir;int *local_matrix = NULL;
int *tmpmatrix = NULL;
int *global_matrix = NULL;
int *newglobal_matrix = NULL;
MPI_Request requests[4];
MPI_Status status[4];FILE * matrix;void display(int *local_matrix) {int i, j;printf("%10c", ' ');printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");for (i = 0; i < MAX_M; i++) {printf("\n%10c", ' ');for (j = 0; j < MAX_N; j++)if (local_matrix[i * MAX_N + j] == ALIVE)printf("+");elseprintf("-");}printf("\n%10c\n", ' ');
}int adj8(int neighbor, int row, int col) {int res;if (neighbor == 2) {return local_matrix[row * MAX_N + col];} else if (neighbor == 3) {return ALIVE;} else {return DEAD;}
}int main(int argc, char *argv[]) {MPI_Init(&argc, &argv);MPI_Comm_size(MPI_COMM_WORLD, &size);MPI_Comm_rank(MPI_COMM_WORLD, &myid);ver = MAX_M / size;//	epoch= atoi(argv[1]);
//	MAX_M= atoi(argv[2]);
//	MAX_N= atoi(argv[3]);epoch = 100;MAX_M = 3;MAX_N = 3;local_matrix = (int*)malloc(sizeof(int) * (ver + 2) * MAX_N);tmpmatrix = (int*)malloc(sizeof(int) * (ver + 2) * MAX_N);for (row = 0; row < ver + 2; row++) {for (col = 0; col < MAX_N; col++) {local_matrix[row * MAX_N + col] = DEAD;tmpmatrix[row * MAX_N + col] = DEAD;}}//Initializationif (myid == 0) {int i;global_matrix = (int*)malloc(sizeof(int) * MAX_M * MAX_N);newglobal_matrix = (int*)malloc(sizeof(int) * MAX_M * MAX_N);// windows 的 msmpi 相对路径不能读取,只能用绝对路径,但是可以通过获取当前文件所在文件夹来拼出来绝对路径FILE* fp;fp = fopen("C:\\Users\\ASUS\\Desktop\\testMPI\\matrixv6.txt", "w");fprintf(fp, "hello\n");fclose(fp);char path[PATH_MAX + 100]; //PATH_MAX is defined in limits.hgetcwd(path, sizeof(path));  		// io.h 获取当前文件夹位置printf("%s\n", path);strcat(path, "\\matrixv7.txt");		// 在当前文件夹位置加入数据printf("%s\n", path);fp = fopen(path, "w");for (int i = 0; i < MAX_M; i++) {for (int j = 0; j < MAX_N; j++) {fprintf(fp, "%d ", 1);}fprintf(fp, "\n");}fclose(fp);if ((matrix = fopen(path, "r")) == NULL) {printf("the file can not open.");return -1;}for (row = 0; row < MAX_M; row++) {for (col = 0; col < MAX_N; col++) {fscanf(matrix, "%d ", &global_matrix[row * MAX_N + col]);}fscanf(matrix, "\n");}memcpy(&local_matrix[MAX_N], &global_matrix[0], ver * MAX_N * sizeof(int));for (dir = 1; dir < size; dir++) {MPI_Send(&global_matrix[dir * ver * MAX_N], ver * MAX_N, MPI_INT, dir, 1, MPI_COMM_WORLD);}display(global_matrix);} else {//For each processor, there is a local matrix.MPI_Recv(&local_matrix[MAX_N], ver * MAX_N, MPI_INT, 0, 1, MPI_COMM_WORLD, status);}exe_time = -MPI_Wtime();for (int count = 0; count < epoch; count++) {int req_id = 0;if (myid == 0) {MPI_Isend(&local_matrix[(ver)*MAX_N], MAX_N, MPI_INT, myid + 1, 1, MPI_COMM_WORLD, &requests[req_id++]);MPI_Irecv(&local_matrix[(ver + 1)*MAX_N], MAX_N, MPI_INT, myid + 1, 1, MPI_COMM_WORLD, &requests[req_id++]);printf("\n");display(local_matrix);} else {MPI_Irecv(local_matrix, MAX_N, MPI_INT, myid - 1, 1, MPI_COMM_WORLD, &requests[req_id++]);MPI_Isend(&local_matrix[(ver)*MAX_N], MAX_N, MPI_INT, myid + 1, 1, MPI_COMM_WORLD, &requests[req_id++]);MPI_Irecv(&local_matrix[(ver + 1)*MAX_N], MAX_N, MPI_INT, myid + 1, 1, MPI_COMM_WORLD, &requests[req_id++]);MPI_Isend(&local_matrix[MAX_N], MAX_N, MPI_INT, myid - 1, 1, MPI_COMM_WORLD, &requests[req_id++]);}MPI_Waitall(req_id, requests, status);for (row = 1; row < ver + 1; row += 1) {for (col = 0; col < MAX_N; col++) {int neighbor = 0, c, r;for (r = row - 1; r <= row + 1; r++)for (c = col - 1; c <= col + 1; c++) {if (c < 0 || c >= MAX_N) continue;if (local_matrix[r * MAX_N + c] == ALIVE) neighbor++;}if (local_matrix[row * MAX_N + col] == ALIVE)neighbor--;tmpmatrix[row * MAX_N + col] = adj8(neighbor, row, col);}}for (row = 1; row < ver + 1; row += 1) {for (col = 0; col < MAX_N; col++) {local_matrix[row * MAX_N + col] = tmpmatrix[row * MAX_N + col];}}}if (myid == 0) {exe_time += MPI_Wtime();printf("Time: %lf \n", exe_time);memcpy(global_matrix, &local_matrix[MAX_N], ver * MAX_N * sizeof(int));for (dir = 1; dir < size; dir++) {MPI_Recv(&global_matrix[dir * ver * MAX_N], ver * MAX_N, MPI_INT, dir, 1, MPI_COMM_WORLD, status);}printf("Last Status:\n");display(global_matrix);} else {MPI_Send(&local_matrix[MAX_N], ver * MAX_N, MPI_INT, 0, 1, MPI_COMM_WORLD);}MPI_Finalize();return 0;
}

这篇关于msmpi 高性能并行计算 移植并行细胞自动机报错的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/956537

相关文章

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

MySQL报错sql_mode=only_full_group_by的问题解决

《MySQL报错sql_mode=only_full_group_by的问题解决》本文主要介绍了MySQL报错sql_mode=only_full_group_by的问题解决,文中通过示例代码介绍的非... 目录报错信息DataGrip 报错还原Navicat 报错还原报错原因解决方案查看当前 sql mo

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

linux报错INFO:task xxxxxx:634 blocked for more than 120 seconds.三种解决方式

《linux报错INFO:taskxxxxxx:634blockedformorethan120seconds.三种解决方式》文章描述了一个Linux最小系统运行时出现的“hung_ta... 目录1.问题描述2.解决办法2.1 缩小文件系统缓存大小2.2 修改系统IO调度策略2.3 取消120秒时间限制3

解决systemctl reload nginx重启Nginx服务报错:Job for nginx.service invalid问题

《解决systemctlreloadnginx重启Nginx服务报错:Jobfornginx.serviceinvalid问题》文章描述了通过`systemctlstatusnginx.se... 目录systemctl reload nginx重启Nginx服务报错:Job for nginx.javas

Go语言使用Buffer实现高性能处理字节和字符

《Go语言使用Buffer实现高性能处理字节和字符》在Go中,bytes.Buffer是一个非常高效的类型,用于处理字节数据的读写操作,本文将详细介绍一下如何使用Buffer实现高性能处理字节和... 目录1. bytes.Buffer 的基本用法1.1. 创建和初始化 Buffer1.2. 使用 Writ

VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virtual disk”问题

《VMWare报错“指定的文件不是虚拟磁盘“或“Thefilespecifiedisnotavirtualdisk”问题》文章描述了如何修复VMware虚拟机中出现的“指定的文件不是虚拟... 目录VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virt

使用Vue.js报错:ReferenceError: “Vue is not defined“ 的原因与解决方案

《使用Vue.js报错:ReferenceError:“Vueisnotdefined“的原因与解决方案》在前端开发中,ReferenceError:Vueisnotdefined是一个常见... 目录一、错误描述二、错误成因分析三、解决方案1. 检查 vue.js 的引入方式2. 验证 npm 安装3.