KMR
testcxx.cpp
1 /* testcxx.cpp (2014-02-04) */
2 
3 /* Check KMR with C++11 closures. NEEDS "-std=gnu++0x" for GCC. */
4 
5 #include <mpi.h>
6 #include <string>
7 #include <iostream>
8 #include <functional>
9 #include "kmr.h"
10 
11 using namespace std;
12 
13 int
14 main(int argc, char *argv[])
15 {
16  int cc;
17  int nprocs, rank, thlv;
18  /*MPI_Init(&argc, &argv);*/
19  MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &thlv);
20  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
21  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22 
23  kmr_init();
24 
25  MPI_Barrier(MPI_COMM_WORLD);
26  if (rank == 0) {printf("simple0...\n");}
27 
28  KMR *mr = kmr_create_context(MPI_COMM_WORLD, MPI_INFO_NULL, 0);
29  KMR_KVS *kvs0 = kmr_create_kvs(mr, KMR_KV_OPAQUE, KMR_KV_OPAQUE);
30 
31  //auto f = [] (int x, int y) -> int { int z = x + y; return z + x; };
32  //std::function<int (int, int)> x = f;
33 
34  cc = kmr_map_on_rank_zero(kvs0, 0, kmr_noopt, ([&] (const struct kmr_kv_box kv0,
35  const KMR_KVS *kvs0_, KMR_KVS *kvo,
36  void *p,
37  const long i) -> int
38  {
39  assert(kvs0_ == 0 && kv0.klen == 0 && kv0.vlen == 0 && kvo != 0);
40  struct kmr_kv_box kv[] = {
41  /* {.klen,.vlen,.k.p,.v.p} */
42  {5, 7, {"key0"}, {"value0"}},
43  {5, 7, {"key1"}, {"value1"}},
44  {5, 7, {"key2"}, {"value2"}},
45  {5, 7, {"key3"}, {"value3"}},
46  {5, 7, {"key4"}, {"value4"}}
47  };
48  for (int i = 0; i < 5; i++) {
49  int cc_ = kmr_add_kv(kvo, kv[i]);
50  assert(cc_ == MPI_SUCCESS);
51  }
52  return MPI_SUCCESS;
53  }));
54  assert(cc == MPI_SUCCESS);
55  kmr_dump_kvs(kvs0, 0);
56  kmr_free_kvs(kvs0);
57 
58  MPI_Barrier(MPI_COMM_WORLD);
59 
60  kmr_fin();
61 
62  MPI_Finalize();
63  return 0;
64 }
Key-Value Stream (abstract).
Definition: kmr.h:587
int kmr_add_kv(KMR_KVS *kvs, const struct kmr_kv_box kv)
Adds a key-value pair.
Definition: kmrbase.c:751
#define kmr_create_kvs(MR, KF, VF)
Makes a new key-value stream (of type KMR_KVS) with the specified field datatypes.
Definition: kmr.h:71
KMR Context.
Definition: kmr.h:222
int kmr_free_kvs(KMR_KVS *kvs)
Releases a key-value stream (type KMR_KVS).
Definition: kmrbase.c:621
Handy Copy of a Key-Value Field.
Definition: kmr.h:358
int kmr_dump_kvs(KMR_KVS *kvs, int flag)
Dumps contents of a key-value stream to stdout.
Definition: kmrutil.c:1609
int kmr_fin(void)
Clears the environment.
Definition: kmrbase.c:124
#define kmr_init()
Sets up the environment.
Definition: kmr.h:747
KMR Interface.
int kmr_map_on_rank_zero(KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps on rank0 only.
Definition: kmrbase.c:1456
KMR * kmr_create_context(const MPI_Comm comm, const MPI_Info conf, const char *name)
Makes a new KMR context (a context has type KMR).
Definition: kmrbase.c:147