1 | #include <stdio.h> |
---|
2 | #include <string.h> |
---|
3 | #include "mpi.h" |
---|
4 | #include "oasis_c.h" |
---|
5 | |
---|
6 | int main(int argc, char *argv[]) |
---|
7 | { |
---|
8 | char *comp_name = "xios"; |
---|
9 | int il_x; |
---|
10 | |
---|
11 | fprintf(stdout,"Component name: %s\n", comp_name); |
---|
12 | fflush(stdout); |
---|
13 | |
---|
14 | bool coupled = 1; |
---|
15 | int comp_id; |
---|
16 | |
---|
17 | OASIS_CHECK_ERR(oasis_c_init_comp(&comp_id, comp_name, coupled)); |
---|
18 | fprintf(stdout, "Xios: Component ID: %d\n", comp_id); |
---|
19 | fflush(stdout); |
---|
20 | |
---|
21 | MPI_Comm localcomm; |
---|
22 | OASIS_CHECK_ERR(oasis_c_get_localcomm(&localcomm)); |
---|
23 | int comm_size; |
---|
24 | OASIS_CHECK_MPI_ERR(MPI_Comm_size(localcomm, &comm_size)); |
---|
25 | int comm_rank; |
---|
26 | OASIS_CHECK_MPI_ERR(MPI_Comm_rank(localcomm, &comm_rank)); |
---|
27 | fprintf(stdout,"Xios: rank = %d of %d\n",comm_rank,comm_size); |
---|
28 | fflush(stdout); |
---|
29 | |
---|
30 | OASIS_CHECK_ERR(oasis_c_enddef()); |
---|
31 | |
---|
32 | char *cnames[3] = {"receiver","xios","sender-box"}; |
---|
33 | int root_ranks[3]; |
---|
34 | |
---|
35 | MPI_Comm intra_comm; |
---|
36 | OASIS_CHECK_ERR(oasis_c_get_multi_intracomm(&intra_comm, 3, cnames, root_ranks)); |
---|
37 | int intra_size; |
---|
38 | OASIS_CHECK_MPI_ERR(MPI_Comm_size(intra_comm, &intra_size)); |
---|
39 | int intra_rank; |
---|
40 | OASIS_CHECK_MPI_ERR(MPI_Comm_rank(intra_comm, &intra_rank)); |
---|
41 | fprintf(stdout,"Xios rank(%d) intra_comm: rank = %d of %d\n",comm_rank, intra_rank, intra_size); |
---|
42 | fflush(stdout); |
---|
43 | |
---|
44 | int orig; |
---|
45 | int i; |
---|
46 | if ( comm_rank == 0) { |
---|
47 | fflush(stdout); |
---|
48 | for (i = 0; i<3 ; i++) { |
---|
49 | fprintf(stdout,"Xios: component %s starts at rank %d\n",cnames[i],root_ranks[i]); |
---|
50 | fflush(stdout); |
---|
51 | if ( strcmp(cnames[i], "sender-box") == 0 ) orig = root_ranks[i]; |
---|
52 | } |
---|
53 | il_x = 0; |
---|
54 | MPI_Status status; |
---|
55 | OASIS_CHECK_MPI_ERR(MPI_Recv(&il_x, 1, MPI_INT, orig, 0, intra_comm, &status)); |
---|
56 | fprintf(stdout,"Xios rank(%d) received il_x = %d\n",comm_rank,il_x); |
---|
57 | } |
---|
58 | |
---|
59 | il_x = 0; |
---|
60 | if ( comm_rank == 0) il_x = 222; |
---|
61 | |
---|
62 | int root; |
---|
63 | for (i = 0; i<3 ; i++) { |
---|
64 | if ( strcmp(cnames[i],comp_name) == 0 ) root = root_ranks[i]; |
---|
65 | } |
---|
66 | OASIS_CHECK_MPI_ERR(MPI_Bcast(&il_x, 1, MPI_INT, root, intra_comm)); |
---|
67 | fprintf(stdout,"Xios rank(%d) got broadcasted il_x = %d\n",comm_rank,il_x); |
---|
68 | fflush(stdout); |
---|
69 | |
---|
70 | OASIS_CHECK_ERR(oasis_c_terminate()); |
---|
71 | |
---|
72 | } |
---|