MPI_Extent等函数的使用

7 篇文章 0 订阅

  MPI_Type_extent -  Returns the extent of a datatype

返回对应数据类型的长度


以下次序输出类型长度为4,8单位是字节

#include<stdio.h>
#include "mpi.h"

int main(int argc ,char *argv[]){

	MPI_Init(&argc,&argv);
	int myrank;
	MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
	int extent;
	int extent1;
	MPI_Type_extent(MPI_INT,&extent);
	MPI_Type_extent(MPI_DOUBLE,&extent1);
	if(myrank==0){
		printf("length of MPI_INT is %d bytes\n",extent);
		printf("length is MPI_DOUBLE is %d bytes\n",extent1);
	}
	MPI_Finalize();



}


#include<stdio.h>
#include "mpi.h"

int main(int argc ,char *argv[]){

	MPI_Init(&argc,&argv);
	int myrank;
	MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
	int extent;
	int extent1;
	int extent2;
	MPI_Type_extent(MPI_INT,&extent);
	MPI_Type_extent(MPI_DOUBLE,&extent1);
	MPI_Datatype newType;
	int blocklen[2]={2,3};
	int count=2;
	MPI_Aint indices[2]={0,8};
	MPI_Datatype oldtype[2]={MPI_INT,MPI_DOUBLE};
	MPI_Type_struct(count,blocklen,indices,oldtype,&newType);
	MPI_Type_commit(&newType);
      MPI_Type_extent(newType,&extent2);
	if(myrank==0){
		printf("length of MPI_INT is %d bytes\n",extent);
		printf("length is MPI_DOUBLE is %d bytes\n",extent1);
            printf("length is newType is %d bytes\n",extent2);
	}
	MPI_Finalize();



}

MPI_Test_extent返回的是构造的结构体中的第一个成员所在的位置到最后一个成员所在的位置所占的字节数。
indices
              - byte displacement of each block (array)
这里indices为struct中每个块所在位置离这个结构首部的偏移量
比如MPI_Aint indices[2]={100,108};返回的还是32 bytes。
若indices[2]={0,9},返回的是36 bytes,按理说应该返回33bytes,但是好像编译器对编译器偏移量是4字节对齐的,不是4字节倍数的自动补成4bytes倍数。
indices[2]={0,10},indices[2]={0,11},indices[2]={0,12}返回的均为36 bytes。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值