Assume we are writing out a 100x100 2D array of double
precision floating point numbers that is
distributed among 4 processes such that each process has a block of
25 columns (e.g., process 0 has columns 0-24, process 1 has columns
25-49, etc.; see Figure 28
).
To create the filetypes for each process one could
use the following C program
(see Section Subarray Datatype Constructor
on
page Subarray Datatype Constructor
):

Or, equivalently in Fortran:double subarray[100][25]; MPI_Datatype filetype; int sizes[2], subsizes[2], starts[2]; int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); sizes[0]=100; sizes[1]=100; subsizes[0]=100; subsizes[1]=25; starts[0]=0; starts[1]=rank*subsizes[1]; MPI_Type_create_subarray(2, sizes, subsizes, starts, MPI_ORDER_C, MPI_DOUBLE, &filetype);

The generated filetype will then describe the portion of the file contained within the process's subarray with holes for the space taken by the other processes. Figure 29 shows the filetype created for process 1.double precision subarray(100,25) integer filetype, rank, ierror integer sizes(2), subsizes(2), starts(2) call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror) sizes(1)=100 sizes(2)=100 subsizes(1)=100 subsizes(2)=25 starts(1)=0 starts(2)=rank*subsizes(2) call MPI_TYPE_CREATE_SUBARRAY(2, sizes, subsizes, starts, & MPI_ORDER_FORTRAN, MPI_DOUBLE_PRECISION, & filetype, ierror)

Return to MPI-2.2 Standard Index

Return to MPI Forum Home Page

(Unofficial) MPI-2.2 of September 4, 2009

HTML Generated on September 10, 2009