From cc8362328f642ef16280f1e8c0633532bc8e8fc1 Mon Sep 17 00:00:00 2001 From: Cristian-Vasile Achim <66278390+csccva@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:01:09 +0300 Subject: [PATCH] Update zz-user-defined-datatypes.md --- mpi/docs/zz-user-defined-datatypes.md | 165 -------------------------- 1 file changed, 165 deletions(-) diff --git a/mpi/docs/zz-user-defined-datatypes.md b/mpi/docs/zz-user-defined-datatypes.md index 9d2c20dec..952132fa6 100644 --- a/mpi/docs/zz-user-defined-datatypes.md +++ b/mpi/docs/zz-user-defined-datatypes.md @@ -385,168 +385,3 @@ MPI_Send(particle, 1000*sizeof(particle[0]), MPI_BYTE, ...); - Ensuring the correct extent of the derived data type is important - MPI provides constructors for several specific types - -# User-defined datatypes: other datatype constructors {.section} - -# MPI_TYPE_CONTIGUOUS - -MPI_Type_contiguous(`count`{.input}, `oldtype`{.input}, `newtype`{.output}) - : `count`{.input} - : number of oldtypes - : `oldtype`{.input} - : old type - : `newtype`{.output} - : new datatype - -- Usage mainly for programming convenience - - derived types in all communication calls - - -
-```fortranfree -! Using derived type -call mpi_send(buf, 1, conttype, ...) -``` -
-
-```fortranfree -! Equivalent call with count and basic type -call mpi_send(buf, count, MPI_REAL, ...) -``` -
-
- - -# MPI_TYPE_INDEXED {.split-def-3} - -- Creates a new type from blocks comprising identical elements - - The size and displacements of the blocks may vary - -MPI_Type_indexed(`count`{.input}, `blocklens`{.input}, `displs`{.input}, `oldtype`{.input}, `newtype`{.output}) - : `count`{.input} - : number of blocks - - `blocklens`{.input} - : lengths of the blocks (array) - - `displs`{.input} - : displacements (array) in extent of oldtypes - - `oldtype`{.input} - : original type - - `newtype`{.output} - : new type - - `-`{.ghost} - : `-`{.ghost} - -

-![](img/type_indexed.png){.center width=100%} - -# Example: an upper triangular matrix - -

-```c -/* Upper triangular matrix */ -double a[100][100]; -int disp[100], blocklen[100], int i; -MPI_Datatype upper; -/* compute start and size of rows */ -for (i=0; i<100; i++) { - disp[i] = 100*i+i; - blocklen[i] = 100-­i; -} -/* create a datatype for upper tr matrix */ -MPI_Type_indexed(100,blocklen,disp, - MPI_DOUBLE,&upper); -MPI_Type_commit(&upper); -/* ... send it ... */ -MPI_Send(a,1,upper,dest, tag, MPI_COMM_WORLD); -MPI_Type_free(&upper); -``` -
- -
-![](img/triangle.png){.center width=65%} -
- -# Subarray - -
-- Subarray datatype describes a N-dimensional subarray within a -N-dimensional array -- Array can have either C (row major) or Fortran (column major) -ordering in memory -
- -
-![](img/subarray.png){.center width=60%} -
- - -# MPI_TYPE_CREATE_SUBARRAY {.split-def-3} - - -MPI_Type_create_subarray(`ndims`{.input}, `sizes`{.input}, `subsizes`{.input}, `offsets`{.input}, `order`{.input}, `oldtype`{.input}, `newtype`{.output}) - : `ndims`{.input} - : number of array dimensions - - `sizes`{.input} - : number of array elements in each dimension (array) - - `subsizes`{.input} - : number of subarray elements in each dimension (array) - - `offsets`{.input} - : starting point of subarray in each dimension (array) - - `order`{.input} - : storage order of the array. Either `MPI_ORDER_C` or - `MPI_ORDER_FORTRAN` - - `oldtype`{.input} - : oldtype - - `newtype`{.output} - : resulting type - - `-`{.ghost} - : `-`{.ghost} - -# Example: subarray - -
- -```c -int a_size[2] = {5,5}; -int sub_size[2] = {2,3}; -int sub_start[2] = {1,2}; -MPI_Datatype sub_type; -double array[5][5]; - -for(i = 0; i < a_size[0]; i++) - for(j = 0; j < a_size[1]; j++) - array[i][j] = rank; - -MPI_Type_create_subarray(2, a_size, sub_size, - sub_start, MPI_ORDER_C, MPI_DOUBLE, &sub_type); - -MPI_Type_commit(&sub_type); - -if (rank==0) - MPI_Recv(array[0], 1, sub_type, 1, 123, - MPI_COMM_WORLD, MPI_STATUS_IGNORE); -if (rank==1) - MPI_Send(array[0], 1, sub_type, 0, 123, - MPI_COMM_WORLD); - -MPI_Type_free(&sub_type); - -``` - -
-
-![](img/type_array.png){.center width=100%} -