KMR
kmrimpl.h
Go to the documentation of this file.
1 /* kmrimpl.h (2014-02-04) */
2 /* Copyright (C) 2012-2016 RIKEN AICS */
3 
4 #ifndef _KMRIMPL_H
5 #define _KMRIMPL_H
6 
7 /** \file kmrimpl.h Utilities Private Part (do not include from
8  applications). */
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <errno.h>
13 
14 #ifdef __cplusplus
15 #error "Do not include kmrimpl.h in C++"
16 #endif
17 
18 /* Suppress warnings/remarks of ICC. */
19 
20 #ifdef __INTEL_COMPILER
21 /* "remark #869: parameter "xxx" was never referenced" */
22 #pragma warning (disable : 869)
23 #endif
24 
25 /* Controls a code for debugging. Define it to generate an
26  expression for including debugging code. \hideinitializer */
27 
28 #ifdef DEBUG
29 #define KMR_DEBUGX(X) (X)
30 #else
31 #define KMR_DEBUGX(X) ((void)0)
32 #endif
33 
34 #define KMR_EMPTY
35 
36 /* Adds threading directives inside mapping and reduction. Be
37  carefull that semicolons are disallowed after these directives. */
38 
39 #ifdef _OPENMP
40 #define KMR_OMP_PARALLEL_ _Pragma("omp parallel")
41 #define KMR_PP_(X) _Pragma(#X)
42 #define KMR_OMP_PARALLEL_IF_(CC) KMR_PP_(omp parallel if (CC))
43 #define KMR_OMP_SINGLE_NOWAIT_ _Pragma("omp single nowait")
44 #define KMR_OMP_PARALLEL_FOR_ _Pragma("omp parallel for")
45 #define KMR_OMP_CRITICAL_ _Pragma("omp critical")
46 #define KMR_OMP_TASK_ _Pragma("omp task")
47 #define KMR_OMP_TASK_FINAL_(CC) KMR_PP_(omp task final (CC))
48 #define KMR_OMP_TASKWAIT_ _Pragma("omp taskwait")
49 #define KMR_OMP_FOR_ _Pragma("omp for")
50 #define KMR_OMP_GET_THREAD_NUM() omp_get_thread_num()
51 //#define KMR_OMP_SET_LOCK(X) omp_set_lock(X)
52 //#define KMR_OMP_UNSET_LOCK(X) omp_unset_lock(X)
53 //#define KMR_OMP_INIT_LOCK(X) omp_init_lock(X)
54 //#define KMR_OMP_DESTROY_LOCK(X) omp_destroy_lock(X)
55 #else
56 #define KMR_OMP_PARALLEL_ KMR_EMPTY
57 #define KMR_OMP_PARALLEL_IF_(CC) KMR_EMPTY
58 #define KMR_OMP_SINGLE_NOWAIT_ KMR_EMPTY
59 #define KMR_OMP_PARALLEL_FOR_ KMR_EMPTY
60 #define KMR_OMP_CRITICAL_ KMR_EMPTY
61 #define KMR_OMP_TASK_ KMR_EMPTY
62 #define KMR_OMP_TASK_FINAL_(CC) KMR_EMPTY
63 #define KMR_OMP_TASKWAIT_ KMR_EMPTY
64 #define KMR_OMP_FOR_ KMR_EMPTY
65 #define KMR_OMP_GET_THREAD_NUM() 0
66 //#define KMR_OMP_SET_LOCK(X) ((void)0)
67 //#define KMR_OMP_UNSET_LOCK(X) ((void)0)
68 //#define KMR_OMP_INIT_LOCK(X) ((void)0)
69 //#define KMR_OMP_DESTROY_LOCK(X) ((void)0)
70 #endif /*_OPENMP*/
71 
72 /** Rounds up a given size to the alignment restriction (currently
73  eight bytes). */
74 
75 #define KMR_ALIGN(X) (((X)+((8)-1))&~((8)-1))
76 
77 /* Maximun number of threads on a node. */
78 
79 #define KMR_MAX_THREADS 200
80 
81 /* MPI tags used in "kmratoa.c". */
82 
83 #define KMR_TAG_ATOA 100
84 
85 /* MPI tags for kmr_map_rank_by_rank(). */
86 
87 #define KMR_TAG_MAP_BY_RANK 200
88 
89 #define KMR_TAG_PUSHOFF 201
90 
91 /* MPI tags for kmr_map_ms(). KMR_TAG_PEER(THRD) chooses a tag
92  exclusively used by a thread. */
93 
94 #define KMR_TAG_REQ 399
95 #define KMR_TAG_PEER_0 400
96 #define KMR_TAG_PEER_END (KMR_TAG_PEER_0 + KMR_MAX_THREADS)
97 #define KMR_TAG_PEER(THRD) (KMR_TAG_PEER_0 + (THRD))
98 
99 /** Prefix to Trace Files. */
100 
101 #define KMR_TRACE_FILE_PREFIX "kmrlog"
102 
103 /* Asserts and aborts, but it cannot be disabled. The two message
104  styles are for Linux and Solaris. \hideinitializer */
105 
106 #ifndef __SVR4
107 #define xassert(X) \
108  ((X) \
109  ? (void)(0) \
110  : (fprintf(stderr, \
111  "%s:%d: %s: Assertion '%s' failed.\n", \
112  __FILE__, __LINE__, __func__, #X), \
113  (void)MPI_Abort(MPI_COMM_WORLD, 1)))
114 #else
115 #define xassert(X) \
116  ((X) \
117  ? (void)(0) \
118  : (fprintf(stderr, \
119  "Assertion failed: %s, file %s, line %d, function %s\n", \
120  #X, __FILE__, __LINE__, __func__), \
121  (void)MPI_Abort(MPI_COMM_WORLD, 1)))
122 #endif
123 
124 /** Positions of node by (X,Y,Z,ABC), with ABC axes collapsed. */
125 
126 typedef unsigned short kmr_k_position_t[4];
127 
128 extern double kmr_wtime(void);
129 
130 /** Returns the clock counter value. (See for well-written
131  information on tick counters: http://www.fftw.org/cycle.h).
132  "__thread" is only needed for an old compiler on K. */
133 
134 static inline long
136 {
137 #if (defined(__sparc_v9__) && defined(__arch64__))
138  /* SPARC V9 */
139  static __thread long r;
140  __asm__ __volatile__ ("rd %%tick, %0" : "=r" (r) : "0" (r));
141  return r;
142 #elif (defined(__x86_64__) && defined(__GNUC__) && !defined(__llvm__))
143  /* x86_64 (rdtsc/rdtscp) */
144  unsigned int ax, dx;
145  __asm__ __volatile__("rdtscp" : "=a" (ax), "=d" (dx));
146  return (((long)ax) | (((long)dx) << 32));
147 #else
148 #define KMR_TICK_ONLY_FOR_AMD64_AND_SPARC 0
149  /*assert(KMR_TICK_ONLY_FOR_AMD64_AND_SPARC);*/
150  return 0;
151 #endif
152 }
153 
154 /* Type of qsort comparator. */
155 
156 typedef int (*kmr_sorter_t)(const struct kmr_kv_box *p,
157  const struct kmr_kv_box *q);
158 typedef int (*kmr_record_sorter_t)(const struct kmr_keyed_record *p,
159  const struct kmr_keyed_record *q);
160 typedef int (*kmr_qsorter_t)(const void *p, const void *q);
161 
162 extern void kmr_warning(KMR *mr, unsigned int mask, char *m);
163 extern void kmr_error_at_site(KMR *mr, char *m, struct kmr_code_line *site);
164 extern void kmr_error(KMR *mr, char *m);
165 extern void kmr_error2(KMR *mr, char *m,
166  const char *file, const int line, const char *func);
167 extern void kmr_error_kvs_at_site(KMR *mr, char *m, KMR_KVS *kvs,
168  struct kmr_code_line *site);
169 extern void kmr_error_kvs(KMR *mr, char *m, KMR_KVS *kvs);
170 extern void kmr_error_kvs2(KMR *mr, char *m, KMR_KVS *kvs,
171  const char *file, const int line, const char *func);
172 extern void kmr_error_mpi(KMR *mr, char *m, int errorcode);
173 extern void kmr_string_truncation(KMR *mr, size_t sz, char *s);
174 
175 /** Allocates memory, or aborts when failed. */
176 
177 #define kmr_malloc(Z) kmr_safe_malloc((Z), #Z, __FILE__, __LINE__, __func__)
178 
179 /** Allocates memory, or aborts when failed. */
180 
181 #define kmr_realloc(P,Z) kmr_safe_realloc((P), (Z), #Z, __FILE__, __LINE__, __func__)
182 
183 static inline void *
184 kmr_safe_malloc(size_t s, char *szexpr,
185  const char *file, const int line, const char *func)
186 {
187  void *p = malloc(s);
188  if (p == 0) {
189  char ee[80];
190  char *m = strerror(errno);
191  snprintf(ee, 80, "malloc((%s)=%zd): %s", szexpr, s, m);
192  kmr_error2(0, ee, file, line, func);
193  }
194  return p;
195 }
196 
197 static inline void *
198 kmr_safe_realloc(void *q, size_t s, char *szexpr,
199  const char *file, const int line, const char *func)
200 {
201  void *p = realloc(q, s);
202  if (p == 0) {
203  char ee[80];
204  char *m = strerror(errno);
205  snprintf(ee, 80, "realloc((%s)=%zd): %s", szexpr, s, m);
206  kmr_error2(0, ee, file, line, func);
207  }
208  return p;
209 }
210 
211 static inline void
212 kmr_free(void *p, size_t sz)
213 {
214  KMR_DEBUGX(memset(p, 0, sz));
215  free(p);
216 }
217 
218 /* Checks if SZ is a multiple of the alignment restriction (currently
219  eight bytes). */
220 
221 static inline _Bool
222 kmr_check_alignment(size_t sz)
223 {
224  return ((sz & ((8)-1)) == 0);
225 }
226 
227 /* Checks if a field (key or value) is of unit-sized. */
228 
229 static inline _Bool
230 kmr_unit_sized_p(enum kmr_kv_field data)
231 {
232  switch (data) {
233  case KMR_KV_BAD:
234  assert(data != KMR_KV_BAD);
235  return 0;
236  case KMR_KV_OPAQUE:
237  case KMR_KV_CSTRING:
238  return 0;
239  case KMR_KV_INTEGER:
240  case KMR_KV_FLOAT8:
241  case KMR_KV_POINTER_OWNED:
242  case KMR_KV_POINTER_UNMANAGED:
243  return 1;
244  default:
245  xassert(0);
246  return 0;
247  }
248 }
249 
250 /* Returns the size of the entry occupying in the storage. It handles
251  the case storing pointers. Use kmr_kvs_entry_netsize() for the
252  size of the entry stored in-line. See
253  kmr_kvs_entry_size_of_box(). */
254 
255 static inline size_t
256 kmr_kvs_entry_size(KMR_KVS *kvs, const struct kmr_kvs_entry *e)
257 {
258  enum kmr_kv_field keyf = kvs->c.key_data;
259  enum kmr_kv_field valf = kvs->c.value_data;
260  size_t ksz;
261  if (kmr_unit_sized_p(keyf)) {
262  ksz = sizeof(union kmr_unit_sized);
263  } else {
264  ksz = (size_t)KMR_ALIGN(e->klen);
265  }
266  size_t vsz;
267  if (kmr_unit_sized_p(valf)) {
268  vsz = sizeof(union kmr_unit_sized);
269  } else {
270  vsz = (size_t)KMR_ALIGN(e->vlen);
271  }
272  return (kmr_kvs_entry_header + ksz + vsz);
273 }
274 
275 static inline size_t
276 kmr_kvs_entry_size_of_box(KMR_KVS *kvs, const struct kmr_kv_box kv)
277 {
278  enum kmr_kv_field keyf = kvs->c.key_data;
279  enum kmr_kv_field valf = kvs->c.value_data;
280  size_t ksz;
281  if (kmr_unit_sized_p(keyf)) {
282  ksz = sizeof(union kmr_unit_sized);
283  } else {
284  ksz = (size_t)KMR_ALIGN(kv.klen);
285  }
286  size_t vsz;
287  if (kmr_unit_sized_p(valf)) {
288  vsz = sizeof(union kmr_unit_sized);
289  } else {
290  vsz = (size_t)KMR_ALIGN(kv.vlen);
291  }
292  return (kmr_kvs_entry_header + ksz + vsz);
293 }
294 
295 /* Returns the size of the entry. It is the size for opaque fields,
296  but not for pointer fields. Use kmr_kvs_entry_size() for the
297  occupying size of the pointer fields. See
298  kmr_kvs_entry_netsize_of_box(). */
299 
300 static inline size_t
301 kmr_kvs_entry_netsize(const struct kmr_kvs_entry *e)
302 {
303  return (kmr_kvs_entry_header
304  + (size_t)KMR_ALIGN(e->klen) + (size_t)KMR_ALIGN(e->vlen));
305 }
306 
307 static inline size_t
308 kmr_kvs_entry_netsize_of_box(const struct kmr_kv_box kv)
309 {
310  return (kmr_kvs_entry_header
311  + (size_t)KMR_ALIGN(kv.klen) + (size_t)KMR_ALIGN(kv.vlen));
312 }
313 
314 /* Moves a pointer to the next entry, not moving over to the next
315  block. */
316 
317 static inline struct kmr_kvs_entry *
318 kmr_kvs_next_entry(KMR_KVS *kvs, const struct kmr_kvs_entry *e)
319 {
320  enum kmr_kv_field keyf = kvs->c.key_data;
321  enum kmr_kv_field valf = kvs->c.value_data;
322  size_t ksz;
323  if (kmr_unit_sized_p(keyf)) {
324  ksz = sizeof(union kmr_unit_sized);
325  } else {
326  ksz = (size_t)KMR_ALIGN(e->klen);
327  }
328  size_t vsz;
329  if (kmr_unit_sized_p(valf)) {
330  vsz = sizeof(union kmr_unit_sized);
331  } else {
332  vsz = (size_t)KMR_ALIGN(e->vlen);
333  }
334  return (void *)&(e->c[(ksz + vsz)]);
335 }
336 
337 /* Puts an end-of-block marker. A marker is placed in a data block
338  when it becomes full or closed (stowed) by kmr_add_kv_done(). */
339 
340 static inline void
341 kmr_kvs_mark_entry_tail(struct kmr_kvs_entry *e)
342 {
343  assert((((intptr_t)e) & 3) == 0);
344  e->klen = -1, e->vlen = -1;
345 }
346 
347 /* Checks if the entry is an end-of-block. */
348 
349 static inline _Bool
350 kmr_kvs_entry_tail_p(struct kmr_kvs_entry *e)
351 {
352  assert(e != 0);
353  return (e->klen == -1 && e->vlen == -1);
354 }
355 
356 /* Returns the first block. */
357 
358 static inline struct kmr_kvs_block *
359 kmr_kvs_first_block(KMR_KVS *kvs)
360 {
361  xassert(kvs->c.current_block == 0);
362  struct kmr_kvs_block *b = kvs->c.first_block;
363  kvs->c.current_block = b;
364  return b;
365 }
366 
367 /* Returns the first entry in the block. It returns null when the
368  given block is null (for the empty case). Note normally the
369  CURRENT_BLOCK be the same as the given block B in case enumerating
370  all the key-value pairs. */
371 
372 static inline struct kmr_kvs_entry *
373 kmr_kvs_first_entry(KMR_KVS *kvs, const struct kmr_kvs_block *b)
374 {
375  if (b == 0) {
376  return 0;
377  } else {
378  return (void *)&(b->data[0]);
379  }
380 }
381 
382 /* Returns the upper bound of the last entry in a block. The last
383  entry never exceeds this point. It keeps one space for an
384  end-of-block marker. */
385 
386 static inline struct kmr_kvs_entry *
387 kmr_kvs_last_entry_limit(const KMR_KVS *kvs, const struct kmr_kvs_block *b)
388 {
389  assert(b != 0);
390  size_t sz = (b->size - kmr_kvs_entry_header);
391  return (void *)((char *)b + sz);
392 }
393 
394 /* Returns a current insertion point in a block. */
395 
396 static inline struct kmr_kvs_entry *
397 kmr_kvs_adding_point(struct kmr_kvs_block *b)
398 {
399  struct kmr_kvs_entry *e = (void *)((char *)&b->data[0] + b->fill_size);
400  return e;
401 }
402 
403 /* Checks if a new key-value entry of a size SZ fits in a block B. It
404  keeps the space for an end-of-block marker. SZ is the space for an
405  entry (including length fields). */
406 
407 static inline _Bool
408 kmr_kvs_entry_fits_in_block(KMR_KVS *kvs, struct kmr_kvs_block *b, size_t sz)
409 {
410  struct kmr_kvs_entry *e = kmr_kvs_adding_point(b);
411  struct kmr_kvs_entry *p = (void *)((char *)e + sz);
412  struct kmr_kvs_entry *limit = kmr_kvs_last_entry_limit(kvs, b);
413  assert(&b->data[0] <= e && e <= limit);
414  return (p <= limit);
415 }
416 
417 /* Returns an entry at a given BYTES offset in the block (not count
418  header bytes). */
419 
420 static inline struct kmr_kvs_entry *
421 kmr_kvs_entry_at(KMR_KVS *kvs, const struct kmr_kvs_block *b, size_t bytes)
422 {
423  assert(b != 0);
424  return (void *)((char *)&(b->data[0]) + bytes);
425 }
426 
427 /* Moves a pointer to the next entry. It returns 0 at the end of the
428  entries. When BOUND_IN_BLOCK is true, it does not go to the next
429  block, otherwise it does. */
430 
431 static inline struct kmr_kvs_entry *
432 kmr_kvs_next(KMR_KVS *kvs, const struct kmr_kvs_entry *e, _Bool bound_in_block)
433 {
434  assert(kvs != 0 && e != 0 && kvs->c.current_block != 0);
435  struct kmr_kvs_block *b = kvs->c.current_block;
436  struct kmr_kvs_entry *p = kmr_kvs_next_entry(kvs, e);
437  assert(p <= kmr_kvs_last_entry_limit(kvs, b));
438  if (!kmr_kvs_entry_tail_p(p)) {
439  return p;
440  } else {
441  if (bound_in_block) {
442  return 0;
443  } else {
444  //struct kmr_kvs_block *previousblock = b;
445  b = b->next;
446  if (b != 0) {
447  kvs->c.current_block = b;
448  struct kmr_kvs_entry *q = kmr_kvs_first_entry(kvs, b);
449  //kvs->c.adding_point = q;
450  return q;
451  } else {
452  //kvs->c.current_block = 0;
453  //kvs->c.adding_point = p;
454  return 0;
455  }
456  }
457  }
458 }
459 
460 static inline void
461 kmr_kvs_reset_block(KMR_KVS *kvs, struct kmr_kvs_block *b,
462  size_t size, size_t netsize)
463 {
464  KMR_DEBUGX(memset(b, 0, size));
465  b->next = 0;
466  b->size = size;
467  b->partial_element_count = 0;
468  b->fill_size = 0;
469  struct kmr_kvs_entry *e = kmr_kvs_entry_at(kvs, b, netsize);
470  kmr_kvs_mark_entry_tail(e);
471 }
472 
473 /* Inserts a new storage block into a KVS. */
474 
475 static inline void
476 kmr_kvs_insert_block(KMR_KVS *kvs, struct kmr_kvs_block *b)
477 {
478  assert(kvs->c.magic == KMR_KVS_ONCORE);
479  if (kvs->c.first_block == 0) {
480  assert(kvs->c.current_block == 0 && kvs->c.block_count == 0);
481  kvs->c.first_block = b;
482  } else {
483  assert(kvs->c.current_block != 0 && kvs->c.block_count != 0);
484  kvs->c.current_block->next = b;
485  }
486  kvs->c.block_count++;
487  kvs->c.current_block = b;
488  kvs->c.adding_point = kmr_kvs_first_entry(kvs, b);
489  assert(kvs->c.current_block != 0 && kvs->c.adding_point != 0);
490 }
491 
492 /* Returns an occupying size of a key field. */
493 
494 static inline size_t
495 kmr_kv_key_size(const KMR_KVS *kvs, const struct kmr_kv_box kv)
496 {
497  return (size_t)KMR_ALIGN(kv.klen);
498 }
499 
500 /* Returns an occupying size of a value field. */
501 
502 static inline size_t
503 kmr_kv_value_size(const KMR_KVS *kvs, const struct kmr_kv_box kv)
504 {
505  return (size_t)KMR_ALIGN(kv.vlen);
506 }
507 
508 /* Returns a pointer pointing to a key in the entry. */
509 
510 static inline union kmr_unit_sized *
511 kmr_point_key(const struct kmr_kvs_entry *e)
512 {
513  return (void *)&(e->c[0]);
514 }
515 
516 /* Returns a pointer pointing to a value in the entry. */
517 
518 static inline union kmr_unit_sized *
519 kmr_point_value(const struct kmr_kvs_entry *e)
520 {
521  return (void *)&(e->c[KMR_ALIGN(e->klen)]);
522 }
523 
524 static inline struct kmr_kv_box
525 kmr_pick_kv2(struct kmr_kvs_entry *e,
526  enum kmr_kv_field keyf, enum kmr_kv_field valf)
527 {
528  struct kmr_kv_box kv;
529  kv.klen = e->klen;
530  kv.vlen = e->vlen;
531  union kmr_unit_sized *kp = kmr_point_key(e);
532  union kmr_unit_sized *vp = kmr_point_value(e);
533  if (kmr_unit_sized_p(keyf)) {
534  kv.k = *kp;
535  } else {
536  kv.k.p = (void *)kp;
537  }
538  if (kmr_unit_sized_p(valf)) {
539  kv.v = *vp;
540  } else {
541  kv.v.p = (void *)vp;
542  }
543  return kv;
544 }
545 
546 /** Returns a handle to a key-value entry -- a reverse of
547  kmr_poke_kv(). An entry does not know its data-types but they are
548  taken from a key-value stream KVS. */
549 
550 static inline struct kmr_kv_box
551 kmr_pick_kv(struct kmr_kvs_entry *e, KMR_KVS *kvs)
552 {
553  struct kmr_kv_box kv = kmr_pick_kv2(e, kvs->c.key_data,
554  kvs->c.value_data);
555  return kv;
556 }
557 
558 static inline void
559 kmr_poke_kv2(struct kmr_kvs_entry *e, const struct kmr_kv_box kv,
560  struct kmr_kv_box *xkv,
561  enum kmr_kv_field keyf, enum kmr_kv_field valf,
562  _Bool reserve_space_only)
563 {
564  e->klen = kv.klen;
565  e->vlen = kv.vlen;
566  union kmr_unit_sized *kp = kmr_point_key(e);
567  union kmr_unit_sized *vp = kmr_point_value(e);
568  if (kmr_unit_sized_p(keyf)) {
569  *kp = kv.k;
570  } else {
571  if (!reserve_space_only) {
572  memcpy(kp, kv.k.p, (size_t)kv.klen);
573  }
574  if (xkv != 0) {
575  xkv->k.p = (const char *)kp;
576  }
577  }
578  if (kmr_unit_sized_p(valf)) {
579  *vp = kv.v;
580  } else {
581  if (!reserve_space_only) {
582  memcpy(vp, kv.v.p, (size_t)kv.vlen);
583  }
584  if (xkv != 0) {
585  xkv->v.p = (const char *)vp;
586  }
587  }
588  return;
589 }
590 
591 /** Stores a key-value pair at the entry E in the store -- a reverse
592  of kmr_pick_kv(). A key-value pair does not know its data-types
593  but they are taken from a key-value stream. It modifies
594  kmr_kv_box XKV (when non-null) to return the pointer to the opaque
595  field when a key or a value is opaque. It does not move actual
596  data when RESERVE_SPACE_ONLY=1. */
597 
598 static inline void
599 kmr_poke_kv(struct kmr_kvs_entry *e, const struct kmr_kv_box kv,
600  struct kmr_kv_box *xkv, const KMR_KVS *kvs,
601  _Bool reserve_space_only)
602 {
603  kmr_poke_kv2(e, kv, xkv, kvs->c.key_data, kvs->c.value_data,
604  reserve_space_only);
605 }
606 
607 /* Checks if an input key-value stream is a proper one. See
608  kmr_assert_kvs_ok2(). */
609 
610 static inline void
611 kmr_assert_i_kvs_ok_at_site(KMR_KVS *kvi, _Bool irequired,
612  struct kmr_code_line *site)
613 {
614  if (irequired && kvi == 0) {
615  kmr_error_at_site(0, "Null input kvs", site);
616  } else if (kvi != 0 && !KMR_KVS_MAGIC_OK(kvi->c.magic)) {
617  kmr_error_at_site(0, "Bad input kvs (freed or corrupted)", site);
618  } else if (kvi != 0 && !kvi->c.stowed) {
619  KMR *mr = kvi->c.mr;
620  kmr_error_kvs_at_site(mr, "kmr_add_kv_done not called for input kvs",
621  kvi, site);
622  }
623 }
624 
625 static inline void
626 kmr_assert_i_kvs_ok(KMR_KVS *kvi, _Bool irequired)
627 {
628  kmr_assert_i_kvs_ok_at_site(kvi, irequired, 0);
629 }
630 
631 /* Checks if an output key-value stream is a proper one. See
632  kmr_assert_kvs_ok2(). */
633 
634 static inline void
635 kmr_assert_o_kvs_ok_at_site(KMR_KVS *kvo, _Bool orequired,
636  struct kmr_code_line *site)
637 {
638  if (orequired && kvo == 0) {
639  kmr_error_at_site(0, "Null output kvs", site);
640  } else if (kvo != 0 && !KMR_KVS_MAGIC_OK(kvo->c.magic)) {
641  kmr_error_at_site(0, "Bad output kvs (freed or corrupted)", site);
642  } else if (kvo != 0 && kvo->c.stowed) {
643  KMR *mr = kvo->c.mr;
644  kmr_error_kvs_at_site(mr,
645  "kmr_add_kv_done already called for output kvs",
646  kvo, site);
647  }
648 }
649 
650 static inline void
651 kmr_assert_o_kvs_ok(KMR_KVS *kvo, _Bool orequired)
652 {
653  kmr_assert_o_kvs_ok_at_site(kvo, orequired, 0);
654 }
655 
656 /* Checks if input/output key-value streams are proper ones. An input
657  stream is required as stowed, and an output stream is not. It
658  accepts null unless IREQUIRED/OREQUIRED is specified. */
659 
660 static inline void
661 kmr_assert_kvs_ok(KMR_KVS *kvi, KMR_KVS *kvo,
662  _Bool irequired, _Bool orequired)
663 {
664  kmr_assert_i_kvs_ok_at_site(kvi, irequired, 0);
665  kmr_assert_o_kvs_ok_at_site(kvo, orequired, 0);
666 }
667 
668 /* Checks if a key field is a pointer. */
669 
670 static inline _Bool
671 kmr_key_pointer_p(KMR_KVS *kvs)
672 {
673  switch (kvs->c.key_data) {
674  case KMR_KV_BAD:
675  xassert(kvs->c.key_data != KMR_KV_BAD);
676  return 0;
677  case KMR_KV_OPAQUE:
678  case KMR_KV_CSTRING:
679  case KMR_KV_INTEGER:
680  case KMR_KV_FLOAT8:
681  return 0;
682  case KMR_KV_POINTER_OWNED:
683  case KMR_KV_POINTER_UNMANAGED:
684  return 1;
685  default:
686  xassert(0);
687  return 0;
688  }
689 }
690 
691 /* Checks if a value field is a pointer. */
692 
693 static inline _Bool
694 kmr_value_pointer_p(KMR_KVS *kvs)
695 {
696  switch (kvs->c.value_data) {
697  case KMR_KV_BAD:
698  xassert(kvs->c.value_data != KMR_KV_BAD);
699  return 0;
700  case KMR_KV_OPAQUE:
701  case KMR_KV_CSTRING:
702  case KMR_KV_INTEGER:
703  case KMR_KV_FLOAT8:
704  return 0;
705  case KMR_KV_POINTER_OWNED:
706  case KMR_KV_POINTER_UNMANAGED:
707  return 1;
708  default:
709  xassert(0);
710  return 0;
711  }
712 }
713 
714 /* Checks if key or value field is a pointer. When it is, fields need
715  to be packed to make data-exchanges easy. */
716 
717 static inline _Bool
718 kmr_fields_pointer_p(KMR_KVS *kvs)
719 {
720  return (kmr_key_pointer_p(kvs) || kmr_value_pointer_p(kvs));
721 }
722 
723 /* Checks a constraint on the sizes of a key and a value. */
724 
725 static inline void
726 kmr_assert_kv_sizes(KMR_KVS *kvs, const struct kmr_kv_box kv)
727 {
728  KMR *mr = kvs->c.mr;
729  switch (kvs->c.key_data) {
730  case KMR_KV_BAD:
731  assert(kvs->c.key_data != KMR_KV_BAD);
732  break;
733  case KMR_KV_INTEGER:
734  if ((size_t)kv.klen != sizeof(long)) {
735  kmr_error(mr, "Bad kv klen");
736  }
737  break;
738  case KMR_KV_FLOAT8:
739  if ((size_t)kv.klen != sizeof(double)) {
740  kmr_error(mr, "Bad kv klen");
741  }
742  break;
743  case KMR_KV_OPAQUE:
744  case KMR_KV_CSTRING:
745  case KMR_KV_POINTER_OWNED:
746  case KMR_KV_POINTER_UNMANAGED:
747  break;
748  default:
749  xassert(0);
750  break;
751  }
752  switch (kvs->c.value_data) {
753  case KMR_KV_BAD:
754  assert(kvs->c.value_data != KMR_KV_BAD);
755  break;
756  case KMR_KV_INTEGER:
757  if ((size_t)kv.vlen != sizeof(long)) {
758  kmr_error(mr, "Bad kv vlen");
759  }
760  break;
761  case KMR_KV_FLOAT8:
762  if ((size_t)kv.vlen != sizeof(double)) {
763  kmr_error(mr, "Bad kv vlen");
764  }
765  break;
766  case KMR_KV_OPAQUE:
767  case KMR_KV_CSTRING:
768  case KMR_KV_POINTER_OWNED:
769  case KMR_KV_POINTER_UNMANAGED:
770  break;
771  default:
772  xassert(0);
773  break;
774  }
775 }
776 
777 /* Regards pointers as opaque ones. It returns the field data for
778  communication, so that pointers should be converted to opaque
779  ones. */
780 
781 static inline enum kmr_kv_field
782 kmr_unit_sized_or_opaque(enum kmr_kv_field data)
783 {
784  switch (data) {
785  case KMR_KV_BAD:
786  xassert(data != KMR_KV_BAD);
787  return KMR_KV_BAD;
788  case KMR_KV_OPAQUE:
789  case KMR_KV_CSTRING:
790  case KMR_KV_INTEGER:
791  case KMR_KV_FLOAT8:
792  return data;
793  case KMR_KV_POINTER_OWNED:
794  case KMR_KV_POINTER_UNMANAGED:
795  return KMR_KV_OPAQUE;
796  default:
797  xassert(0);
798  return KMR_KV_BAD;
799  }
800 }
801 
802 /* Regards opaque data as unmanaged pointers. It returns temporarily
803  a pointer, to avoid copying opaque data . */
804 
805 static inline enum kmr_kv_field
806 kmr_unit_sized_with_unmanaged(enum kmr_kv_field data)
807 {
808  switch (data) {
809  case KMR_KV_BAD:
810  xassert(data != KMR_KV_BAD);
811  return KMR_KV_BAD;
812  case KMR_KV_INTEGER:
813  case KMR_KV_FLOAT8:
814  return data;
815  case KMR_KV_OPAQUE:
816  case KMR_KV_CSTRING:
817  case KMR_KV_POINTER_OWNED:
818  case KMR_KV_POINTER_UNMANAGED:
819  return KMR_KV_POINTER_UNMANAGED;
820  default:
821  xassert(0);
822  return KMR_KV_BAD;
823  }
824 }
825 
826 static inline _Bool
827 kmr_shuffle_compatible_data_p(enum kmr_kv_field d0, enum kmr_kv_field d1)
828 {
829  return (kmr_unit_sized_or_opaque(d0) == kmr_unit_sized_or_opaque(d1));
830 }
831 
832 /* Checks if fields are compatible for communication. */
833 
834 static inline _Bool
835 kmr_shuffle_compatible_p(KMR_KVS *s0, KMR_KVS *s1)
836 {
837  return (kmr_shuffle_compatible_data_p(s0->c.key_data, s1->c.key_data)
838  && kmr_shuffle_compatible_data_p(s0->c.key_data, s1->c.key_data));
839 }
840 
841 /* Links a key-value stream to a list on a context. */
842 
843 static inline void
844 kmr_link_kvs(KMR_KVS *kvs)
845 {
846  KMR *mr = kvs->c.mr;
847  assert(mr != 0);
848  if (mr->kvses.tail == 0) {
849  assert(mr->kvses.head == 0);
850  mr->kvses.head = kvs;
851  mr->kvses.tail = kvs;
852  kvs->c.link.next = 0;
853  kvs->c.link.prev = 0;
854  } else {
855  KMR_KVS *tail = mr->kvses.tail;
856  assert(tail->c.link.next == 0);
857  tail->c.link.next = kvs;
858  mr->kvses.tail = kvs;
859  kvs->c.link.next = 0;
860  kvs->c.link.prev = tail;
861  }
862 }
863 
864 /* Copies options of the input and threading part. */
865 
866 static inline struct kmr_option
867 kmr_copy_options_i_part(struct kmr_option opt)
868 {
869  struct kmr_option xopt = {.inspect = opt.inspect,
870  .nothreading = opt.nothreading,
871  .take_ckpt = opt.take_ckpt};
872  return xopt;
873 }
874 
875 /* Copies options of the output and threading part. */
876 
877 static inline struct kmr_option
878 kmr_copy_options_o_part(struct kmr_option opt)
879 {
880  struct kmr_option xopt = {.keep_open = opt.keep_open,
881  .nothreading = opt.nothreading,
882  .take_ckpt = opt.take_ckpt};
883  return xopt;
884 }
885 
886 /* Copies options of the threading part. */
887 
888 static inline struct kmr_option
889 kmr_copy_options_m_part(struct kmr_option opt)
890 {
891  struct kmr_option xopt = {.nothreading = opt.nothreading,
892  .take_ckpt = opt.take_ckpt};
893  return xopt;
894 }
895 
896 /* Copies options for the kmr_shuffle()/kmr_replicate() part. */
897 
898 static inline struct kmr_option
899 kmr_copy_s_option(struct kmr_option opt)
900 {
901  struct kmr_option xopt = {.key_as_rank = opt.key_as_rank,
902  .rank_zero = opt.rank_zero,
903  .take_ckpt = opt.take_ckpt};
904  return xopt;
905 }
906 
907 /* Returns a start of data portion of an n-tuple of size N. */
908 
909 static inline size_t
910 kmr_ntuple_data_offset(int n)
911 {
912  size_t sz = sizeof(((struct kmr_ntuple *)0)->len[0]);
913  size_t off = (size_t)KMR_ALIGN((int)sz * n);
914  return (offsetof(struct kmr_ntuple, len) + off);
915 }
916 
917 /* Returns a rounded up size of a length LEN. */
918 
919 static inline int
920 kmr_ntuple_entry_size(int len)
921 {
922  return KMR_ALIGN(len);
923 }
924 
925 /* Returns an offset to the NTH position in an n-tuple. */
926 
927 static inline size_t
928 kmr_ntuple_nth_offset(struct kmr_ntuple *u, int nth)
929 {
930  size_t off;
931  off = kmr_ntuple_data_offset(u->n);
932  for (int i = 0; i < nth; i++) {
933  off += (size_t)kmr_ntuple_entry_size(u->len[i]);
934  }
935  return off;
936 }
937 
938 /* Returns a current insertion point. */
939 
940 static inline void *
941 kmr_ntuple_insertion_point(struct kmr_ntuple *u)
942 {
943  assert(u->index < u->n);
944  char *p = (void *)u;
945  size_t off = kmr_ntuple_nth_offset(u, u->index);
946  return (void *)(p + off);
947 }
948 
949 #define CHECK_ONE_FN_OPTION(NAME, A, B) \
950  if (A . NAME < B . NAME) { \
951  char ee[80]; \
952  snprintf(ee, sizeof(ee), \
953  "%s() does not support '" # NAME "' option", func); \
954  kmr_error(mr, ee); \
955  }
956 
957 /* Check options given to a kmr function */
958 
959 static inline void
960 kmr_check_fn_options(KMR *mr, struct kmr_option provide,
961  struct kmr_option given, const char *func)
962 {
963  CHECK_ONE_FN_OPTION(nothreading, provide, given);
964  CHECK_ONE_FN_OPTION(inspect, provide, given);
965  CHECK_ONE_FN_OPTION(keep_open, provide, given);
966  CHECK_ONE_FN_OPTION(key_as_rank, provide, given);
967  CHECK_ONE_FN_OPTION(rank_zero, provide, given);
968  CHECK_ONE_FN_OPTION(collapse, provide, given);
969  CHECK_ONE_FN_OPTION(take_ckpt, provide, given);
970 }
971 
972 extern int kmr_kv_field_bad;
973 extern int kmr_kv_field_opaque;
974 extern int kmr_kv_field_cstring;
975 extern int kmr_kv_field_integer;
976 extern int kmr_kv_field_float8;
977 extern int kmr_kv_field_pointer_owned;
978 extern int kmr_kv_field_pointer_unmanaged;
979 
980 extern int kmr_k_node(KMR *mr, kmr_k_position_t p);
981 
982 extern char *kmr_strptr_ff(char *s);
983 extern char *kmr_ptrstr_ff(char *s);
984 extern long kmr_ptrint_ff(void *p);
985 extern void * kmr_intptr_ff(long p);
986 extern long kmr_dblint_ff(double v);
987 extern double kmr_intdbl_ff(long v);
988 extern long kmr_strint_ff(char *p);
989 extern int kmr_intstr_ff(long p, char *s, int n);
990 
991 extern unsigned long kmr_fix_bits_endian_ff(unsigned long b);
992 
993 extern int kmr_get_nprocs(const KMR *mr);
994 extern int kmr_get_rank(const KMR *mr);
995 extern int kmr_get_nprocs_ff(const KMR_KVS *kvs);
996 extern int kmr_get_rank_ff(const KMR_KVS *kvs);
997 extern int kmr_get_key_type_ff(const KMR_KVS *kvs);
998 extern int kmr_get_value_type_ff(const KMR_KVS *kvs);
999 
1000 extern int kmr_init_ff(int kf, struct kmr_option opt,
1001  struct kmr_file_option fopt);
1002 extern KMR *kmr_create_context_ff(const int fcomm, const int finfo,
1003  const char *name);
1004 extern int kmr_map_via_spawn_ff(KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
1005  int finfo, struct kmr_spawn_option opt,
1006  kmr_mapfn_t m);
1007 extern int kmr_get_spawner_communicator_ff(KMR *mr, long i, int *comm);
1008 
1009 extern void kmr_init_kvs_oncore(KMR_KVS *kvs, KMR *mr);
1010 extern int kmr_free_kvs_pushoff(KMR_KVS *kvs, _Bool deallocate);
1011 extern int kmr_add_kv_pushoff(KMR_KVS *kvs, const struct kmr_kv_box kv);
1012 extern int kmr_add_kv_done_pushoff(KMR_KVS *kvs);
1013 extern int kmr_pushoff_make_stationary(KMR_KVS *kvs);
1014 
1015 extern int kmr_load_properties(MPI_Info conf, char *filename);
1016 extern int kmr_copy_mpi_info(MPI_Info src, MPI_Info dst);
1017 extern int kmr_dump_mpi_info(char *prefix, MPI_Info info);
1018 extern int kmr_parse_int(char *s, int *r);
1019 extern int kmr_parse_boolean(char *s, int *r);
1020 
1021 extern int kmr_scan_argv_strings(KMR *mr, char *s, size_t len, int arglim,
1022  int *argc, char **argv,
1023  _Bool wssep, char *msg);
1024 
1025 extern int kmr_allocate_block(KMR_KVS *kvs, size_t size);
1026 
1027 extern void kmr_isort(void *a, size_t n, size_t es, int depth);
1028 extern void *kmr_bsearch(const void *key, const void *base,
1029  size_t nel, size_t size,
1030  int (*compar)(const void *, const void *));
1031 
1032 extern int kmr_reverse_fn(const struct kmr_kv_box kv,
1033  const KMR_KVS *kvs, KMR_KVS *kvo, void *p,
1034  const long i);
1035 extern int kmr_pairing_fn(const struct kmr_kv_box kv,
1036  const KMR_KVS *kvi, KMR_KVS *kvo, void *p,
1037  const long i);
1038 extern int kmr_unpairing_fn(const struct kmr_kv_box kv,
1039  const KMR_KVS *kvs, KMR_KVS *kvo, void *p,
1040  const long i);
1041 extern int kmr_imax_one_fn(const struct kmr_kv_box kv[], const long n,
1042  const KMR_KVS *kvi, KMR_KVS *kvo, void *p);
1043 extern int kmr_isum_one_fn(const struct kmr_kv_box kv[], const long n,
1044  const KMR_KVS *kvi, KMR_KVS *kvo, void *p);
1045 
1046 extern kmr_sorter_t kmr_choose_sorter(const KMR_KVS *kvs);
1047 extern signed long kmr_stable_key(const struct kmr_kv_box kv,
1048  const KMR_KVS *kvs);
1049 extern int kmr_pitch_rank(const struct kmr_kv_box kv, KMR_KVS *kvs);
1050 extern int kmr_assert_sorted(KMR_KVS *kvi, _Bool locally,
1051  _Bool shuffling, _Bool ranking);
1052 extern struct kmr_kvs_entry *kmr_find_kvs_last_entry(KMR_KVS *kvs);
1053 
1054 extern int kmr_exchange_sizes(KMR *mr, long *sbuf, long *rbuf);
1055 extern int kmr_alltoallv(KMR *mr,
1056  void *sbuf, long *scounts, long *sdsps,
1057  void *rbuf, long *rcounts, long *rdsps);
1058 extern int kmr_gather_sizes(KMR *mr, long siz, long *rbuf);
1059 extern int kmr_allgatherv(KMR *mr, _Bool rankzeroonly,
1060  void *sbuf, long scnt,
1061  void *rbuf, long *rcnts, long *rdsps);
1062 
1063 extern int kmr_iogroup_distance(int a0, int a1);
1064 extern int kmr_iogroup_of_node(KMR *mr);
1065 extern int kmr_iogroup_of_obd(int obdidx);
1066 
1067 extern void *kmr_strdup(char *s);
1068 extern FILE *kmr_fopen(const char *n, const char *m);
1069 extern int kmr_fgetc(FILE *f);
1070 extern int kmr_getdtablesize(KMR *mr);
1071 
1072 extern int kmr_msleep(int msec, int interval);
1073 extern void kmr_mfree(void *p, size_t sz);
1074 extern size_t kmr_mpi_type_size(char *s);
1075 extern uint64_t kmr_mpi_constant_value(char *s);
1076 
1077 extern int kmr_install_watch_program(KMR *mr, char *msg);
1078 
1079 extern int kmr_check_options(KMR *mr, MPI_Info conf);
1080 extern int kmr_load_preference(KMR *mr, MPI_Info info);
1081 extern int kmr_set_option_by_strings(KMR *mr, char *k, char *v);
1082 extern char *kmr_stringify_options(struct kmr_option o);
1083 extern char *kmr_stringify_file_options(struct kmr_file_option o);
1084 extern char *kmr_stringify_spawn_options(struct kmr_spawn_option o);
1085 extern void kmr_print_options(struct kmr_option opt);
1086 extern void kmr_print_file_options(struct kmr_file_option opt);
1087 extern void kmr_print_spawn_options(struct kmr_spawn_option opt);
1088 extern void kmr_print_string(char *msg, char *s, int len);
1089 
1090 extern void kmr_open_log(KMR *mr);
1091 extern void kmr_log_map(KMR *mr, KMR_KVS *kvs, struct kmr_kv_box *ev,
1092  long i, long cnt, kmr_mapfn_t m, double dt);
1093 extern void kmr_log_reduce(KMR *mr, KMR_KVS *kvs, struct kmr_kv_box *ev,
1094  long n, kmr_redfn_t r, double dt);
1095 
1096 extern void kmr_ckpt_create_context(KMR *);
1097 extern void kmr_ckpt_free_context(KMR *);
1098 extern int kmr_ckpt_enabled(KMR *);
1099 extern int kmr_ckpt_disable_ckpt(KMR *);
1100 extern int kmr_ckpt_enable_ckpt(KMR *, int);
1101 extern void kmr_ckpt_restore_ckpt(KMR_KVS *);
1102 extern void kmr_ckpt_remove_ckpt(KMR_KVS *);
1103 extern void kmr_ckpt_save_kvo_whole(KMR *, KMR_KVS *);
1104 extern void kmr_ckpt_save_kvo_block_init(KMR *, KMR_KVS *);
1105 extern void kmr_ckpt_save_kvo_block_add(KMR *, KMR_KVS *, long);
1106 extern void kmr_ckpt_save_kvo_block_fin(KMR *, KMR_KVS *);
1107 extern void kmr_ckpt_save_kvo_each_init(KMR *, KMR_KVS *);
1108 extern void kmr_ckpt_save_kvo_each_add(KMR *, KMR_KVS *, long);
1109 extern void kmr_ckpt_save_kvo_each_fin(KMR *, KMR_KVS *);
1110 extern void kmr_ckpt_lock_start(KMR *);
1111 extern void kmr_ckpt_lock_finish(KMR *);
1112 extern int kmr_ckpt_progress_init(KMR_KVS *, KMR_KVS *, struct kmr_option);
1113 extern void kmr_ckpt_progress_fin(KMR *);
1114 extern long kmr_ckpt_first_unprocessed_kv(KMR *);
1115 
1116 /*
1117 Copyright (C) 2012-2016 RIKEN AICS
1118 This library is distributed WITHOUT ANY WARRANTY. This library can be
1119 redistributed and/or modified under the terms of the BSD 2-Clause License.
1120 */
1121 
1122 #endif /*_KMRIMPL_H*/
int kmr_ckpt_progress_init(KMR_KVS *, KMR_KVS *, struct kmr_option)
It initializes a progress of MapReduce checkpointing.
Definition: kmrckpt.c:2753
Key-Value Stream (abstract).
Definition: kmr.h:587
int kmr_iogroup_of_obd(int obdidx)
Returns an I/O-group (an integer key) of a disk from an OBDIDX of Lustre file-system.
Definition: kmrfiles.c:120
Options to Mapping, Shuffling, and Reduction.
Definition: kmr.h:613
int kmr_intstr_ff(long p, char *s, int n)
Fills the character array S by the contents at the pointer value integer P by the length N...
Definition: kmrutil.c:257
void kmr_ckpt_progress_fin(KMR *)
It finalizes the progress of MapReduce checkpointing.
Definition: kmrckpt.c:2845
void kmr_string_truncation(KMR *mr, size_t sz, char *s)
Modifies the string end with by "..." for indicating truncation, used on the result of snprintf...
Definition: kmrutil.c:193
#define KMR_ALIGN(X)
Rounds up a given size to the alignment restriction (currently eight bytes).
Definition: kmrimpl.h:75
unsigned long kmr_fix_bits_endian_ff(unsigned long b)
Fixes little-endian bits used in Fortran to host-endian.
Definition: kmrutil.c:284
void kmr_ckpt_restore_ckpt(KMR_KVS *)
It restores checkpoint data to kvs.
Definition: kmrckpt.c:2557
void kmr_ckpt_save_kvo_each_init(KMR *, KMR_KVS *)
It initializes saving indexed key-value pairs of the output KVS to a checkpoint data file...
Definition: kmrckpt.c:2703
void kmr_ckpt_save_kvo_each_fin(KMR *, KMR_KVS *)
It finalizes saving indexed key-value pairs of the output KVS to the checkpoint data file...
Definition: kmrckpt.c:2733
int kmr_ckpt_enabled(KMR *)
Check if checkpoint/restart is enabled.
Definition: kmrckpt.c:2478
static const size_t kmr_kvs_entry_header
Size of an Entry Header.
Definition: kmr.h:382
Keyed-Record for Sorting.
Definition: kmr.h:372
long kmr_ckpt_first_unprocessed_kv(KMR *)
It returns the index of the first unprocessed key-value in the input KVS.
Definition: kmrckpt.c:2535
Definition: kmr.h:348
KMR Context.
Definition: kmr.h:222
void kmr_ckpt_save_kvo_each_add(KMR *, KMR_KVS *, long)
It adds new key-value pairs of the output KVS to the checkpoint data file.
Definition: kmrckpt.c:2718
FILE * kmr_fopen(const char *n, const char *m)
Does fopen, avoiding EINTR.
Definition: kmrutil.c:610
char * kmr_strptr_ff(char *s)
Returns itself; this is for Fortran-binding.
Definition: kmrutil.c:208
unsigned short kmr_k_position_t[4]
Positions of node by (X,Y,Z,ABC), with ABC axes collapsed.
Definition: kmrimpl.h:126
void kmr_ckpt_save_kvo_whole(KMR *, KMR_KVS *)
It saves all key-value pairs in the output KVS to a checkpoint data file.
Definition: kmrckpt.c:2638
int kmr_fgetc(FILE *f)
Does fgetc, avoiding EINTR.
Definition: kmrutil.c:622
int kmr_dump_mpi_info(char *prefix, MPI_Info info)
Dumps simply contents in MPI_Info.
Definition: kmrutil.c:2212
int kmr_allgatherv(KMR *mr, _Bool rankzeroonly, void *sbuf, long scnt, void *rbuf, long *rcnts, long *rdsps)
All-gathers data, or gathers data when RANKZEROONLY.
Definition: kmratoa.c:70
static long kmr_tick()
Returns the clock counter value.
Definition: kmrimpl.h:135
char * kmr_stringify_spawn_options(struct kmr_spawn_option o)
Returns a print string of a single option, to check the bits are properly encoded in foreign language...
Definition: kmrutil.c:405
void kmr_ckpt_save_kvo_block_add(KMR *, KMR_KVS *, long)
It adds a new block of key-value pairs of the output KVS to the checkpoint data file.
Definition: kmrckpt.c:2670
struct kmr_kvs_entry * kmr_find_kvs_last_entry(KMR_KVS *kvs)
Finds the last entry of a key-value stream.
Definition: kmrbase.c:2759
kmr_kv_field
Datatypes of Keys or Values.
Definition: kmr.h:325
void kmr_isort(void *a, size_t n, size_t es, int depth)
Sorts by comparator on long integers.
Definition: kmrisort.c:292
void kmr_ckpt_create_context(KMR *)
Initialize checkpoint context.
Definition: kmrckpt.c:119
Handy Copy of a Key-Value Field.
Definition: kmr.h:358
Options to Mapping by Spawns.
Definition: kmr.h:662
void kmr_ckpt_save_kvo_block_fin(KMR *, KMR_KVS *)
It finalizes saving block of key-value pairs of the output KVS to the checkpoint data file...
Definition: kmrckpt.c:2685
void * kmr_bsearch(const void *key, const void *base, size_t nel, size_t size, int(*compar)(const void *, const void *))
Searches a key entry like bsearch(3C), but returns a next greater entry instead of null on no match...
Definition: kmrutil.c:565
void kmr_ckpt_free_context(KMR *)
Free checkpoint context.
Definition: kmrckpt.c:162
char * kmr_stringify_file_options(struct kmr_file_option o)
Returns a print string of a single option, to check the bits are properly encoded in foreign language...
Definition: kmrutil.c:386
int kmr_ckpt_disable_ckpt(KMR *)
It temporally disables checkpoint/restart.
Definition: kmrckpt.c:2494
int kmr_add_kv_pushoff(KMR_KVS *kvs, const struct kmr_kv_box kv)
Adds a key-value pair.
Definition: kmraltkvs.c:460
int kmr_assert_sorted(KMR_KVS *kvi, _Bool locally, _Bool shuffling, _Bool ranking)
Checks a key-value stream is sorted.
Definition: kmrutil.c:702
int kmr_iogroup_of_node(KMR *mr)
Returns an I/O-group (an integer key) of a compute node.
Definition: kmrfiles.c:106
void kmr_ckpt_save_kvo_block_init(KMR *, KMR_KVS *)
It initializes saving blocks of key-value pairs of the output KVS to a checkpoint data file...
Definition: kmrckpt.c:2654
#define xassert(X)
Asserts and aborts, but it cannot be disabled.
Definition: kmrdp.cpp:51
char * kmr_stringify_options(struct kmr_option o)
Returns a print string of a single option, to check the bits are properly encoded in foreign language...
Definition: kmrutil.c:361
int kmr_add_kv_done_pushoff(KMR_KVS *kvs)
Marks finished adding key-value pairs, called from kmr_add_kv_done().
Definition: kmraltkvs.c:555
int kmr_getdtablesize(KMR *mr)
Does getdtablesize(); it is defined, because it is not Posix.
Definition: kmrutil.c:635
int kmr_load_properties(MPI_Info conf, char *filename)
Loads properties into MPI_Info (in Latin1 characters).
Definition: kmrutil.c:1851
Options to Mapping on Files.
Definition: kmr.h:638
Unit-Sized Storage.
Definition: kmr.h:340
static struct kmr_kv_box kmr_pick_kv(struct kmr_kvs_entry *e, KMR_KVS *kvs)
Returns a handle to a key-value entry – a reverse of kmr_poke_kv().
Definition: kmrimpl.h:551
int kmr_k_node(KMR *mr, kmr_k_position_t p)
Gets TOFU position (physical coordinates) of the node.
Definition: kmrutil.c:441
N-Tuple.
Definition: kmr.h:731
int(* kmr_redfn_t)(const struct kmr_kv_box kv[], const long n, const KMR_KVS *kvi, KMR_KVS *kvo, void *arg)
Reduce-function Type.
Definition: kmr.h:700
int kmr_gather_sizes(KMR *mr, long siz, long *rbuf)
Calls all-gather for collecting one long-integer.
Definition: kmratoa.c:58
int kmr_ckpt_enable_ckpt(KMR *, int)
It temporally enables checkpoint/restart which has been disabled by calling kmr_ckpt_disable_ckpt().
Definition: kmrckpt.c:2515
static void kmr_poke_kv(struct kmr_kvs_entry *e, const struct kmr_kv_box kv, struct kmr_kv_box *xkv, const KMR_KVS *kvs, _Bool reserve_space_only)
Stores a key-value pair at the entry E in the store – a reverse of kmr_pick_kv().
Definition: kmrimpl.h:599
Information of Source Code Line.
Definition: kmr.h:107
int(* kmr_mapfn_t)(const struct kmr_kv_box kv, const KMR_KVS *kvi, KMR_KVS *kvo, void *arg, const long index)
Map-function Type.
Definition: kmr.h:689
void kmr_ckpt_lock_start(KMR *)
Define the start position of code region that is referred when restart.
Definition: kmrckpt.c:1934
int kmr_copy_mpi_info(MPI_Info src, MPI_Info dst)
Copies contents of MPI_Info.
Definition: kmrutil.c:2238
int kmr_alltoallv(KMR *mr, void *sbuf, long *scounts, long *sdsps, void *rbuf, long *rcounts, long *rdsps)
Does all-to-all-v, but it takes arguments of long-integers.
Definition: kmratoa.c:116
void * kmr_strdup(char *s)
STRDUP, but aborts on failure.
Definition: kmrutil.c:592
void kmr_ckpt_remove_ckpt(KMR_KVS *)
It removes checkpoint data file.
Definition: kmrckpt.c:2612
void kmr_ckpt_lock_finish(KMR *)
Define the end position of code region that is referred when restart.
Definition: kmrckpt.c:1945
int kmr_exchange_sizes(KMR *mr, long *sbuf, long *rbuf)
Calls all-to-all to exchange one long-integer.
Definition: kmratoa.c:46