博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MPI笔记:派生数据类型相关例子
阅读量:4137 次
发布时间:2019-05-25

本文共 1975 字,大约阅读时间需要 6 分钟。

/*文件名:mpi_structs.c目的:该代码用于测试向量类型、结构类型、打包解包的传输效率测试传输的数据是100000个MPI_DOUBLE类型,且以24为间隔存储的数据派生数据类型相关的函数:MPI_Type_vectorMPI_Type_create_struct(新)/MPI_Type_struct(弃)MPI_Type_commitMPI_Type_extent运行:mpicc -g mpi_structs.c -o mpi_structs -Wallmpirun -n 2 ./mpi_structs*/#include 
#include
#include
#include "mpi.h"#define NUMBER_OF_TESTS 10 // 重复运行的次数int main(int argc, char *argv[]){
MPI_Datatype vec1, vec_n; int blocklens[2]; MPI_Aint indices[2]; MPI_Datatype old_types[2]; double *buf, // 原数据所在的不连续的缓冲区 *lbuf; // 打包所需的连续存储的缓冲区 register double *in_p, *out_p; int rank; int n, stride; double t1, t2, tmin; int i, j, k, nloop; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); n = 1000; // vec1中块的个数 stride = 24; // vec1中每个块起始位置的间隔 nloop = 100000 / n; // 一共100,000个MPI_DOUBLE类型的数据,分成nloop个vec1类型进行传输 buf = (double *)malloc(n*stride*sizeof(double)); if(!buf){
fprintf(stderr, "Could not allocate send/recv buffer of size %d\n", n*stride); MPI_Abort(MPI_COMM_WORLD, 1); } lbuf = (double *)malloc(n*sizeof(double)); if(!buf){
fprintf(stderr, "Could not allocate send/recv lbuffer of size %d\n", n); MPI_Abort(MPI_COMM_WORLD, 1); } if(rank == 0) printf("Kind\t\t n\t stride\t time(sec)\t Rate(MB/sec)\n"); /* 向量类型的传输 */ MPI_Type_vector(n, 1, stride, MPI_DOUBLE, &vec1); MPI_Type_commit(&vec1); /* 打印派生数据类型的跨度 */ if(rank == 0){
MPI_Aint ext[1]; MPI_Type_extent(MPI_DOUBLE, ext); printf("extent of MPI_DOUBLE : %d\n",(int)(*ext)); // extent of MPI_DOUBLE: 8 MPI_Type_extent(vec1, ext); printf("extent of vec1 : %d\n",(int)(*ext)); // extent of vec1: 191816 = (n-1)*stride*ex(MPI_DOUBLE)+ex(MPI_DOUBLE) } tmin = 1000; // 重复计算10遍时间,取其中运行的最短时间为tmin for(k=0; k

代码来源:《高性能计算之并行编程技术——MPI并行编程设计》都志辉 P165

单机运行结果如下:
运行结果

转载地址:http://evxvi.baihongyu.com/

你可能感兴趣的文章
删除weblogic 域
查看>>
VMware Workstation 14中文破解版下载(附密钥)(笔记)
查看>>
日志框架学习
查看>>
日志框架学习2
查看>>
SVN-无法查看log,提示Want to go offline,时间显示1970问题,error主要是 url中 有一层的中文进行了2次encode
查看>>
NGINX
查看>>
Qt文件夹选择对话框
查看>>
1062 Talent and Virtue (25 分)
查看>>
1061 Dating (20 分)
查看>>
1060 Are They Equal (25 分)
查看>>
83. Remove Duplicates from Sorted List(easy)
查看>>
88. Merge Sorted Array(easy)
查看>>
leetcode刷题191 位1的个数 Number of 1 Bits(简单) Python Java
查看>>
leetcode刷题198 打家劫舍 House Robber(简单) Python Java
查看>>
NG深度学习第一门课作业2 通过一个隐藏层的神经网络来做平面数据的分类
查看>>
leetcode刷题234 回文链表 Palindrome Linked List(简单) Python Java
查看>>
NG深度学习第二门课作业1-1 深度学习的实践
查看>>
Ubuntu下安装Qt
查看>>
Qt札记
查看>>
我的vimrc和gvimrc配置
查看>>