MPI分布阵列
MPI distributing array
我正试图用MPI结构写一个c++程序。我想从一个巨大的文件中读取,并将数字存储到一个数组中。我希望数组是本地的,也就是说,我不希望所有线程都拥有整个数组,因为数组非常庞大。每个线程进行本地计算,并为进一步的计算"发送"answers"接收"。最好的方法是什么?我在网上看到的所有代码都使用rand()函数生成本地数组,但我想从文件中读取值。
这可能是我想要的:
int main()
{
// Read from a file
// store in array a[] temporarily
//MPI_init();
//My thread should have an array b[] that is a subset of a[]
//MY code to do a numerical simulation
//MPI_finalise();
return 0;
}
PS:我的数据结构比数组更复杂。I存储了一个巨大的图。它更像是一个链表数组或者向量数组。 MPI是进程之间而不是线程之间的消息传递系统。当进程在不同的机器上运行时,这是一个真正的区别。
如果你想做的操作在你的图的每个部分是完全独立的,我会选择并行读取。另一个原因是如果你想读取和展开一个数组你可以这样写:
int main(int argc, char * argv[])
{
MPI_init(&argc, &argv);
int prank; MPI_Comm_rank(MPI_COMM_WORLD, &prank);
int psize; MPI_Comm_size(MPI_COMM_WORLD, &psize);
if(prank == 0) {
// Read from a file
// store in array a[] temporarily
MPI_Scatter(a, length(a)/psize, MPI_DATATYPE_OF_A, b, leanght(a)/psize, MPI_DATATYPE_OF_A, 0, MPI_COMM_WORLD);
// this works only if length(a) is a multiple of psize, otherwhy you should go for MPI_Scatterv
} else {
MPI_Scatter(NULL, 0, MPI_DATATYPE_OF_A, b, leanght(a)/psize, MPI_DATATYPE_OF_A, 0, MPI_COMM_WORLD);
}
//My thread should have an array b[] that is a subset of a[]
//MY code to do a numerical simulation
MPI_finalise();
return 0;
}
但是如果你有数组,如果你有一个图,你应该看看图分区器来分割你的图,并将碎片发送到不同的进程。我觉得崔莉诺斯为你做了一切。否则,你可以使用Scotch或Metis为你的图形上色,然后使用MPI将每种颜色发送给处理器。
相关文章:
- OpenMP阵列性能较差
- 如何将三维尺寸不固定的三维阵列展平为一维阵列
- 当我的阵列太大时出现分段错误
- 位阵列上的快速AND运算
- 阵列必须使用大括号封闭的初始器进行初始化
- 没有从阵列<float>到阵列<int>的可行转换
- C++动态安全 2D 交错阵列
- 将平面阵列重塑为复杂的特征类型
- 如何使用英特尔 PIN 捕获阵列的所有负载?
- 为什么我能够为阵列分配比计算机实际拥有的内存更多的内存
- 库特<<恩德尔;不适用于打印 2D 阵列
- 数组类 阵列的打印输出
- 从较小的阵列到较大的阵列的元素级转换
- 仅在大型阵列上出现合并排序分段错误
- 从阵列C++中删除重复项
- 阵列的大小在C++中是否灵活?
- 反转阵列中的正序列
- 改变或缩放两个正态分布以具有特定的相关系数
- 如何创建没有特定定义的随机分布?uniform_int_distribution是从其他类继承的吗?
- MPI分布阵列