source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/7-multiple-puts/C/receiver_two.c @ 6331

Last change on this file since 6331 was 6331, checked in by aclsce, 17 months ago

Moved oasis-mct_5.0 in oasis3-mct/branches directory.

File size: 3.3 KB
Line 
1#include <stdio.h>
2#include <math.h>
3#include "oasis_c.h"
4
5int main(int argc, char *argv[])
6{
7  char *comp_name = "receiver_two";
8  fprintf(stdout,"Component name: %s\n", comp_name);
9  fflush(stdout);
10
11  int comp_id;
12
13  OASIS_CHECK_ERR(oasis_c_init_comp(&comp_id, comp_name, OASIS_COUPLED));
14  fprintf(stdout, "Recv_two: Component ID: %d\n", comp_id);
15  fflush(stdout);
16
17  const int n_points = 1;
18  int part_params[OASIS_Serial_Params];
19  part_params[OASIS_Strategy] = OASIS_Serial;
20  part_params[OASIS_Length] = n_points;
21  int part_id;
22
23  OASIS_CHECK_ERR(oasis_c_def_partition(&part_id, OASIS_Serial_Params,
24                                        part_params, OASIS_No_Gsize,
25                                        OASIS_No_Name));
26  fprintf(stdout, "Recv_two: part_id: %d\n", part_id);
27  fflush(stdout);
28
29  char *var_name[2]  = {"FRECVICE_1","FRECVICE_2"};
30  int bundle_size = 1;
31  int var_id[2];
32
33  int i;
34  for (i = 0; i<2; i++) {
35    fprintf(stdout, "Recv_two: var_name %s\n", var_name[i]);
36    OASIS_CHECK_ERR(oasis_c_def_var(&var_id[i], var_name[i], part_id, bundle_size,
37                                    OASIS_IN, OASIS_REAL));
38    fprintf(stdout, "Recv_two: var_id %d\n", var_id[i]);
39    fflush(stdout);
40  }
41
42  OASIS_CHECK_ERR(oasis_c_enddef());
43
44  MPI_Comm inter_two;
45  int inter_size, inter_rank;
46  OASIS_CHECK_ERR(oasis_c_get_intercomm(&inter_two, "sender-serial"));
47  OASIS_CHECK_MPI_ERR(MPI_Comm_size(inter_two, &inter_size));
48  OASIS_CHECK_MPI_ERR(MPI_Comm_rank(inter_two, &inter_rank));
49  fprintf(stdout,"Recv_two inter_two: rank = %d of %d\n",inter_rank,inter_size);
50  fflush(stdout);
51
52  int ncpl;
53  OASIS_CHECK_ERR(oasis_c_get_ncpl(var_id[0], &ncpl));
54  int cpl_freqs_0[ncpl];
55  OASIS_CHECK_ERR(oasis_c_get_freqs(var_id[0], OASIS_IN, ncpl, cpl_freqs_0));
56
57  OASIS_CHECK_ERR(oasis_c_get_ncpl(var_id[1], &ncpl));
58  int cpl_freqs_1[ncpl];
59  OASIS_CHECK_ERR(oasis_c_get_freqs(var_id[1], OASIS_IN, ncpl, cpl_freqs_1));
60
61  float field[n_points];
62  bool do_send;
63  float epsilon = 1.e-8;
64  float error;
65  int kinfo;
66
67  int date;
68  for (date = 0; date < 43200; date++) {
69
70    do_send = 0;
71    for (i = 0; i < ncpl ; i++ ) do_send = do_send || (date % cpl_freqs_0[i]) == 0;
72    if ( do_send ) {
73      for (i = 0; i < n_points; i++ ) field[i] = 0.0;
74      OASIS_CHECK_ERR(oasis_c_get(var_id[0], date, n_points, 1, bundle_size,
75                                  OASIS_REAL, OASIS_COL_MAJOR, field, &kinfo));
76      error = 0.;
77      for (i = 0; i < n_points; i++ ) error += fabs(field[i] - (float) date);
78      if (error < epsilon) {
79        fprintf(stdout, "Recv_two: field 1 received successfully at time %d\n", date);
80      } else {
81        fprintf(stdout, "Warning: Recv_two at time %d got %.0f instead of %.0f\n",
82                date, field[0], (float) date);
83      }
84      fflush(stdout);
85    }
86
87    do_send = 0;
88    for (i = 0; i < ncpl ; i++ ) do_send = do_send || (date % cpl_freqs_1[i]) == 0;
89    if ( do_send ) {
90      for (i = 0; i < n_points; i++ ) field[i] = 0.0;
91      OASIS_CHECK_ERR(oasis_c_get(var_id[1], date, n_points, 1, bundle_size,
92                                  OASIS_REAL, OASIS_COL_MAJOR, field, &kinfo));
93      error = 0.;
94      for (i = 0; i < n_points; i++ ) error += fabs(field[i] + (float) date);
95      if (error < epsilon) {
96        fprintf(stdout, "Recv_two: field 2 received successfully at time %d\n", date);
97      } else {
98        fprintf(stdout, "Warning: Recv_two at time %d got %.0f instead of %.0f\n",
99                date, field[0], -1.0 * (float) date);
100      }
101      fflush(stdout);
102
103    }
104
105  }
106
107  OASIS_CHECK_ERR(oasis_c_terminate());
108
109}
Note: See TracBrowser for help on using the repository browser.