如何向其他节点发出信号,表明主节点没有更多工作可用
How to signal to other node that no more work is available from the master node
我想请求一些帮助来完成 mpi 实现中的工作负载分配。
这个想法是节点 0 将有一个文件名列表 ("list_file"(。当其他节点空闲时,它们将向节点 0 发送文件请求,节点 0 将发回文件名。
一旦没有更多的文件要发送节点 0,就会完成其工作。但是,如何向其他节点中的读取器线程发出信号,表明节点 0 没有更多文件,它们应该停止等待节点 0 发送新文件。
// pid 0 will collect all input text file names and distribute them to other nodes
if (pid == 0)
{
vector<char*> list_file; // a vector to hold the input text file names to be processed
GetInputFile(argv, list_file); // argv[1] is a text file that contains the input text files to be processed, all the text file names will be added to list_file
num_file_remaining = list_file.size(); // number of file remained in the queue to be processed
MPI_Status requeststats; // for MPI_recv
// listen to request for file from other nodes as long as there is file left in list_file
while (num_file_remaining != 0)
{
MPI_recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &requeststats); // listen to request for file
MPI_send(list_file.back(), 5 * MAX_WORD_LENGTH, MPI_CHAR, requeststats.MPI_SOURCE, requeststats.MPI_SOURCE, MPI_COMM_WORLD); // send the file to respective node
list_file.pop_back(); // remove the file that was just sent
num_file_remaining -= 1; // reduce the number of file remained in the queue
}
}
// other nodes will request work from pid 0
if (pid != 0)
{
char* file_name;
while (num_file_remaining != 0)
{
MPI_send(NULL, 0, MPI_INT, 0, 0, MPI_COMM_WORLD); // send the request for a file to node 0
MPI_recv(file_name, 5 * MAX_WORD_LENGTH, MPI_CHAR, 0, pid, MPI_COMM_WORLD, MPI_STATUS_IGNORE); // receive the file from node 0
cout << "pid: " << pid << " - " << file_name << endl; // process the file
// HOW TO EXIT THE LOOP WHEN NO MORE FILE TO RECEIVE FROM NODE 0
}
}
进行有效的MPI_Irecv
调用:
// set this tag to whatever you want and don’t use it for anything else
constexpr int AM_I_FINISHED_TAG = 1376;
MPI_Request am_I_finished = MPI_Irecv(nullptr, 0, MPI_INT, 0, AM_I_FINISHED_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
每当处理完子节点上的文件时,请使用 MPI_Test 检查该请求是否完成。当主节点不再为子节点工作时,让它使用 AM_I_FINISHED_TAG 将数据发送到所有子节点。
相关文章:
- 反向给定链表中的K节点
- QSqlquery prepare()和bindvalue()不工作
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 导入库可以跨dll版本工作吗
- Boost Graph Library,修复节点大小
- C++A*算法并不总是在路径中具有目标节点
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 如何找到2个单链表的公共节点
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 双向链表 std::unique_ptr 类在节点删除时无法按预期工作
- 链表中的交换节点如何工作
- 如何向其他节点发出信号,表明主节点没有更多工作可用
- 从链表中删除节点无法正常工作
- 数组类节点不工作
- 如何从节点在Heroku上运行可执行文件,在本地工作
- MPI代码不工作与2个节点,但与1
- ROS节点无法通过启动文件执行工作