Exercise: Subarray
In this exercise we show how MPI_Type_create_subarray can be used to create a derived datatype which is a portion of a multi-dimensional array. It should be noted that the multi-dimensional array may be implemented as a one-dimensional array, which is a common practice in the C programming language.
- In the directory Subarray, there are f and c subdirectories for Fortran and C, respectively. If you have loaded the modules as described in exercise Hello, compilers and MPI wrappers are ready for use. The compilations should be carried out using mpiicc and mpiifort for C and Fortran, respectively.
- This code should be executed only with two processes, otherwise it aborts with an error message.
- In the program, rank=0 sends a block of 3x2 which is a part of a 5x4 matrix. This means that some elements of the subarray are not contiguous in memory and cannot be sent in one call using the default datatypes available in MPI libraries.
- There are 6 FIXME markers which are related to the creation and use of the new datatype.
Questions:
- Is it obligatory to define the new datatype on rank=1 to be able to receive the 6 elements of the matrix? If not, why would changes in the code be necessary at all?
- Could the C and Fortran programs be called together such that one process is the C program and the other one the Fortran program?
Last modified: Friday, 12 April 2024, 10:36 AM