source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/2-apple/C/sender-apple.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: 2.2 KB
Line 
1#include <stdio.h>
2#include "mpi.h"
3#include "oasis_c.h"
4
5int main(int argc, char *argv[])
6{
7  char *comp_name = "sender-apple";
8  fprintf(stdout,"Component name: %s\n", comp_name);
9  fflush(stdout);
10
11  OASIS_CHECK_MPI_ERR(MPI_Init(&argc, &argv));
12
13  MPI_Comm commworld;
14  OASIS_CHECK_MPI_ERR(MPI_Comm_split(MPI_COMM_WORLD, 1, 0, &commworld));
15
16  int comp_id;
17  OASIS_CHECK_ERR(oasis_c_init_comp_with_comm(&comp_id, comp_name, OASIS_COUPLED, commworld));
18  fprintf(stdout, "Sender: 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,"Sender: rank = %d of %d\n",comm_rank,comm_size);
28  fflush(stdout);
29
30  const int n_points = 16;
31  int local_size = n_points/comm_size;
32  int offset = comm_rank*local_size;
33  if ( comm_rank == comm_size - 1 ) {
34    local_size = n_points - offset;
35  }
36
37
38  int part_params[OASIS_Apple_Params];
39  part_params[OASIS_Strategy] = OASIS_Apple;
40  part_params[OASIS_Offset] = offset;
41  part_params[OASIS_Length] = local_size;
42  int part_id;
43
44  OASIS_CHECK_ERR(oasis_c_def_partition(&part_id, OASIS_Apple_Params,
45                                        part_params, OASIS_No_Gsize,
46                                        OASIS_No_Name));
47  fprintf(stdout, "Sender rank(%d): part_id: %d\n", comm_rank, part_id);
48  fflush(stdout);
49
50
51  char *var_name  = "FSENDOCN";
52  fprintf(stdout, "Sender rank(%d): var_name %s\n", comm_rank, var_name);
53  int bundle_size = 1;
54  int var_id;
55
56  OASIS_CHECK_ERR(oasis_c_def_var(&var_id, var_name, part_id, bundle_size, OASIS_OUT, OASIS_REAL));
57  fprintf(stdout, "Sender rank(%d): var_id %d\n", comm_rank, var_id);
58  fflush(stdout);
59
60  OASIS_CHECK_ERR(oasis_c_enddef());
61
62  float field[local_size];
63  int i;
64  for (i = 0; i<local_size; i++) {
65    field[i] = (float) offset+i;
66  }
67  int date = 0;
68
69  int kinfo;
70  OASIS_CHECK_ERR(oasis_c_put(var_id, date, local_size, 1, bundle_size, OASIS_REAL, OASIS_COL_MAJOR, field, OASIS_No_Restart, &kinfo));
71  fprintf(stdout, "Sender rank(%d): oasis_c_put returned kinfo = %d\n", comm_rank, kinfo);
72  fflush(stdout);
73
74  OASIS_CHECK_ERR(oasis_c_terminate());
75
76  OASIS_CHECK_MPI_ERR(MPI_Finalize());
77
78}
Note: See TracBrowser for help on using the repository browser.