Tag: mpi

使用MPI写入文件

我正在写一个文件如下。 顺序并不一定重要(虽然如果我可以通过K订购它会很好,就像在串行代码中本身一样) CALL MPI_BARRIER(MPI_COMM_WORLD, IERR) OPEN(EIGENVALUES_UP_IO, FILE=EIGENVALUES_UP_PATH, ACCESS=’APPEND’) WRITE(EIGENVALUES_UP_IO, *) K * 0.0001_DP * PI, (EIGENVALUES(J), J = 1, ATOM_COUNT) CLOSE(EIGENVALUES_UP_IO) 我知道这可能是最糟糕的选择。 我已经看过MPI_FILE_WRITE_AT等但是我不确定他们(直接)以我的forms获取数据? 该文件必须采用与此格式相同的格式,该格式为每K行一行,ATOM_COUNT + 1列。 值为REAL(8) 我一遍又一遍地寻找,并且找不到任何关于实现这一点的简单参考。 有帮助吗? 🙂 C中的类似代码(假设它与FORTRAN基本相同)同样有用 谢谢!

在`libpmpi.12.dylib`中使用MPI_Barrier时出现分段错误

我使用brew install mpich ,但是如果我使用MPI_Barrier ,我会得到分段错误。 请参阅以下简单代码: // Ac #include “mpi.h” #include int main(int argc, char *argv[]) { int rank, nprocs; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&nprocs); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Barrier(MPI_COMM_WORLD); printf(“Hello, world. I am %d of %d\n”, rank, nprocs);fflush(stdout); MPI_Finalize(); return 0; } mpicc Ac -g -O0 -o A 运行mpirun -n 2 ./A ,我收到以下错误: ================================================================================== = = BAD TERMINATION OF ONE […]

MPI I / O,单进程和多进程输出的混合

我需要一个MPI C代码通过MPI I / O将数据写入二进制文件。 我需要进程0来编写一个短标题,然后我需要整个进程范围来编写标题所指示的自己的数组。 然后我需要进程0来编写另一个头,然后是所有进程编写下一个数组的部分,等等。我想出了以下测试代码,它实际上做了我想要的。 没有人比我更惊讶。 我的问题是,我是MPI I / O的新手。 所以我“得到它”? 我这样做是“正确的方式”还是有更高效或更紧凑的方式来做到这一点? 代码是:(顺便说一句,如果您考虑测试此function,请仅使用4个触发器进行测试。) #include #include #include #include “mpi.h” #define ROWS 9 #define COLS 10 int main(int argc, char *argv[]) { int size_mpi, rank_mpi, row_mpi, col_mpi; int i,j,p,ttlcols; int sizes[]= {2*ROWS,2*COLS}; int subsizes[]= {ROWS,COLS}; int starts[] = {0,0}; int vals[ROWS][COLS]; char hdr[] = “This […]

MPI将动态2Darrays广播到其他处理器

