Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / simple-pack-external2.c
1 #include <mpi.h>
2 #include <stdlib.h>
3
4 char *datarep = "external32";
5
6 #define UINT_COUNT (2)
7 #define DBLE_COUNT (24)
8
9 int main(void)
10 {
11     unsigned *uint_data = calloc(UINT_COUNT, sizeof(unsigned));
12     double *dble_data = calloc(DBLE_COUNT, sizeof(double));
13     MPI_Aint uint_pack_size, dble_pack_size;
14     MPI_Aint pack_size;
15     void *pack_buffer;
16     MPI_Aint position = 0;
17
18     MPI_Init(NULL, NULL);
19
20     MPI_Pack_external_size(datarep, UINT_COUNT, MPI_UNSIGNED, &uint_pack_size);
21     MPI_Pack_external_size(datarep, DBLE_COUNT, MPI_DOUBLE, &dble_pack_size);
22
23     pack_size = uint_pack_size + dble_pack_size;
24     pack_buffer = malloc(pack_size);
25
26     MPI_Pack_external(datarep, uint_data, UINT_COUNT, MPI_UNSIGNED, pack_buffer, pack_size,
27                       &position);
28     MPI_Pack_external(datarep, dble_data, DBLE_COUNT, MPI_DOUBLE, pack_buffer, pack_size,
29                       &position);
30
31     free(pack_buffer);
32     free(dble_data);
33     free(uint_data);
34
35     MPI_Finalize();
36
37     printf(" No Errors\n");
38
39     return 0;
40 }