- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将多列“B”矩阵从处理器 0 发送到不同的处理器。我正在尝试使用 MPI_Send 进行发送,但它不起作用。有人可以帮助我吗?
例如:方阵 B 的大小为 7。这样就应该被分发了。
处理器 0:3 列
处理器 1:2 列
处理器 2:2 列</p>
#include <stdlib.h>
#include <mpi.h>
#include <stdio.h>
#define ERR_BADORDER 255
#define TAG_INIT 31337
#define TAG_RESULT 42
#define DISP_MAXORDER 12
int mm(double *A, double *B, double *C, int n, int n1);
int rc(int rt,int rank, int size);
int main(int argc, char *argv[]) {
double *A, *B, *C,t,tt;
int n = 0, n0, n1, n2, i,ss,sts;
int rank = 0, size = 1,prev,next,k,z,jcol,ix=0,m,j;
MPI_Datatype column;
MPI_Request reqs[4];
MPI_Status stats[2];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (!rank) {
if (argc > 1) {
n = atoi(argv[1]);
}
}
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (!n) {
MPI_Finalize();
return 0;
}
n1 = rc(n, rank,size);
n0 = n * n1;
n2 = n * n;
A = (double *) malloc(sizeof(double) * (rank ? n0 : n2));
B = (double *) malloc(sizeof(double) * n2 );
C = (double *) malloc(sizeof(double) * (rank ? n0 : n2));
if (!rank) {
for (i=0; i<n2; i++) {
A[i] = 1.0;
B[i] = 1.0;
}
}
t = MPI_Wtime();
if (!rank) {
ss = n0;
for (i=1; i<size; i++) {
sts = n * rc(n, i, size);
MPI_Send(A + ss, sts, MPI_DOUBLE, i, TAG_INIT,
MPI_COMM_WORLD);
ss += sts;
}
}
else {
MPI_Recv(A, n0, MPI_DOUBLE, 0, TAG_INIT, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
}
MPI_Type_vector(n,1,n,MPI_DOUBLE, &column);
MPI_Type_commit(&column);
if (!rank) {
for (i=1; i<size; i++) {
for(m=0;m<=i-1;m++)
ix+=rc(n,m,size);
ss=rc(n,i,size);
for(j=ix;j<ss+ix;j++)
MPI_Send(&B[j], 1, column, i, TAG_INIT, MPI_COMM_WORLD);
/* MPI_Send(&B[i+(n-1)*n], 1, column, i, TAG_INIT,
MPI_COMM_WORLD);*/
}
}
else {
printf("hello");
MPI_Recv(B, n, MPI_DOUBLE, 0, TAG_INIT, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
}
for (i=0; i<n0; i++) {
printf("Processor: %d and matrix %lf \n ",rank, B[i]);
}
for (i=0; i<n0; i++) {
C[i] = 0.0;
}
MPI_Finalize();
return 0;
}
int rc(int rt, int rank, int size) {
return (rt / size) + (rt % size > rank);
}
最佳答案
请不要用两到三个字母来调用值,因为我无法理解你想要做什么。
您可以通过不同的方式解决问题。当 n = 7 并且我有 3 个进程时,我向与主进程 0 不同的每个进程发送 2 列。
#include <stdlib.h>
#include <mpi.h>
#include <stdio.h>
#define ERR_BADORDER 255
#define TAG_INIT 31337
#define TAG_RESULT 42
#define DISP_MAXORDER 12
int main(int argc, char *argv[]) {
double *B;
int n = 0;
int rank , size;
int i;
int columnToSend;
MPI_Datatype column;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (!rank)printf ("rank = %d , size = %d\n", rank, size);
if (!rank) {
if (argc > 1) {
n = atoi(argv[1]);
}
}
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (!n) {
printf ("n = %d!!\n", n);
MPI_Finalize();
return 0;
}
int offset = n%size;
int gap = n/size;
if (!rank)printf ("n = %d, offset = %d , gap = %d\n", n, offset, gap);
MPI_Type_vector(n,gap,n,MPI_DOUBLE, &column);
MPI_Type_commit(&column);
B = (double *) malloc(sizeof(double) * n*n );
for (i = 0 ; i < n * n ; i++) {
B[i] = -1.0;
}
if (!rank) {
for (i = 0 ; i < n * n ; i++) {
B[i] = i;//<----- I put i instead one
}
for (i=1; i < size; i++) {
columnToSend = gap *i + offset;
printf ("columnToSend = %d to i = %d \n", columnToSend, i);
MPI_Send(&B[columnToSend], 1, column, i, TAG_INIT, MPI_COMM_WORLD);
}
}
if (rank) {
printf ("in rank = %d n*gap = %d \n", rank, n*gap);
MPI_Recv(B, n*gap, MPI_DOUBLE, 0, TAG_INIT, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for (i=0; i < n*gap; i++) {
printf("Processor: %d and matrix %lf \n ",rank, B[i]);
}
}
MPI_Finalize();
return 0;
}
关于c - 使用 MPI_Send 发送矩阵的多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19467608/
我有一个使用 openmpi 编译和运行的代码。最近,我想使用 Intel MPI 运行同样的代码。但是我的代码没有按预期工作。我深入研究了代码,发现 MPI_Send 在两个实现中的行为不同。 我从
我想将 MPI_Send 消息发送到单个但可变的主机。我的意思是,我在编译时不知道要发送消息的主机的级别。 很自然地,我写的内容如下: MPI_Send(&myIntData, 1, MPI_INT,
我可以在单个 MPI_SEND 中发送一个矩阵的行和另一个矩阵的列,我该如何执行此过程? MPI_SEND (row and column of the matrix ...) 最佳答案 由于 C/C
我有以下代码: double * myX; double * myY; double * myZ; int amount; int count; // number of process v
我正在编写 mpi 的 C++ 包装器。 我在 mpi 遇到了一个奇怪的错误:在我的例子中,错误只在消息足够大时出现,运行时错误如下: Fatal error in MPI_Send: Other M
如果我想定义自己的类型,并将其用作 MPI_Send 的数据类型以仅从矩阵中获取偶数行,是否必须静态分配该矩阵(发送缓冲区)? 我动态分配的时候好像有问题。这是因为地址需要连续才能发送数据吗? 最佳答
我正在使用 MPI 编写 Mergesort 来对整数数组进行排序。这个想法是在同一等级上对数组的左半部分进行归并排序,同时将数组的右半部分发送到子等级。所以如果有四个过程,它看起来像这样:
我必须在我的程序中使用 MPI API 发送/接收矩阵。为了发送矩阵,我使用了以下语法: MPI_Send(matrix, ...) <- USE THIS MPI_Send(&matrix, ..
在大量内核上调试我的程序时,我遇到了非常奇怪的虚拟内存不足错误。我的调查导致代码和平,主人向每个奴隶发送小消息。然后我写了一个小程序,其中 1 个主机使用 MPI_SEND 发送 10 个整数,所有从
这是我在 stackoverflow 中的第一个问题。我有两个进程,一个根 0 和一个从属 1。从属分配一个二维数组 (CHUNK_ROWS+2,CHUNK_COLUMNS+2) 并想发送一个 [CH
我正在尝试使用 MPI 形成环形通信,其中我的每个进程都将其结果发送到下一个进程,最后一个进程将结果发送到第 0 个进程。假设我有 4 个进程,那么我的第 0 个进程会将结果发送到第 1 个、第 1
我得到了一个小练习,我必须通过使用 MPI 来估计 n 个球体的总体积来实现蒙特卡罗算法,这些球体的中心坐标和半径在 3 维中。即使我们必须使用 MPI,我们也可以在本地机器上启动所有进程,因此没有网
当我使用超过 1 个处理器执行程序时,程序将停止工作。它在第一个 MPI_Send 处停止我做错了什么? #include "mpi.h" #include #include #include
我有一个主进程和更多从进程。我希望每个从进程向主进程发送一个整数,所以我想我应该使用 MPI_Gather 收集它们。但不知怎的,它不起作用,我开始认为 MPI_Gather 与 MPI_Send 不
我正在尝试将多列“B”矩阵从处理器 0 发送到不同的处理器。我正在尝试使用 MPI_Send 进行发送,但它不起作用。有人可以帮助我吗? 例如:方阵 B 的大小为 7。这样就应该被分发了。 处理器 0
最近才知道MPI_Send不能一次发送太长的数据,所以决定把数据分成几 block ,用for循环发送。下面是一个测试用例。这里的问题是,如果我使用少量数据并将其分成几 block ,程序将运行;但是
我正在尝试使用 MPI 在 C++ 中处理一些动态分配的多维数组。为了避免担心不连续的内存,我编写了一个类包装器,它允许我像访问二维数组一样访问一维数组。我正在尝试创建一个 MPI 数据类型以通过 M
这可能是一件微不足道的事情,但是: 底层数组的大小是否可以长于在 MPI_Send( ... ) 调用中与缓冲区指针一起发送的计数参数? 至于 MPI_Recv( ... ),我发现消息来源清楚地表明
我正在尝试运行下面使用并行编程的程序。如果我们使用 4 个处理器,我希望它们包含总和 1+2=3、3+4=7、11 和 15。所以我希望求和 vector 按顺序包含 3、7、11 和 15。但是,由
我正在学习 MPI_Send,但我对这种方法感到困惑。我写了一个简单的乒乓程序,rank-0 节点发送消息给 rank-1 节点,然后后者返回消息给前一个。 if (rank == 0) { /*
我是一名优秀的程序员,十分优秀!