在从站MPI Spawn C中接收数据 [英] Receiving data in slaves mpi spawn c
问题描述
我正在尝试使用mpi_comm_spawn&来实现以下方案分散:
I'm trying to implement the following scenario using mpi_comm_spawn & scatter :
1-主人通过一个工作产生了2个进程.
1- Master spawns 2 processes with a job.
2-他将数组分散到那些生成的进程中.
2- He scatters an array to those spawned processes.
3-生成的进程接收分散的数组排序,然后将其发回.
3- The spawned processes receive the scattered array sort it then send it back.
4-主机接收数组的排序部分.
4- The master receives the sorted parts of the array.
我想知道如何执行步骤2,到目前为止,我已经尝试过发送和接收,它们可以正常工作,但是我想使用散点图功能.
I'd like to know how to do the step 2, so far i've tried with send and receives, they work perfectly but i want to do it with the scatter function.
这是我要在主代码中执行的操作,我丢失了从属设备接收分散数组的部分
Edit : Here's what i'd like to do in the master code , i'm missing the part in the slave's where i receive the scattered array
/*Master Here*/
MPI_Comm_spawn(slave, MPI_ARGV_NULL, 2, MPI_INFO_NULL,0, MPI_COMM_WORLD, &inter_comm, array_of_errcodes);
printf("MASTER Sending a message to slaves \n");
MPI_Send(message, 50, MPI_CHAR,0 , tag, inter_comm);
MPI_Scatter(array, 10, MPI_INT, &array_r, 10, MPI_INT, MPI_ROOT, inter_comm);
谢谢.
推荐答案
master.c
#include "mpi.h"
int main(int argc, char *argv[])
{
int n_spawns = 2;
MPI_Comm intercomm;
MPI_Init(&argc, &argv);
MPI_Comm_spawn("worker_program", MPI_ARGV_NULL, n_spawns, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm, MPI_ERRCODES_IGNORE);
int sendbuf[2] = {3, 5};
int recvbuf; // redundant for master.
MPI_Scatter(sendbuf, 1, MPI_INT, &recvbuf, 1, MPI_INT, MPI_ROOT, intercomm);
MPI_Finalize();
return 0;
}
worker.c
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
MPI_Comm intercomm;
MPI_Comm_get_parent(&intercomm);
int sendbuf[2]; // redundant for worker.
int recvbuf;
MPI_Scatter(sendbuf, 1, MPI_INT, &recvbuf, 1, MPI_INT, 0, intercomm);
printf("recvbuf = %d\n", recvbuf);
MPI_Finalize();
return 0;
}
命令行
mpicc master.c -o master_program
mpicc worker.c -o worker_program
mpirun -n 1 master_program
这篇关于在从站MPI Spawn C中接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!