Contiguous Derived Data
来源:互联网 发布:sql server offset 编辑:程序博客网 时间:2024/05/01 23:04
1. 连续的构造数据类型
(1)把同一内置数据类型/连续的多个元素组合成一个构造数据类型
2. 举例
#include<stdio.h>#include"mpi.h"#define SIZE 4int main(int argc, char *argv[]){ int totalNumTasks, rankID; float sendBuf[SIZE][SIZE] = { {1.0, 2.0, 3.0, 4.0}, {5.0, 6.0, 7.0, 8.0}, {9.0, 10.0, 11.0, 12.0}, {13.0, 14.0, 15.0, 16.0} }; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rankID); MPI_Comm_size(MPI_COMM_WORLD, &totalNumTasks); if(totalNumTasks == SIZE){ MPI_Datatype rowType; MPI_Type_contiguous(SIZE, MPI_FLOAT, &rowType);//each rowType has NUM = 4 data MPI_Type_commit(&rowType); int source = 0; int sendCount = 1; int recvCount = 1; float recvBuf[SIZE]; MPI_Scatter(sendBuf, sendCount, rowType, recvBuf, recvCount, rowType, source, MPI_COMM_WORLD); printf("my rankID = %d, receive Results: %f %f %f %f, total = %f\n", rankID, recvBuf[0], recvBuf[1], recvBuf[2], recvBuf[3], recvBuf[0] + recvBuf[1] + recvBuf[2] + recvBuf[3]); }else if(totalNumTasks == 8){ MPI_Datatype rowType; int NUM = 2; MPI_Type_contiguous(NUM, MPI_FLOAT, &rowType);//each rowType has NUM = 2 data MPI_Type_commit(&rowType); int source = 0; int sendCount = 1; int recvCount = 1; float recvBuf[2]; MPI_Scatter(sendBuf, sendCount, rowType, recvBuf, recvCount, rowType, source, MPI_COMM_WORLD); printf("my rankID = %d, receive result: %f %f, total = %f\n", rankID, recvBuf[0], recvBuf[1], recvBuf[0] + recvBuf[1]); }else printf("error, please specify -n %d or -n %d\n", SIZE, 2*SIZE); MPI_Finalize(); return 0;}
3. 编译执行
[amao@amao991 mpi-study]$ mpicc contiguousDerivedData.c [amao@amao991 mpi-study]$ mpiexec -n 4 -f machinefile ./a.out my rankID = 0, receive Results: 1.000000 2.000000 3.000000 4.000000, total = 10.000000my rankID = 1, receive Results: 5.000000 6.000000 7.000000 8.000000, total = 26.000000my rankID = 3, receive Results: 13.000000 14.000000 15.000000 16.000000, total = 58.000000my rankID = 2, receive Results: 9.000000 10.000000 11.000000 12.000000, total = 42.000000[amao@amao991 mpi-study]$ mpiexec -n 8 -f machinefile ./a.out my rankID = 6, receive result: 13.000000 14.000000, total = 27.000000my rankID = 7, receive result: 15.000000 16.000000, total = 31.000000my rankID = 4, receive result: 9.000000 10.000000, total = 19.000000my rankID = 0, receive result: 1.000000 2.000000, total = 3.000000my rankID = 1, receive result: 3.000000 4.000000, total = 7.000000my rankID = 5, receive result: 11.000000 12.000000, total = 23.000000my rankID = 3, receive result: 7.000000 8.000000, total = 15.000000my rankID = 2, receive result: 5.000000 6.000000, total = 11.000000
4. 总结
(1) 组合数据类型主要是通过以下语句实现的
MPI_Datatype rowType;
MPI_Type_contiguous(SIZE, MPI_FLOAT, &rowType);//each rowType has NUM = 4 data
MPI_Type_commit(&rowType);
- Contiguous Derived Data
- Derived Data Type
- Contiguous Array
- Contiguous Array
- Creating a CAknEnumeratedTextPopupSettingItem-derived class to use dynamic data at runtime
- Maximum Contiguous Mum I
- Contiguous Implementation remove函数
- contiguous/flush/informed
- LeetCode 525. Contiguous Array
- Leetcode 525. Contiguous Array
- 525. Contiguous Array
- 525. Contiguous Array
- 525. Contiguous Array
- [LeetCode]525. Contiguous Array
- 525. Contiguous Array Medium
- 525. Contiguous Array
- 525. Contiguous Array
- [leetcode] 525. Contiguous Array
- java.lang.ArrayIndexOutOfBoundsException异常分析及解决
- Linux启动流程图
- JAVA解析纯真IP地址库
- vim缩进与TAB设置
- S40后台运行权限破解详尽图文
- Contiguous Derived Data
- pig的疑问:如何执行简单查询?
- 关于C++中随机数的问题.
- Oracle Undo
- 第1章 Oracle关系数据库 Oracle 11g完全学习手册
- 关于计算Java程序运行时间
- 面向对象JAVA多态性
- android XPath 解析xml
- ORACLE运营维护手册