- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个一维矩阵数据作为 Q_send_matrix
。在每次迭代中,每个处理器更新其Q_send_matrix
并将其发送到前一个处理器(rank-1
),同时它接收一个新更新的矩阵作为Q_recv_matrix
来自下一个处理器(rank+1
)。例如,在一次迭代中,Proc[0]
更新它的 Q_send_matrix
并将其发送到 Proc[3]
,而它接收 来自
。正如您所估计的那样,它就像一个环形通信。请在我在下面对代码进行解释后查看下面的代码。Proc[1]
的 Q_recv_matrix
MPI_Request request;
MPI_Status status;
// All the elements of Q_send and Q_recv buffers
// are set to 1.0 initially. Each processor
// updates its Q_send buffer to prepare it
// to be sent below.(above part is big, so it
// is not added here...)
/**
* Transfer Q matrix blocks among processors
* + Each processor sends the Q matrix
* + to the previous processor while receives
* + the Q matrix from the next processor
* + It is like a ring communication
* */
/* Receive Q matrix with MPI_Irecv */
source = (my_rank+1)%comm_size;
recv_count = no_col_per_proc[source]*input_k;
MPI_Irecv(Q_recv_matrix, recv_count,
MPI_FP_TYPE, source,
0, MPI_COMM_WORLD,
&request);
/* Send Q matrix */
dest = (my_rank-1+comm_size)%comm_size;
send_count = no_col_per_proc[my_rank]*input_k;
MPI_Send(Q_send_matrix, send_count,
MPI_FP_TYPE, dest,
0, MPI_COMM_WORLD);
/* Wait status */
// MPI_Wait(request, status);
/* Barrier */
MPI_Barrier(MPI_COMM_WORLD);
/* Print Q send and receive matrices */
for( j = 0; j < send_count; j ++ )
{
printf("P[%d] sends Q_send[%d] to P[%d] = %.2f\n",
my_rank, j, dest, Q_send_matrix[j]);
}
for( j = 0; j < recv_count; j ++ )
{
printf("P[%d] receives Q_recv[%d] from P[%d] = %.2f\n",
my_rank, j, source, Q_recv_matrix[j]);
}
我想以同步方式进行此通信。但是,MPI_Send
和 MPI_Recv
是不可能的,因为它们的阻塞特性会导致死锁。因此,我将 MPI_Irecv
和 MPI_Send
与 MPI_Wait
一起使用。然而,它并没有完成,所有的处理器都在等待。所以,我用 MPI_Barrier
代替 MPI_Wait
让它们同步,解决了处理器的等待问题,所以它们完成了工作。但是,它无法正常工作。以下代码的某些输出是错误的。每个处理器发送正确的数据,发送端没有问题。另一方面,接收数据缓冲区没有变化。这意味着在某些处理器中,即使从其他处理器之一接收到数据,接收缓冲区的初始值仍然存在,如下所示。
P[0] sends Q_send[0] to P[3] = -2.12
P[0] sends Q_send[1] to P[3] = -2.12
P[0] sends Q_send[2] to P[3] = 4.12
P[0] sends Q_send[3] to P[3] = 4.12
P[0] receives Q_recv[0] from P[1] = 1.00
P[0] receives Q_recv[1] from P[1] = 1.00
P[0] receives Q_recv[2] from P[1] = 1.00
P[0] receives Q_recv[3] from P[1] = 1.00
P[1] sends Q_send[0] to P[0] = -2.12
P[1] sends Q_send[1] to P[0] = -2.12
P[1] sends Q_send[2] to P[0] = 0.38
P[1] sends Q_send[3] to P[0] = 0.38
P[1] receives Q_recv[0] from P[2] = 1.00
P[1] receives Q_recv[1] from P[2] = 1.00
P[1] receives Q_recv[2] from P[2] = 1.00
P[1] receives Q_recv[3] from P[2] = 1.00
P[2] sends Q_send[0] to P[1] = 1.00
P[2] sends Q_send[1] to P[1] = 1.00
P[2] sends Q_send[2] to P[1] = -24.03
P[2] sends Q_send[3] to P[1] = -24.03
P[2] receives Q_recv[0] from P[3] = 1.00
P[2] receives Q_recv[1] from P[3] = 1.00
P[2] receives Q_recv[2] from P[3] = 1.00
P[2] receives Q_recv[3] from P[3] = 1.00
P[3] sends Q_send[0] to P[2] = 7.95
P[3] sends Q_send[1] to P[2] = 7.95
P[3] sends Q_send[2] to P[2] = 0.38
P[3] sends Q_send[3] to P[2] = 0.38
P[3] receives Q_recv[0] from P[0] = -2.12
P[3] receives Q_recv[1] from P[0] = -2.12
P[3] receives Q_recv[2] from P[0] = 4.12
P[3] receives Q_recv[3] from P[0] = 4.12
最佳答案
在从 MPI_Irecv
访问数据之前,您必须完成一个MPI_Wait
或一个成功的MPI_Test
。你不能用障碍代替它。
对于环形通信,考虑使用 MPI_Sendrecv
。它可以比使用异步通信更简单。
关于c - MPI_Irecv 没有正确接收 MPI_Send 发送的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42121393/
我的代码可以在我的github上找到: https://github.com/chrismunley/ParallelProgramming/tree/master 我得到的错误是:PGC-W-009
我有这段代码用于测试 MPI_Irecv 和 MPI_Isend if(rank==1){ int cc; MPI_Request request;
我一直在并行执行哲学家就餐问题,但遇到了一个我无法解决的问题。基本上,我有一个 for 循环,其中一个进程检查是否有任何新消息,然后休眠半秒钟(它重复随机次数)。在该部分之后,它会尝试收集所有需要的
来自 OpenMPI 文档:C++ 语法 Request Comm::Irecv(void* buf, int count, const Datatype& datatype, int sou
我试图在这个简化的代码中实现的是: 2 种类型的进程(根进程和子进程,ids/rank 分别为 10 和 0-9) 初始化: root 会听 child “完成” children 将在所有完成后收听
MPI_IRecv(&myArr[0], 5, MPI_INT, 1, MPI_ANY_TAG, MPI_COMM_WORLD, request); MPI_IRecv(&myArr[5], 5, M
我想知道为什么我无法通过 MPI_Recv 命令访问数据。我有一个包含 100 个元素的数组,我想将其分为 8 个进程。由于 100/8 返回不等长度的 block ,因此我手动执行此操作。然后我计算
对于MPI中的异步通信,以下哪个更好(在性能、可靠性、可读性等方面): MPI_Isend with buffer 然后 MPI_Iprobe & MPI_Recv 一旦接收器准备好,或者 带缓冲区的
我有一个一维矩阵数据作为 Q_send_matrix。在每次迭代中,每个处理器更新其Q_send_matrix并将其发送到前一个处理器(rank-1),同时它接收一个新更新的矩阵作为Q_recv_ma
我正在编写一个程序来检测远程机器的突然崩溃。 manager 进程在机器 1 上运行,worker 进程在机器 2 上运行。 manager 服务器通过调用 MPI_Isend 向工作进程发送消息。
我想了解 MPI 如何处理发送和接收。假设我分配一个 [12][50] 元素的缓冲区,如下所示: int **buf= malloc(12 * sizeof(int *)); for (i = 0;
我对两个 MPI_Irecv 使用了 2 个 MPI_Irecv,然后是 2 个 MPI_Send,然后是 MPI_Waitall,如下所示。经过几次计算后,我再次编写了相同的代码块。但 MPI 进程
MPI_Isend 和 MPI_Irecv 有问题。我正在研究按行分布的图的邻接矩阵。我们可以假设每个处理器包含一行。对于每对索引 (i,j) 我需要发送和接收 2 个整数。基本上,我需要从其他行接收
我在使用 C 语言的 MPI 程序时遇到了一些问题。我想使用 MPI_Send 从从站向主站发送两条消息(使用 MPI_Send、MPI_Irecv 和 MPI_Test),但只有第一条消息有效。在那
当我尝试在四个处理器上运行一个问题时收到以下错误序列。我使用的 MPI 命令是 mpirun -np 4 我很抱歉按原样发布错误消息(主要是由于缺乏破译给定信息的知识)。感谢您在以下方面的意见: 错误
我有一个项目,我需要使用 MPI_Isend 和 MPI_Irecv 对 MPI_Bcast 的任何错误实现进行计时,并将其与 MPI_Bcast 进行比较。因为这些程序的时间是 0.000000 秒
我正在学习 c 中的 mpi 通信。我在尝试使用 MPI_Isend 从一个节点发送消息并使用 MPI_Irecv 在另一个节点上接收它时遇到问题。这是代码: #include #include
我想运行一个程序来了解 MPI_Isend 和 MPI_Irecv 的工作原理。等级 0 的 Isend 和 Irecv 工作正常,但等级 5 的 Irecv 采用默认值。有人可以向我解释一下吗? #
我是一名优秀的程序员,十分优秀!