我已经搜索了很多解释,但我想我无法弄清楚我是如何做到这种情况的。 我想做类似的事情:使用主处理器,我正在创建一个动态的2D数组。 然后我想; 1-将此arrays发送到其他处理器。 并且每个处理器打印该2Darrays2-将该arrays的一部分发送给其他人。 每个处理器将其部件打印到屏幕上。 例如; 我有2Darrays11 * 11和4个处理器。 等级0是主人。 其他人是奴隶。 对于第一种情况,我想将所有数组发送到排名1,排名2和排名3.而对于第二种情况,我想将行分享给从属。 11/3 = 3.因此,等级1需要3行,等级2需要3行,等级3需要5行。 这是我的代码: int processorID; int numberOfProcessors; int main(int argc, char* argv[]){ MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD ,&numberOfProcessors); MPI_Comm_rank(MPI_COMM_WORLD ,&processorID); double **array; if(MASTER){ array = (double**) malloc(11*sizeof(double *)); for(i=0; i<11; i++){ array[i] = (double *) malloc(11*sizeof(double)); } for(i=0; i<11; i++){ for(j=0; j<11; j++){ […]

MPI Bcast与MPI_Type_create_struct分段错误

我强迫自己用C语言MPI进行个人结构广播。 基本上我已经创建了结构Vector3d。 typedef struct { double x, y, z; } Vector3d; 然后我一直在阅读并为每个MPI流程编写代码。 int rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); // MPI Struct para Vector3d int nroItems = 3; int blockLengths[3] = { 1, 1, 1 }; MPI_Datatype types[3] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE }; MPI_Datatype MPI_Vector3d; MPI_Aint offsets[3]; offsets[0] = offsetof(Vector3d, x); offsets[1] […]

MPI_Gather分段错误

我有这个并行高斯消元码。 调用MPI_Gather函数调用时发生分段错误。 我知道如果没有为任何缓冲区正确分配内存,这样的错误可能会增加。 但我看不出内存管理代码有任何问题。 有人可以帮忙吗? 谢谢。 注意:程序从名为input.txt的同一目录中的.txt文件中读取。 码: #include #include #include #include “mpi.h” /*void print2dAddresses(double** array2d, int rows, int cols) { int i; for(i = 0; i < rows; i++) { int j; for(j = 0; j < cols; j++) { printf("%d ", &(array2d[i][j])); } printf("\n"); } printf("————————————"); }*/ double** newMatrix(int rows, int cols) { […]

MPI – 发送和接收列

我需要从一个进程发送一个矩arrays,然后从另一个进程接收它。 我尝试运行以下程序,但是我得到了一个奇怪的结果(至少我是这么认为的); 仅复制矩阵的第一个元素,并且一些矩阵元素意外更改。 #include #include #include #include #include “mpi.h” void swap(int* a,int* b){ int temp; temp=*a; *a=*b; *b=temp; } void print_matrix(double** A,int n){ int i,j; for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("%f ",A[i][j]); } printf("\n"); } } int main(int argc, char *argv[]){ int i,j,k,l,n,myid,p,maxp; double **A; MPI_Datatype col_type; MPI_Status status; n=3; A=malloc(n*sizeof(double*)); /*allocating memory */ for(i=0;i<n;i++) A[i]=malloc(n*sizeof(double)); A[0][0]=-1; A[0][1]=2; […]

MPI_Gatherv:创建和收集可变大小的数组(MPI + C)

我是MPI的新手,我试图并行管理不同大小的数组,然后将它们传递给主线程,到目前为止还没有成功。 我已经了解到了 MPI_Gatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int *recvcounts, const int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm) 是这种情况下的方法。 这是我的示例代码,由于内存问题而无效(我认为)。 #include #include #include #include int main (int argc, char *argv[]) { MPI_Init(&argc, &argv); int world_size,*sendarray; int rank, *rbuf=NULL, count; int *displs=NULL,i,*rcounts=NULL; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &world_size); if(rank==0){ rbuf = malloc(10*sizeof(int)); displs […]

MPI:广播一个很长的int

该程序通过将随机“飞镖”(采样点)投掷到圆形或半径= 1内切长度为2的方形板内来估计Pi 。 使用这种关系 Area of circle / Area of Square = Pi/4 我们可以用表达的相同关系来估计Pi Darts Inside Circle / Darts Outside Circle = Pi/4 当我在#define指定NDARTS时程序工作正常,但是当尝试将它作为long long int广播时,从scanf读取,我得到以下执行错误: mpirun -np 4 ./pi_montecarlo.x —————————————————————————– One of the processes started by mpirun has exited with a nonzero exit code. This typically indicates that the process finished in error. If […]

MPI_Gather()将中心元素转换为全局矩阵

这是来自MPI_Gather 2Darrays的后续问题。 情况如下: id = 0 has this submatrix |16.000000| |11.000000| |12.000000| |15.000000| |6.000000| |1.000000| |2.000000| |5.000000| |8.000000| |3.000000| |4.000000| |7.000000| |14.000000| |9.000000| |10.000000| |13.000000| ———————– id = 1 has this submatrix |12.000000| |15.000000| |16.000000| |11.000000| |2.000000| |5.000000| |6.000000| |1.000000| |4.000000| |7.000000| |8.000000| |3.000000| |10.000000| |13.000000| |14.000000| |9.000000| ———————– id = 2 has this submatrix […]