Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add 2 tests for comm
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / comm_info2.c
1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5
6 #include <stdio.h>
7 #include <mpi.h>
8 #include "mpitest.h"
9
10
11 /*
12   This program provides tests cases for the functional evaluation
13   of the MPI communicator info hints infrastructure.
14  */
15
16 int main(int argc, char **argv)
17 {
18     int rank;
19     MPI_Info info_in, info_out;
20     int errs = 0;
21     MPI_Comm comm;
22     char query_key[MPI_MAX_INFO_KEY];
23     char val[MPI_MAX_INFO_VAL];
24     char new_key[MPI_MAX_INFO_KEY];
25     MPI_Comm comm_dup2;
26     MPI_Comm comm_dup3;
27     MPI_Comm comm_dup4;
28     MPI_Comm comm_split1;
29     MPI_Info info_out2;
30     MPI_Info info_out3;
31     MPI_Info info_out5;
32     MPI_Info info_in3;
33
34
35     /* Read arguments: info key and value */
36     snprintf(query_key, MPI_MAX_INFO_KEY, "arbitrary_key");
37     snprintf(val, MPI_MAX_INFO_VAL, "arbitrary_val");
38
39     MTest_Init(&argc, &argv);
40     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
41
42     /* Goal of the test is only to make sure that MPI does not break */
43     /* No expectation is made on if the hints are actually set */
44
45     /* Test 1: comm_dup */
46     if (rank == 0)
47         MTestPrintfMsg(1,
48                        "Testing MPI_Comm_dup with a source comm that has default comm infohints");
49     MPI_Comm_dup(MPI_COMM_WORLD, &comm);
50
51     /* Test 2: comm_set_info and comm_get_info */
52     if (rank == 0)
53         MTestPrintfMsg(1, "Testing MPI_Comm_set_info and MPI_Comm_get_info");
54     MPI_Info_create(&info_in);
55     MPI_Info_set(info_in, query_key, val);
56     MPI_Comm_set_info(comm, info_in);
57     MPI_Comm_get_info(comm, &info_out);
58     MPI_Info_free(&info_out);
59
60     /* Test 3: com_dup after info is set in source comm */
61     if (rank == 0)
62         MTestPrintfMsg(1, "Testing MPI_Comm_dup: source comm has user provided comm infohint");
63     MPI_Comm_dup(comm, &comm_dup2);
64     MPI_Comm_get_info(comm_dup2, &info_out2);
65     MPI_Comm_free(&comm_dup2);
66     MPI_Info_free(&info_out2);
67
68     /* Test 4: Comm_dup_with_info */
69     if (rank == 0)
70         MTestPrintfMsg(1, "Testing MPI_Comm_dup_with_info");
71
72     /* Add 2 hints and create comm dup with info */
73     MPI_Info_create(&info_in3);
74     MPI_Info_set(info_in3, query_key, val);
75     snprintf(new_key, MPI_MAX_INFO_KEY, "arbitrary_key_2");
76     MPI_Info_set(info_in3, new_key, "arbitrary_value_2");
77     MPI_Comm_dup_with_info(comm, info_in3, &comm_dup3);
78     MPI_Comm_get_info(comm_dup3, &info_out3);
79     MPI_Info_free(&info_in3);
80     MPI_Info_free(&info_out3);
81     MPI_Comm_free(&comm_dup3);
82
83     /* Test 5: MPI_Comm_split_type */
84     MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, info_in, &comm_split1);
85     MPI_Comm_get_info(comm_split1, &info_out5);
86     MPI_Info_free(&info_out5);
87     MPI_Comm_free(&comm_split1);
88
89     /* Test 6: comm_dup_with_info with info=MPI_INFO_NULL */
90     if (rank == 0)
91         MTestPrintfMsg(1, "Testing MPI_Comm_dup_with_info with MPI_INFO_NULL");
92     MPI_Comm_dup_with_info(comm, MPI_INFO_NULL, &comm_dup4);
93     MPI_Comm_free(&comm_dup4);
94
95     /* TODO - Test: MPI_Dist_graph_create_adjacent */
96
97     /* Release remaining resources */
98     MPI_Info_free(&info_in);
99     MPI_Comm_free(&comm);
100
101     MTest_Finalize(errs);
102     return MTestReturnValue(errs);
103 }