Skip to content

Commit

Permalink
Update zz-user-defined-datatypes.md
Browse files Browse the repository at this point in the history
  • Loading branch information
csccva authored Jun 17, 2024
1 parent f7b9d59 commit cc83623
Showing 1 changed file with 0 additions and 165 deletions.
165 changes: 0 additions & 165 deletions mpi/docs/zz-user-defined-datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<small>
<div class=column>
```fortranfree
! Using derived type
call mpi_send(buf, 1, conttype, ...)
```
</div>
<div class=column>
```fortranfree
! Equivalent call with count and basic type
call mpi_send(buf, count, MPI_REAL, ...)
```
</div>
</small>


# 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}

<p>
![](img/type_indexed.png){.center width=100%}

# Example: an upper triangular matrix

<div class="column">
```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);
```
</div>
<div class="column">
![](img/triangle.png){.center width=65%}
</div>
# Subarray
<div class=column>
- 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
</div>
<div class="column">
![](img/subarray.png){.center width=60%}
</div>
# MPI_TYPE_CREATE_SUBARRAY {.split-def-3}
<!--- Creates a type describing an N-dimensional subarray within an N-dimensional array
-->
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
<div class=column>
<small>
```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);
```
</small>
</div>
<div class=column>
![](img/type_array.png){.center width=100%}
</div>

0 comments on commit cc83623

Please sign in to comment.