Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge tag 'v3_9_90' into hypervisor
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / tresized.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test of type resized";
14 */
15
16 int main( int argc, char *argv[] )
17 {
18     int errs = 0, i;
19     int rank, size, source, dest;
20     int count; 
21     int *buf; 
22     MPI_Comm      comm;
23     MPI_Status    status;
24     MPI_Datatype  newtype;
25
26     MTest_Init( &argc, &argv );
27
28     comm = MPI_COMM_WORLD;
29
30     /* Determine the sender and receiver */
31     MPI_Comm_rank( comm, &rank );
32     MPI_Comm_size( comm, &size );
33     source = 0;
34     dest   = size - 1;
35         
36     MPI_Type_create_resized( MPI_INT, 0, 3 * sizeof(int), &newtype );
37     MPI_Type_commit( &newtype );
38     for (count = 1; count < 65000; count = count * 2) {
39         buf = (int *)malloc( count * 3 * sizeof(int) );
40         if (!buf) {
41             MPI_Abort( comm, 1 );
42         }
43         for (i=0; i<3*count; i++) buf[i] = -1;
44         if (rank == source) {
45             for (i=0; i<count; i++) buf[3*i] = i;
46             MPI_Send( buf, count, newtype, dest, 0, comm );
47             MPI_Send( buf, count, newtype, dest, 1, comm );
48         }
49         else if (rank == dest) {
50             MPI_Recv( buf, count, MPI_INT, source, 0, comm, &status );
51             for (i=0; i<count; i++) {
52                 if (buf[i] != i) {
53                     errs++;
54                     if (errs < 10) {
55                         printf( "buf[%d] = %d\n", i, buf[i] );
56                     }
57                 }
58             }
59             for (i=0; i<count*3; i++) buf[i] = -1;
60             MPI_Recv( buf, count, newtype, source, 1, comm, &status );
61             for (i=0; i<count; i++) {
62                 if (buf[3*i] != i) {
63                     errs++;
64                     if (errs < 10) {
65                         printf( "buf[3*%d] = %d\n", i, buf[i] );
66                     }
67                 }
68             }
69         }
70     }
71
72     MPI_Type_free( &newtype );
73
74     MTest_Finalize( errs );
75     MPI_Finalize();
76     return 0;
77 }