15.9.2. Subarray Filetype Constructor

PreviousUpNext
Up: Examples Next: Tool Support Previous: Double Buffering with Split Collective I/O

Image file


Figure 38: Example array file layout


Example Assume we are writing out a 100×100 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 38). To create the filetypes for each process one could use the following C program (see Section Subarray Datatype Constructor):


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); 

Or, equivalently in Fortran:


Example [Local subarray for file output in Fortran 90]FortranLocal subarray for file output in Fortran 90@Local subarray for file output in Fortran 90MPI_TYPE_CREATE_SUBARRAY Writing out a 100×100 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 38).

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) 

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 39 shows the filetype created for process 1.

Image file


Figure 39: Example local array filetype for process 1


PreviousUpNext
Up: Examples Next: Tool Support Previous: Double Buffering with Split Collective I/O


Return to MPI-5.0 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-5.0 of June 9, 2025
HTML Generated on March 2, 2025