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。