KMR
kmr.h
Go to the documentation of this file.
1 /* kmr.h (2014-02-04) */
2 /* Copyright (C) 2012-2016 RIKEN AICS */
3 
4 #ifndef _KMR_H
5 #define _KMR_H
6 
7 #define KMR_H 20160425
8 
9 /** \file kmr.h KMR Interface. GENERAL NOTES. (1) The sizes of
10  key-value fields are rounded up to 8-byte boundary. */
11 
12 /** \mainpage KMR
13  \htmlinclude kmr-overview.html */
14 
15 #include <stdio.h>
16 #include <stddef.h>
17 #include <inttypes.h>
18 #include <sys/types.h>
19 #include <string.h>
20 #include <assert.h>
21 
22 /* Poor guess of K or Fujitsu FX10. */
23 #if defined(__sparc) && defined(__HPC_ACE__)
24 #define __K 1
25 #endif
26 
27 #define KMR_BR0 {
28 #define KMR_BR1 }
29 #ifdef __cplusplus
30 extern "C" KMR_BR0
31 #endif
32 
33 #ifdef __cplusplus
34 #ifdef _Bool
35 #undef _Bool
36 #endif
37 typedef unsigned char _Bool;
38 #endif
39 
40 /* KMR version number. */
41 
42 #define KMR_API_ID0(X) KMR_API_ID1(X)
43 #define KMR_API_ID1(X) kmr_api_ ## X
44 #define KMR_API_ID KMR_API_ID0(KMR_H)
45 
46 extern int KMR_API_ID;
47 extern const int kmr_version;
48 
49 /* MPI tags used as replies in kmr_map_via_spawn(). */
50 
51 #define KMR_TAG_SPAWN_REPLY 500
52 #define KMR_TAG_SPAWN_REPLY1 501
53 
54 struct kmr_ctx;
55 union kmr_kvs;
56 
57 typedef struct kmr_ctx KMR;
58 typedef union kmr_kvs KMR_KVS;
59 
60 #define KMR_JOB_NAME_LEN 256
61 
62 /** Makes a new key-value stream (of type KMR_KVS) with the specified
63  field datatypes. */
64 
65 #define kmr_create_kvsx(MR,KF,VF,OPT) \
66  kmr_create_kvs7((MR), (KF), (VF), (OPT), __FILE__, __LINE__, __func__)
67 
68 /** Makes a new key-value stream (of type KMR_KVS) with the specified
69  field datatypes. */
70 
71 #define kmr_create_kvs(MR,KF,VF) \
72  kmr_create_kvs7((MR), (KF), (VF), kmr_noopt, __FILE__, __LINE__, __func__)
73 
74 /** Makes a new key-value stream (of type KMR_KVS). */
75 
76 #define kmr_create_kvs_(MR,IGNORE) \
77  kmr_create_kvs7((MR), KMR_KV_BAD, KMR_KV_BAD, kmr_noopt, \
78  __FILE__, __LINE__, __func__)
79 
80 /** Maps simply. See kmr_map9(). */
81 
82 #define kmr_map(KVI, KVO, ARG, OPT, M) \
83  kmr_map9(0, (KVI), (KVO), (ARG), (OPT), (M), \
84  __FILE__, __LINE__, __func__)
85 
86 /** Reduces key-value pairs. See kmr_reduce9(). */
87 
88 #define kmr_reduce(KVI, KVO, ARG, OPT, R) \
89  kmr_reduce9(0, (KVI), (KVO), (ARG), (OPT), (R), \
90  __FILE__, __LINE__, __func__)
91 
92 /* Link of Key-Value Streams. */
93 
94 struct kmr_kvs_list {
95  KMR_KVS *prev, *next;
96 };
97 
99  KMR_KVS *head, *tail;
100 };
101 
102 struct kmr_ckpt_ctx;
103 struct kmr_trace;
104 
105 /** Information of Source Code Line. */
106 
107 struct kmr_code_line { const char *file; const char *func; int line; };
108 
109 /** KMR Context. Structure KMR is a common record of key-value
110  streams. It records a few internal states and many options.
111 
112  KVSES is a linked-list recording all active key-value streams. It
113  is used to warn about unfreed key-value streams.
114 
115  CKPT_KVS_ID_COUNTER and CKPT_CTX record checkpointing states.
116 
117  LOG_TRACES is a file stream, when it is non-null, which records
118  times taken by each call to map/reduce-functions. Note that trace
119  routines call MPI_Wtime() in OMP parallel regions (although it may
120  be non-threaded). ATWORK indicates the caller of the current work
121  of mapping or reducing (or null if it is not associated), which is
122  used in logging traces.
123 
124  SPAWN_SIZE and SPAWN_COMMS temporarily holds an array of
125  inter-communicators for kmr_map_via_spawn(), so that a
126  communicator can be obtained by kmr_get_spawner_communicator() in
127  a map-function.
128 
129  MAPPER_PARK_SIZE is the number of entries pooled before calling a
130  map-function. Entries are aggregated to try to call a
131  map-function with threads. PRESET_BLOCK_SIZE is the default
132  allocation size of a buffer of key-values. It is used as a
133  block-size of key-value streams after trimmed by the amount of the
134  malloc overhead. MALLOC_OVERHEAD (usually an amount of one
135  pointer) is reduced from the allocation size, to keep good
136  alignment boundary.
137 
138  ATOA_THRESHOLD makes the choice of algorithms of all-to-all-v
139  communication by the sizes of messages (set to zero to use
140  all-to-all-v of MPI).
141 
142  SORT_TRIVIAL determines the sorter to run on a single node when
143  data size is this value or smaller. SORT_THRESHOLD determines the
144  sorter to use full sampling of a sampling-sort, or pseudo sampling
145  when data size is small. SORT_SAMPLES_FACTOR determines the
146  number of samples of a sampling-sort. SORT_THREADS_DEPTH controls
147  the local sorter. The quick-sort uses Open MP threads until
148  recursion depth reaches this value (set to zero for sequential
149  run).
150 
151  FILE_IO_BLOCK_SIZE is a block size of file reading, used when the
152  striping information is not available.
153 
154  PUSHOFF_BLOCK_SIZE is a block size of a push-off key-value stream.
155  It is a communication block size and should be eqauls on all
156  ranks. PUSHOFF_POLL_RATE gives a hint to a polling interval of a
157  push-off key-value stream.
158 
159  KMR_INSTALLATION_PATH records the installation path, which is
160  taken from the configuration. SPAWN_WATCH_PROGRAM is a
161  watch-program name, which is used in spawning processes which do
162  not communicate to the parent. The variable is a file-path which
163  may be set in advance or may be set to one where the watch-program
164  is copied (usually in the user's home directory).
165  SPAWN_WATCH_PREFIX is a location where a watch-program is to be
166  installed (instead of the home directory). SPAWN_WATCH_HOST_NAME
167  is a name of a host-name of a spawner. It may be set when there
168  is a difficulty in connecting a socket. SPAWN_MAX_PROCESSES
169  limits the number of processes simultaneously spawned without
170  regard to the universe size. SPAWN_WATCH_AF is 0, 4, or 6 as the
171  preferred IP address format used by the watch-program.
172  SPAWN_WATCH_PORT_RANGE[2] is a range of IP port number used by the
173  watch-program (values are inclusive). SPAWN_GAP_MSEC[2] is the
174  time given between spawning calls needed by the MPI runtime to
175  clean-up the resource management. The value is scaled to the log
176  of the universe size, corresponding the 1st value to 0 processes
177  and the 2nd value to 1,000 processes (the default is 1 second to
178  one process and 10 seconds for 1,000 processes).
179  SPAWN_WATCH_ACCEPT_ONHOLD_MSEC is the time given to wait for the
180  watch-program to connect back by a socket.
181 
182  VERBOSITY is the verbosity of warning messages; default 5 is good
183  for typical use.
184 
185  ONK enables the features on K or FX10. SINGLE_THREAD makes imply
186  the nothreading option for mapper/shuffler/reducer. ONE_STEP_SORT
187  disables a prior sorting step which sort on (packed/hashed)
188  integer keys in local sorting. STEP_SYNC is to call a barrier at
189  each operation step for debugging. TRACE_FILE_IO, TRACE_MAP_MS,
190  and TRACE_MAP_SPAWN let dump trace output for debugging.
191  (TRACE_ALLTOALL lets dump trace output on communication for
192  debugging internals). TRACE_KMRDP lets dump timing information of
193  run of KMR-DP. STD_ABORT lets use abort() instead of MPI_Abort()
194  on errors, to let cores dumped on some MPI implementations.
195  (FILE_IO_DUMMY_STRIPING is for debugging internals, and assigns
196  dummy striping information on not Lustre file-systems).
197  (FILE_IO_ALWAYS_ALLTOALLV is for debugging internals).
198  SPAWN_DISCONNECT_EARLY (useless) lets the spawner free the
199  inter-communicator immediately after spawning.
200  SPAWN_DISCONNECT_BUT_FREE lets the spawner use
201  MPI_Comm_disconnect() instead of MPI_Comm_free() (It is only used
202  with buggy Intel MPI (4.x)). (SPAWN_PASS_INTERCOMM_IN_ARGUMENT
203  changes the behavior to the old API). MPI_THREAD_SUPPORT records
204  the thread support level. CKPT_ENABLE is a checkpointing enable.
205  CKPT_SELECTIVE enables users to specify which kmr functions take
206  ckpt files of the output key-value stream. To take ckpt files
207  with this option enabled, users should specify TAKE_CKPT option
208  enabled when calling a kmr function. CKPT_NO_FSYNC does not call
209  fsync syscall on writing ckpt files. Both CKPT_SELECTIVE and
210  CKPT_NO_FSYNC should be specified with CKPT_ENABLE.
211  STOP_AT_SOME_CHECK_GLOBALLY forces global checking of stop-at-some
212  state in mapping (not implemented). Mapping with stop-at-some
213  should be stopped when some key-value is added on any rank, but
214  the check is performed only locally by default. PUSHOFF_HANG_OUT
215  makes communication of push-off continue on after a finish of
216  mapping/reducing. PUSHOFF_FAST_NOTICE enables use of RDMA put for
217  event notification in push-off key-value streams. PUSHOFF_STAT
218  enables collecting statistics of communication in push-off
219  key-value streams. KMRVIZ_TRACE enables tracing kmr function calls
220  for KMRViz. IDENTIFYING_NAME is just a note. */
221 
222 struct kmr_ctx {
223  MPI_Comm comm;
224  int nprocs;
225  int rank;
226  MPI_Info conf;
227  struct kmr_kvs_list_head kvses;
228 
229  long ckpt_kvs_id_counter;
230  struct kmr_ckpt_ctx *ckpt_ctx;
231 
232  struct kmr_trace *kvt_ctx;
233 
234  FILE *log_traces;
235  struct kmr_code_line *atwork;
236 
237  int spawn_size;
238  MPI_Comm **spawn_comms;
239 
240  long mapper_park_size;
241  size_t preset_block_size;
242  size_t malloc_overhead;
243 
244  long atoa_threshold;
245 
246  long sort_trivial;
247  long sort_threshold;
248  long sort_sample_factor;
249  int sort_threads_depth;
250 
251  long file_io_block_size;
252 
253  char *kmr_installation_path;
254  char *spawn_watch_program;
255  char *spawn_watch_prefix;
256  char *spawn_watch_host_name;
257  int spawn_max_processes;
258  int spawn_watch_af;
259  int spawn_watch_port_range[2];
260  int spawn_gap_msec[2];
261  int spawn_watch_accept_onhold_msec;
262 
263  size_t pushoff_block_size;
264  int pushoff_poll_rate;
265 
266  uint8_t verbosity;
267 
268  _Bool onk : 1;
269  _Bool single_thread : 1;
270  _Bool one_step_sort : 1;
271  _Bool step_sync : 1;
272  _Bool trace_sorting : 1;
273  _Bool trace_file_io : 1;
274  _Bool trace_map_ms : 1;
275  _Bool trace_map_spawn : 1;
276  _Bool trace_alltoall : 1;
277  _Bool trace_kmrdp : 1;
278  _Bool trace_iolb : 1;
279  _Bool std_abort : 1;
280  _Bool file_io_dummy_striping : 1;
281  _Bool file_io_always_alltoallv : 1;
282  _Bool spawn_sync_at_startup : 1;
283  _Bool spawn_watch_all : 1;
284  _Bool spawn_disconnect_early : 1;
285  _Bool spawn_disconnect_but_free : 1;
286  _Bool spawn_pass_intercomm_in_argument : 1;
287  _Bool keep_fds_at_fork : 1;
288 
289  _Bool mpi_thread_support : 1;
290 
291  _Bool ckpt_enable : 1;
292  _Bool ckpt_selective : 1;
293  _Bool ckpt_no_fsync : 1;
294 
295  _Bool stop_at_some_check_globally : 1;
296 
297  _Bool pushoff_hang_out : 1;
298  _Bool pushoff_fast_notice : 1;
299  _Bool pushoff_stat : 1;
300 
301  struct {
302  double times[4];
303  long counts[10];
304  } pushoff_statistics;
305 
306  _Bool kmrviz_trace : 1;
307 
308  char identifying_name[KMR_JOB_NAME_LEN];
309 
310 };
311 
312 /** Datatypes of Keys or Values. It indicates the field data of keys
313  or values. KMR_KV_OPAQUE is a variable-sized byte vector, and
314  KMR_KV_CSTRING is a non-wide C string, and they are dealt with in
315  exactly the same way. KMR_KV_INTEGER is a long integer, and
316  KMR_KV_FLOAT8 is a double. The datatypes are mostly uninterpreted
317  in mapping/reducing, except for in sorting. There are two other
318  types for pointers. Pointers can be stored as they are (unlike
319  opaque data, which are embedded in the field), but converted to
320  opaque ones before communication. KMR_KV_POINTER_OWNED is an
321  allocated pointer, and the data will be freed on consuming a
322  key-value stream. KMR_KV_POINTER_UNMANAGED is a pointer to a
323  possibly shared data. */
324 
326  KMR_KV_BAD,
327  KMR_KV_OPAQUE,
328  KMR_KV_CSTRING,
329  KMR_KV_INTEGER,
330  KMR_KV_FLOAT8,
331  KMR_KV_POINTER_OWNED,
332  KMR_KV_POINTER_UNMANAGED
333 };
334 
335 /** Unit-Sized Storage. A key or a value is passed around as
336  unit-sized data. It is accessed by ".i" for KMR_KV_INTEGER, ".d"
337  for KMR_KV_FLOAT8, and ".p" KMR_KV_OPAQUE or other pointer cases.
338  It appears in struct kmr_kv_box. */
339 
340 union kmr_unit_sized {const char *p; long i; double d;};
341 
342 /* Storage of a Key-Value Entry. They are stored as key-length;
343  value-length; key-content[]; value-content[]. Occupied lengths are
344  rounded up to the alignment, thus the size of the entry is:
345  (2*sizeof(int)+KMR_ALIGN(klen)+KMR_ALIGN(vlen)). Flexible-array
346  member is avoided for C++. */
347 
349  int klen;
350  int vlen;
351  unsigned char c[1];
352 };
353 
354 /** Handy Copy of a Key-Value Field. It holds a pair of a key and a
355  value. The field may either be a copy (for an integer or a real
356  value) or a pointer to the storage. */
357 
358 struct kmr_kv_box {
359  int klen;
360  int vlen;
361  union kmr_unit_sized k;
362  union kmr_unit_sized v;
363 };
364 
365 #define kmr_kv_cake kmr_kv_box
366 
367 /** Keyed-Record for Sorting. A ranking key V is associated with an
368  entry for sorting. An array of this record is held during local
369  sorting. The ranking keys are integers respecting the ordering of
370  integers, doubles, and opaque bytes. */
371 
373  long v;
374  struct kmr_kvs_entry *e;
375 };
376 
377 /** Size of an Entry Header. It is the size of the length fields of a
378  key-value. It is also the size of the slack space for an
379  end-of-block marker, where the end of entries in a block is marded
380  by klen=-1 and vlen=-1. */
381 
382 static const size_t kmr_kvs_entry_header = offsetof(struct kmr_kvs_entry, c);
383 
384 /* Types of Key-Value Stream. It is a tag stored in the header.
385  KMR_KVS_ONCORE corresponds to struct kmr_kvs_oncore, and
386  KMR_KVS_PUSHOFF to struct kmr_kvs_pusoff. (KMR_KVS_STREAM is
387  undefined currently). PACKED is a marker after packing (marshaling
388  to byte arrays). */
389 
390 enum kmr_kvs_magic {
391  KMR_KVS_BAD,
392  KMR_KVS_ONCORE,
393  /*KMR_KVS_STREAM,*/
394  KMR_KVS_PUSHOFF,
395  KMR_KVS_ONCORE_PACKED
396  /*KMR_KVS_STREAM_PACKED*/
397 };
398 
399 #define KMR_KVS_MAGIC_OK(X) \
400  ((X) == KMR_KVS_ONCORE || (X) == KMR_KVS_ONCORE_PACKED \
401  || (X) == KMR_KVS_PUSHOFF)
402 
403 /** State during kmr_map_ms(). It is kept in a key-value stream only
404  during kmr_map_ms() on rank0. (IT SHOULD BE INCLUDED IN THE STATE
405  OF kmr_save_kvs() AND kmr_restore_kvs(), BUT NOT YET).
406  Flexible-array member is avoided for C++. */
407 
409  int nodes;
410  int kicks;
411  int dones;
412  char states[1];
413 };
414 
415 /** Key-Value Stream. MAGIC and MR holds the relevant data. LINK is
416  used to list all allocated key-value streams in the context to
417  detect unfreed ones. KEY_DATA is a datatype of a key field.
418  VALUE_DATA is a datatype of a value field. INFO_LINE0 records the
419  location of its allocation in a program. ELEMENT_COUNT is the
420  local count of the number of elements.
421 
422  STOWED is set when adding key-value is finished. ONCORE is always
423  true (currently ignored). NOGROW is set when the buffer is
424  preallocated by an enough size. SORTED indicates the key-value
425  stream is locally sorted. SHUFFLED_IN_PUSHOFF is true when its
426  contents are already shuffled. (UNIFORMLY_SIZED is set when all
427  key-values are of the same size. (currently ignored)).
428  (SHUFFLE_TO_SINGLE is set when the shuffling target is a single rank,
429  which only checked locally at each rank. (currently ignored)).
430 
431  Fields start from CKPT_ are used only when checkpoint/restart is
432  enabled. CKPT_KVS_ID stores a sequence number starts from 0 which
433  is assigned to Key-Value Stream and used to distinguish each other.
434  CKPT_GENERATED_OP and CKPT_CONSUMED_OP store sequence numbers of
435  operations performed to this Key-Value Stream. When this Key-Value
436  Stream is used as an output, the sequence number of the operation
437  is set to CKPT_GENERATED_OP. When this Key-Value Stream is used as
438  an input, the sequence number of the operation is set to
439  CKPT_CONSUMED_OP.
440 
441  BLOCK_SIZE is an unit of memory allocation invoked at adding a
442  key-value pair. It is PRESET_BLOCK_SIZE in the KMR-context by
443  default. ELEMENT_SIZE_LIMIT restricts the size of one key-value
444  pair (for error detection), and it is set to the 1/4 of BLOCK_SIZE
445  by default.
446 
447  STORAGE_NETSIZE is the local total size used to hold key-value
448  pairs. The size is the sum of kmr_kvs_entry_netsize()
449  corresponding to opaque fields, and is much larger than actually
450  occupied when the data fields are pointers. FIRST_BLOCK points to
451  the chain of blocks of data.
452 
453  MS field holds a state during master-slave mapping.
454 
455  A pair of transient fields CURRENT_BLOCK and ADDING_POINT points
456  to the current insertion point. */
457 
459  enum kmr_kvs_magic magic;
460  KMR *mr;
461  struct kmr_kvs_list link;
462  enum kmr_kv_field key_data;
463  enum kmr_kv_field value_data;
464  struct kmr_code_line info_line0;
465  long element_count;
466 
467  _Bool stowed : 1;
468  _Bool oncore : 1;
469  _Bool nogrow : 1;
470  _Bool sorted : 1;
471  _Bool shuffled_in_pushoff : 1;
472  _Bool _uniformly_sized_ : 1;
473  //_Bool _shuffle_to_single_ : 1;
474 
475  long ckpt_kvs_id;
476  long ckpt_generated_op;
477  long ckpt_consumed_op;
478 
479  size_t block_size;
480  size_t element_size_limit;
481 
482  size_t storage_netsize;
483  long block_count;
484  struct kmr_kvs_block *first_block;
485 
486  /* Transient fields: */
487 
488  struct kmr_map_ms_state *ms;
489 
490  _Bool under_threaded_operation;
491  struct kmr_kvs_block *current_block;
492  struct kmr_kvs_entry *adding_point;
493  void *temporary_data;
494 
495  //#ifdef _OPENMP
496  //omp_lock_t mutex;
497  //#endif /*_OPENMP*/
498 };
499 
500 /* Storage of Key-Value Pairs. The storage is managed as blocks, each
501  containing entries terminated by an end-of-block marker. A marker
502  is of klen=-1 and vlen=-1 with no data. A MARKER IS MANDATORYILY
503  PLACED TO CHECK THE END (the early design did not have FILL_SIZE
504  field). SIZE is the whole structure (not just the data part).
505  PARTIAL_ELEMENT_COUNT is the count in this block. FILL_SIZE is a
506  next fill-point. Flexible-array member is avoided for C++. */
507 
509  struct kmr_kvs_block *next;
510  size_t size;
511  long partial_element_count;
512  size_t fill_size;
513  struct kmr_kvs_entry data[1];
514 };
515 
516 /* Size of a Block Header. */
517 
518 static const size_t kmr_kvs_block_header = offsetof(struct kmr_kvs_block, data);
519 
520 /** Record of Push-Off Key-Value Stream for a Rank. FILLBUF is for
521  fill-in and RECVBUF receiving. SENDBUFS[2] is a list of blocks,
522  where SENDBUFS[0] points to the head and and SENDBUFS[1] to the
523  tail. */
524 
526  struct kmr_kvs_entry *adding_point;
527  struct kmr_kvs_block *fillbuf;
528  struct kmr_kvs_block *recvbuf;
529  struct kmr_kvs_block *sendbufs[2];
530  int sends;
531  _Bool closed[2];
532 };
533 
534 /** Key-Value Stream with Shuffling at Addition of Key-Values.
535  ELEMENT_COUNT counts local calls of kmr_add_kv(), and it is not
536  the result count which is the count of the elements received.
537  STORAGE keeps the true contents temporarily, and later it will
538  replace this key-value stream. PEERS and REQS are used
539  communication. REQS is of length (2*nprocs), the first half for
540  sends and the second half for receives. */
541 
543  enum kmr_kvs_magic magic;
544  KMR *mr;
545  struct kmr_kvs_list link;
546  enum kmr_kv_field key_data;
547  enum kmr_kv_field value_data;
548  struct kmr_code_line info_line0;
549  long element_count;
550 
551  _Bool stowed : 1;
552  _Bool oncore : 1;
553  _Bool nogrow : 1;
554  _Bool sorted : 1;
555  _Bool shuffled_in_pushoff : 1;
556  _Bool _uniformly_sized_ : 1;
557 
558  int seqno;
559  KMR_KVS *storage;
560  struct kmr_pushoff_buffers *peers;
561  MPI_Request *reqs;
562  int *indexes;
563  MPI_Status *statuses;
564 };
565 
566 /** Key-Value Stream (DUMMY); Mandatory Entries. */
567 
569  enum kmr_kvs_magic magic;
570  KMR *mr;
571  struct kmr_kvs_list link;
572  enum kmr_kv_field key_data;
573  enum kmr_kv_field value_data;
574  struct kmr_code_line info_line0;
575  long element_count;
576 
577  _Bool stowed : 1;
578  _Bool oncore : 1;
579  _Bool nogrow : 1;
580  _Bool sorted : 1;
581  _Bool shuffled_in_pushoff : 1;
582  _Bool _uniformly_sized_ : 1;
583 };
584 
585 /** Key-Value Stream (abstract). */
586 
587 union kmr_kvs {
588  struct kmr_kvs_dummy m;
589  struct kmr_kvs_oncore c;
590  struct kmr_kvs_pushoff o;
591 };
592 
593 /** Options to Mapping, Shuffling, and Reduction. Options must be the
594  same on all ranks. NOTHREADING tells a mapper and a reducer to
595  suppress threading on loops calling a map-function or a
596  reduce-function. It should be set when a map-function or a
597  reduce-function is multi-threaded itself. INSPECT tells a mapper
598  that a map-function just inspects the entries, and does not
599  consume the input key-value stream. KEEP_OPEN tells a mapper not
600  to close the output key-value stream for further additions of
601  key-value pairs. KEY_AS_RANK tells a shuffler to use a key as a
602  rank. TAKE_CKPT tells kmr functions that support
603  Checkpoint/Restart to take checkpoints of the output key-value
604  stream when CKPT_SELECTIVE global option is enabled. RANK_ZERO
605  tells kmr_replicate() to gather pairs on rank0 only. (COLLAPSE
606  tells a mapper to convert pointer data to opaque. Conversions of
607  data fields are needed in advance to exchanging data in shuffling.
608  It is mainly intended internal use only). The padding fields make
609  the option size as long, for the Fortran binding whose options are
610  passed by intergers (SPARC-V9 compilers put bit-fields on
611  arguments as 64 bits). */
612 
613 struct kmr_option {
614  _Bool nothreading : 1;
615  _Bool inspect : 1;
616  _Bool keep_open : 1;
617  _Bool key_as_rank : 1;
618  _Bool rank_zero : 1;
619  _Bool collapse : 1;
620  _Bool take_ckpt : 1;
621  /*_Bool guess_pattern : 1;*/
622  int : 16;
623  int : 32;
624 };
625 
626 /* Initializers are not by designators for C++ below. */
627 
628 static const struct kmr_option kmr_noopt = {0, 0, 0, 0, 0, 0, 0};
629 static const union {struct kmr_option o; unsigned long bits;}
630  kmr_optmask = {{1, 1, 1, 1, 1, 1, 1}};
631 
632 /** Options to Mapping on Files. See the description on
633  kmr_map_file_names() and kmr_map_file_contents() for the meaning.
634  The padding fields make the option size as long, for the Fortran
635  binding whose options are passed by intergers (SPARC-V9 compilers
636  put bit-fields on arguments as 64 bits). */
637 
639  _Bool each_rank : 1;
640  _Bool subdirectories : 1;
641  _Bool list_file : 1;
642  _Bool shuffle_names : 1;
643  int : 16;
644  int : 32;
645 };
646 
647 /* Initializers are not by designators for C++ below. */
648 
649 static const struct kmr_file_option kmr_fnoopt = {0, 0, 0, 0};
650 static const union {struct kmr_file_option o; unsigned long bits;}
651  kmr_foptmask = {{1, 1, 1, 1}};
652 
653 /** Options to Mapping by Spawns. See the description on
654  kmr_map_via_spawn() for the meaning. The padding fields make the
655  option size as long, for the Fortran binding whose options are
656  passed by intergers (SPARC-V9 compilers put bit-fields on
657  arguments as 64 bits). ONE_BY_ONE is no longer used (since
658  ver.178). TAKE_CKPT tells kmr functions that support
659  Checkpoint/Restart to take checkpoints of the output key-value
660  stream when CKPT_SELECTIVE global option is enabled. */
661 
663  _Bool separator_space : 1;
664  _Bool reply_each : 1;
665  _Bool reply_root : 1;
666  _Bool one_by_one : 1;
667  _Bool take_ckpt : 1;
668  int : 16;
669  int : 32;
670 };
671 
672 /* Initializers are not by designators for C++ below. */
673 
674 static const struct kmr_spawn_option kmr_snoopt = {0, 0, 0, 0, 0};
675 static const union {struct kmr_spawn_option o; unsigned long bits;}
676  kmr_soptmask = {{1, 1, 1, 1, 1}};
677 
678 /** Map-function Type. A map-function gets a key-value pair as struct
679  kmr_kv_box KV. KVI is the input key-value stream, but it can be
680  usually ignored (its potential usage is to check the content type
681  of the key and value fields). KVO is the output key-value stream.
682  The pointer ARG is one just passed to kmr_map(), which has no
683  specific purpose and is used to pass any argument to a
684  map-function. INDEX is the count of map-function calls, and it
685  usually equals to the index of a key-value pair in the input. It
686  is assured distinct, and can be used for race-free accesses to the
687  pointer ARG. */
688 
689 typedef int (*kmr_mapfn_t)(const struct kmr_kv_box kv,
690  const KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
691  const long index);
692 
693 /** Reduce-function Type. A reduce-function gets key-value pairs as
694  an array KV of struct kmr_kv_box. N is the number of key-value
695  pairs. KVI is the the input key-value stream, but it can be
696  usually ignored. KVO is the output key-value stream. The pointer
697  ARG is one just passed to kmr_reduce(), which has no specific
698  purpose and is used to pass any argument to a reduce-function. */
699 
700 typedef int (*kmr_redfn_t)(const struct kmr_kv_box kv[], const long n,
701  const KMR_KVS *kvi, KMR_KVS *kvo, void *arg);
702 
703 /** Spawning Info. (OBSOLETE: USE IS ENABLED BY SETTING
704  SPAWN_PASS_INTERCOMM_IN_ARGUMENT=1 IN THE MKR STRUCTURE). It is
705  passed to a map-function in kmr_map_via_spawn(). MAPARG is the
706  pointer argument to kmr_map_via_spawn(). ICOMM is the
707  inter-communicator, and ICOMM_FF is for Fortran. REPLY_ROOT is a
708  boolean value of the option REPLY_ROOT. Union is taken for icomm
709  to make it independent from its representation (integer or
710  pointer). */
711 
713  void *maparg;
714  union {MPI_Comm icomm; long i_;} u;
715  int icomm_ff;
716  int reply_root;
717 };
718 
719 /** N-Tuple. An n-tuple is a list of opaque values, intended to store
720  a list of data items as a key or a value in a key-value stream.
721  It is for the utility purpose. N is the number of entries.
722  MARKER can be any value and it is used as a tag for a direct-sum,
723  which identifies which key-value stream an n-tuple originally
724  belonged. Use kmr_reset_ntuple() and kmr_put_ntuple() to create
725  n-tuples, and kmr_add_ntuple() to add n-tuples in key-value
726  stream. The data items in an n-tuple are a sequence of pairs -- a
727  length followed by opaque bytes. Note the marker and the item
728  length be kept the same when n-tuples are used as keys for
729  sorting. */
730 
731 struct kmr_ntuple {
732  int marker;
733  unsigned short n;
734  unsigned short index;
735  unsigned short len[1];
736 };
737 
738 /** N-Tuple Argument. */
739 
741  void *p;
742  unsigned short len;
743 };
744 
745 /** Sets up the environment. Currently it does nothing. */
746 
747 #define kmr_init() kmr_init_2(KMR_API_ID)
748 
749 extern int kmr_init_2(int ignore);
750 extern int kmr_fin(void);
751 extern KMR *kmr_create_context(const MPI_Comm comm, const MPI_Info conf,
752  const char *name);
753 extern int kmr_free_context(KMR *mr);
754 extern KMR *kmr_get_context_of_kvs(KMR_KVS const *kvs);
755 
756 extern KMR_KVS *kmr_create_kvs7(KMR *mr, enum kmr_kv_field k,
757  enum kmr_kv_field v,
758  struct kmr_option opt,
759  const char *, const int, const char *);
760 extern int kmr_free_kvs(KMR_KVS *kvs);
761 extern int kmr_move_kvs(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
762 extern int kmr_concatenate_kvs(KMR_KVS *kvs[], int nkvs, KMR_KVS *kvo,
763  struct kmr_option opt);
764 
765 extern int kmr_add_kv(KMR_KVS *kvs, const struct kmr_kv_box kv);
766 extern int kmr_add_kv1(KMR_KVS *kvs, void *k, int klen, void *v, int vlen);
767 extern int kmr_add_kv_space(KMR_KVS *kvs, const struct kmr_kv_box kv,
768  void **keyp, void **valuep);
769 extern int kmr_add_kv_quick_(KMR_KVS *kvs, const struct kmr_kv_box kv);
770 extern int kmr_add_kv_done(KMR_KVS *kvs);
771 extern int kmr_add_string(KMR_KVS *kvs, const char *k, const char *v);
772 
773 extern int kmr_map9(_Bool stop_when_some_added,
774  KMR_KVS *kvi, KMR_KVS *kvo,
775  void *arg, struct kmr_option opt, kmr_mapfn_t m,
776  const char *, const int, const char *);
777 extern int kmr_map_skipping(long from, long stride, long limit,
778  _Bool stop_when_some_added,
779  KMR_KVS *kvi, KMR_KVS *kvo,
780  void *arg, struct kmr_option opt, kmr_mapfn_t m);
781 extern int kmr_map_once(KMR_KVS *kvo, void *arg, struct kmr_option opt,
782  _Bool rank_zero_only, kmr_mapfn_t m);
783 extern int kmr_map_on_rank_zero(KMR_KVS *kvo, void *arg, struct kmr_option opt,
784  kmr_mapfn_t m);
785 extern int kmr_map_rank_by_rank(KMR_KVS *kvi, KMR_KVS *kvo,
786  void *arg, struct kmr_option opt,
787  kmr_mapfn_t m);
788 extern int kmr_map_ms(KMR_KVS *kvi, KMR_KVS *kvo,
789  void *arg, struct kmr_option opt,
790  kmr_mapfn_t m);
791 extern int kmr_map_ms_commands(KMR_KVS *kvi, KMR_KVS *kvo,
792  void *arg, struct kmr_option opt,
793  struct kmr_spawn_option sopt,
794  kmr_mapfn_t m);
795 extern int kmr_map_for_some(KMR_KVS *kvi, KMR_KVS *kvo,
796  void *arg, struct kmr_option opt, kmr_mapfn_t m);
797 
798 extern int kmr_map_via_spawn(KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
799  MPI_Info info, struct kmr_spawn_option opt,
800  kmr_mapfn_t mapfn);
801 extern int kmr_reply_to_spawner(KMR *mr);
802 extern MPI_Comm *kmr_get_spawner_communicator(KMR *mr, long index);
803 
804 extern int kmr_map_processes(_Bool nonmpi,
805  KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
806  MPI_Info info, struct kmr_spawn_option opt,
807  kmr_mapfn_t mapfn);
808 extern int kmr_map_parallel_processes(KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
809  MPI_Info info,
810  struct kmr_spawn_option opt,
811  kmr_mapfn_t mapfn);
812 extern int kmr_map_serial_processes(KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
813  MPI_Info info,
814  struct kmr_spawn_option opt,
815  kmr_mapfn_t mapfn);
816 
817 extern KMR *kmr_create_context_world(void);
818 extern KMR *kmr_create_dummy_context(void);
819 extern int kmr_send_kvs_to_spawner(KMR *mr, KMR_KVS *kvs);
820 extern int kmr_receive_kvs_from_spawned_fn(const struct kmr_kv_box kv,
821  const KMR_KVS *kvi,
822  KMR_KVS *kvo, void *arg,
823  const long index);
824 
825 #define kmr_sort_a_batch(X0,X1,X2,X3) kmr_sort_locally(X0,X1,X2,X3)
826 
827 extern int kmr_sort_locally(KMR_KVS *kvi, KMR_KVS *kvo, _Bool shuffling,
828  struct kmr_option opt);
829 
830 extern int kmr_shuffle(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
831 extern int kmr_replicate(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
832 
833 extern int kmr_reduce9(_Bool stop_when_some_added,
834  KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
835  struct kmr_option opt, kmr_redfn_t r,
836  const char *, const int, const char *);
837 extern int kmr_reduce_as_one(KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
838  struct kmr_option opt, kmr_redfn_t r);
839 extern int kmr_reduce_for_some(KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
840  struct kmr_option opt, kmr_redfn_t r);
841 
842 extern int kmr_file_enumerate(KMR *mr, char **names, int n, KMR_KVS *kvo,
843  struct kmr_file_option fopt);
844 extern int kmr_map_file_names(KMR *mr, char **names, int n,
845  struct kmr_file_option fopt,
846  KMR_KVS *kvo, void *arg,
847  struct kmr_option opt, kmr_mapfn_t m);
848 extern int kmr_map_getline(KMR *mr, FILE *f, long limit, _Bool largebuffering,
849  KMR_KVS *kvo,
850  void *arg, struct kmr_option opt, kmr_mapfn_t m);
851 extern int kmr_map_getline_in_memory_(KMR *mr, void *b, size_t sz, long limit,
852  KMR_KVS *kvo, void *arg,
853  struct kmr_option opt, kmr_mapfn_t m);
854 
855 extern int kmr_take_one(KMR_KVS *kvi, struct kmr_kv_box *kv);
856 extern int kmr_find_key(KMR_KVS *kvi, struct kmr_kv_box ki,
857  struct kmr_kv_box *vo);
858 extern int kmr_find_string(KMR_KVS *kvi, const char *k, const char **vq);
859 
860 extern int kmr_copy_info_to_kvs(MPI_Info src, KMR_KVS *kvo);
861 extern int kmr_copy_kvs_to_info(KMR_KVS *kvi, MPI_Info dst);
862 
863 extern int kmr_get_element_count(KMR_KVS *kvs, long *v);
864 extern int kmr_local_element_count(KMR_KVS *kvs, long *v);
865 
866 extern int kmr_add_identity_fn(const struct kmr_kv_box kv,
867  const KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
868  const long i);
869 extern int kmr_copy_to_array_fn(const struct kmr_kv_box kv,
870  const KMR_KVS *kvi, KMR_KVS *kvo, void *arg,
871  const long i);
872 extern int kmr_save_kvs(KMR_KVS *kvi, void **dataq, size_t *szq,
873  struct kmr_option opt);
874 extern int kmr_restore_kvs(KMR_KVS *kvo, void *data, size_t sz,
875  struct kmr_option opt);
876 
877 extern int kmr_reverse(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
878 extern int kmr_pairing(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
879 extern int kmr_unpairing(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
880 
881 extern int kmr_sort(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
882 extern int kmr_sort_small(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
883 extern int kmr_sort_large(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
884 extern int kmr_sort_by_one(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
885 
886 extern int kmr_match(KMR_KVS *kvi0, KMR_KVS *kvi1, KMR_KVS *kvo,
887  struct kmr_option opt);
888 extern int kmr_ranking(KMR_KVS *kvi, KMR_KVS *kvo, long *count,
889  struct kmr_option opt);
890 extern int kmr_distribute(KMR_KVS *kvi, KMR_KVS *kvo, _Bool cyclic,
891  struct kmr_option opt);
892 extern int kmr_shuffle_leveling_pair_count(KMR_KVS *kvi, KMR_KVS *kvo);
893 extern int kmr_scan_locally(KMR_KVS *kvi, KMR_KVS *carryin,
894  KMR_KVS *kvo, KMR_KVS *carryout, kmr_redfn_t r);
895 extern int kmr_scan_on_values(KMR_KVS *kvi, KMR_KVS *kvo,
896  KMR_KVS *total, kmr_redfn_t r);
897 extern int kmr_choose_first_part(KMR_KVS *kvi, KMR_KVS *kvo,
898  long n, struct kmr_option opt);
899 extern int kmr_legal_minimum_field_size(KMR *mr, enum kmr_kv_field f);
900 extern int kmr_histogram_count_by_ranks(KMR_KVS *kvs, long *frq, double *var,
901  _Bool rankzeroonly);
902 
903 extern int kmr_read_files_reassemble(KMR *mr, char *file, int color,
904  off_t offset, off_t bytes,
905  void **buffer, off_t *readsize);
906 extern int kmr_read_file_by_segments(KMR *mr, char *file, int color,
907  void **buffer, off_t *readsize);
908 
909 extern int kmr_retrieve_kvs_entries(KMR_KVS *kvs, struct kmr_kvs_entry **ev,
910  long n);
911 extern int kmr_retrieve_keyed_records(KMR_KVS *kvs,
912  struct kmr_keyed_record *ev,
913  long n, _Bool shuffling, _Bool ranking);
914 extern void kmr_dump_slot(union kmr_unit_sized e, int len,
915  enum kmr_kv_field data, char *buf, int buflen);
916 extern int kmr_dump_kv(struct kmr_kv_box kv, const KMR_KVS *kvs,
917  char *buf, int buflen);
918 extern int kmr_dump_kvs(KMR_KVS *kvs, int flag);
919 extern int kmr_dump_kvs_stats(KMR_KVS *, int level);
920 extern void kmr_dump_opaque(const char *p, int siz, char *buf, int buflen);
921 extern int kmr_dump_keyed_records(const struct kmr_keyed_record *ev,
922  KMR_KVS *kvi);
923 
924 extern void kmr_reset_ntuple(struct kmr_ntuple *u, int n, int marker);
925 extern int kmr_put_ntuple(KMR *mr, struct kmr_ntuple *u, const int sz,
926  const void *v, const int vlen);
927 extern int kmr_put_ntuple_long(KMR *mr, struct kmr_ntuple *u, const int sz,
928  long v);
929 extern int kmr_put_ntuple_entry(KMR *mr, struct kmr_ntuple *u, const int sz,
930  struct kmr_ntuple_entry e);
931 extern struct kmr_ntuple_entry kmr_nth_ntuple(struct kmr_ntuple *u, int nth);
932 extern int kmr_size_ntuple(struct kmr_ntuple *u);
933 extern int kmr_size_ntuple_by_lengths(int n, int len[]);
934 extern int kmr_add_ntuple(KMR_KVS *kvo, void *k, int klen,
935  struct kmr_ntuple *u);
936 
937 extern int kmr_separate_ntuples(KMR *mr,
938  const struct kmr_kv_box kv[], const long n,
939  struct kmr_ntuple **vv[2], long cnt[2],
940  int markers[2], _Bool disallow_other_entries);
941 extern int kmr_product_ntuples(KMR_KVS *kvo,
942  struct kmr_ntuple **vv[2], long cnt[2],
943  int newmarker,
944  int slots[][2], int nslots,
945  int keys[][2], int nkeys);
946 
947 extern KMR_KVS *kmr_create_pushoff_kvs(KMR *mr, enum kmr_kv_field kf,
948  enum kmr_kv_field vf,
949  struct kmr_option opt,
950  const char*, const int, const char*);
951 extern void kmr_print_statistics_on_pushoff(KMR *mr, char *titlestring);
952 extern void kmr_init_pushoff_fast_notice_(MPI_Comm, _Bool verbose);
953 extern void kmr_fin_pushoff_fast_notice_(void);
954 extern void kmr_check_pushoff_fast_notice_(KMR *mr);
955 
956 extern int kmr_assign_file(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt);
957 
958 /* Suppresses warnings of unused constants (for icc). */
959 
960 static inline void
961 kmr_dummy_dummy_dummy_(void)
962 {
963  (void)kmr_kvs_entry_header;
964  (void)kmr_kvs_block_header;
965  (void)kmr_noopt;
966  (void)kmr_optmask;
967  (void)kmr_fnoopt;
968  (void)kmr_foptmask;
969  (void)kmr_snoopt;
970  (void)kmr_soptmask;
971 }
972 
973 #ifdef __cplusplus
974 KMR_BR1
975 #endif
976 
977 #undef KMR_BR0
978 #undef KMR_BR1
979 
980 /*
981 Copyright (C) 2012-2016 RIKEN AICS
982 This library is distributed WITHOUT ANY WARRANTY. This library can be
983 redistributed and/or modified under the terms of the BSD 2-Clause License.
984 */
985 
986 #endif /*_KMR_H*/
int kmr_retrieve_keyed_records(KMR_KVS *kvs, struct kmr_keyed_record *ev, long n, _Bool shuffling, _Bool ranking)
Fills keyed records in an array for sorting.
Definition: kmrbase.c:2820
int kmr_map_serial_processes(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, MPI_Info info, struct kmr_spawn_option opt, kmr_mapfn_t mapfn)
Maps on processes started by MPI_Comm_spawn() to run serial processes.
Definition: kmrmapms.c:1945
Key-Value Stream (abstract).
Definition: kmr.h:587
int kmr_map_for_some(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps until some key-value are added.
Definition: kmrmoreops.c:1170
int kmr_map_file_names(KMR *mr, char **names, int n, struct kmr_file_option fopt, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps on file names.
Definition: kmrfiles.c:1372
Options to Mapping, Shuffling, and Reduction.
Definition: kmr.h:613
int kmr_file_enumerate(KMR *mr, char *names[], int n, KMR_KVS *kvo, struct kmr_file_option fopt)
Adds file names in a key-value stream KVO.
Definition: kmrfiles.c:1157
int kmr_add_kv(KMR_KVS *kvs, const struct kmr_kv_box kv)
Adds a key-value pair.
Definition: kmrbase.c:751
int kmr_unpairing(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Extracts a key-value pair from a pairing in the value part, discarding the original key...
Definition: kmrmoreops.c:234
KMR_KVS * kmr_create_pushoff_kvs(KMR *mr, enum kmr_kv_field kf, enum kmr_kv_field vf, struct kmr_option opt, const char *, const int, const char *)
Makes a new key-value stream with the specified field data-types.
Definition: kmraltkvs.c:85
void kmr_reset_ntuple(struct kmr_ntuple *u, int n, int marker)
Resets an n-tuple U with N entries and a MARKER.
Definition: kmrmoreops.c:1234
Spawning Info.
Definition: kmr.h:712
int kmr_size_ntuple_by_lengths(int n, int len[])
Returns the storage size of an n-tuple for N entries with LEN[i] size each.
Definition: kmrmoreops.c:1221
int kmr_find_key(KMR_KVS *kvi, struct kmr_kv_box ki, struct kmr_kv_box *vo)
Finds a key-value pair for a key.
Definition: kmrmoreops.c:43
int kmr_put_ntuple(KMR *mr, struct kmr_ntuple *u, const int sz, const void *v, const int vlen)
Adds an entry V with LEN in an n-tuple U whose size is limited to SIZE.
Definition: kmrmoreops.c:1252
int kmr_map_once(KMR_KVS *kvo, void *arg, struct kmr_option opt, _Bool rank_zero_only, kmr_mapfn_t m)
Maps once.
Definition: kmrbase.c:1402
int kmr_map9(_Bool stop_when_some_added, KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m, const char *, const int, const char *)
Maps simply.
Definition: kmrbase.c:1289
int kmr_scan_locally(KMR_KVS *kvi, KMR_KVS *carryin, KMR_KVS *kvo, KMR_KVS *carryout, kmr_redfn_t r)
Scans every key-value with a reduce-function locally (independently on each rank).
Definition: kmrbase.c:2880
int kmr_save_kvs(KMR_KVS *kvi, void **dataq, size_t *szq, struct kmr_option opt)
Packs locally the contents of a key-value stream to a byte array.
Definition: kmrbase.c:968
Key-Value Stream.
Definition: kmr.h:458
MPI_Comm * kmr_get_spawner_communicator(KMR *mr, long index)
Obtains (a reference to) a parent inter-communicator of a spawned process.
Definition: kmrmapms.c:1799
struct kmr_ntuple_entry kmr_nth_ntuple(struct kmr_ntuple *u, int nth)
Returns an NTH entry of an n-tuple.
Definition: kmrmoreops.c:1197
int kmr_shuffle(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Shuffles key-value pairs to the appropriate destination ranks.
Definition: kmrbase.c:2036
static const size_t kmr_kvs_entry_header
Size of an Entry Header.
Definition: kmr.h:382
int kmr_send_kvs_to_spawner(KMR *mr, KMR_KVS *kvs)
Sends the KVS from a spawned process to the map-function of the spawner.
Definition: kmrmapms.c:2005
int kmr_copy_to_array_fn(const struct kmr_kv_box kv, const KMR_KVS *kvi, KMR_KVS *kvo, void *arg, const long i)
Copies the entry in the array.
Definition: kmrutil.c:934
int kmr_retrieve_kvs_entries(KMR_KVS *kvs, struct kmr_kvs_entry **ev, long n)
Fills local key-value entries in an array for inspection.
Definition: kmrbase.c:2801
int kmr_reduce9(_Bool stop_when_some_added, KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_redfn_t r, const char *, const int, const char *)
Reduces key-value pairs.
Definition: kmrbase.c:2549
Keyed-Record for Sorting.
Definition: kmr.h:372
int kmr_distribute(KMR_KVS *kvi, KMR_KVS *kvo, _Bool cyclic, struct kmr_option opt)
Distributes key-values so that each rank has approximately the same number of pairs.
Definition: kmrmoreops.c:835
int kmr_add_kv_done(KMR_KVS *kvs)
Marks finished adding key-value pairs.
Definition: kmrbase.c:881
Definition: kmr.h:348
int kmr_reply_to_spawner(KMR *mr)
Sends a reply message in the spawned process, which tells it is ready to finish and may have some dat...
Definition: kmrmapms.c:1776
int kmr_add_ntuple(KMR_KVS *kvo, void *k, int klen, struct kmr_ntuple *u)
Adds an n-tuple U with a given key K and KLEN in a key-value stream KVO.
Definition: kmrmoreops.c:1295
int kmr_sort_by_one(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Sort by rank0, a degenerated case for small number of keys.
Definition: kmrmoreops.c:544
KMR Context.
Definition: kmr.h:222
int kmr_add_kv1(KMR_KVS *kvs, void *k, int klen, void *v, int vlen)
Adds a key-value pair as given directly by a pointer.
Definition: kmrbase.c:779
int kmr_concatenate_kvs(KMR_KVS *kvs[], int nkvs, KMR_KVS *kvo, struct kmr_option opt)
Concatenates a number of KVSes to one.
Definition: kmrbase.c:2696
int kmr_add_kv_space(KMR_KVS *kvs, const struct kmr_kv_box kv, void **keyp, void **valuep)
Adds a key-value pair, but only allocates a space and returns the pointers to the key and the value p...
Definition: kmrbase.c:843
int kmr_free_kvs(KMR_KVS *kvs)
Releases a key-value stream (type KMR_KVS).
Definition: kmrbase.c:621
int kmr_scan_on_values(KMR_KVS *kvi, KMR_KVS *kvo, KMR_KVS *total, kmr_redfn_t r)
Prefix-scans every key-value with a reduce-function (non-self-inclusively) and generates the final va...
Definition: kmrmoreops.c:943
int kmr_map_parallel_processes(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, MPI_Info info, struct kmr_spawn_option opt, kmr_mapfn_t mapfn)
Maps on processes started by MPI_Comm_spawn() to run independent MPI processes, which will not commun...
Definition: kmrmapms.c:1915
int kmr_find_string(KMR_KVS *kvi, const char *k, const char **vq)
Finds the key K in the key-value stream KVS.
Definition: kmrmoreops.c:73
void kmr_check_pushoff_fast_notice_(KMR *mr)
Check if fast-notice works.
Definition: kmraltkvs.c:808
int kmr_assign_file(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Assigns files to ranks based on data locality.
Definition: kmriolb.c:257
int kmr_copy_kvs_to_info(KMR_KVS *kvi, MPI_Info dst)
Copies kvs entires into mpi-info.
Definition: kmrutil.c:1034
int kmr_map_getline(KMR *mr, FILE *f, long limit, _Bool largebuffering, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Calls a map-function M for each line by getline() on an input F.
Definition: kmrfiles.c:1561
int kmr_read_file_by_segments(KMR *mr, char *file, int color, void **buffer, off_t *readsize)
Reads one file by segments and reassembles by all-gather.
Definition: kmrfiles.c:1021
kmr_kv_field
Datatypes of Keys or Values.
Definition: kmr.h:325
int kmr_reduce_for_some(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_redfn_t r)
Reduces until some key-value are added.
Definition: kmrmoreops.c:1183
int kmr_take_one(KMR_KVS *kvi, struct kmr_kv_box *kv)
Extracts a single key-value pair locally in the key-value stream KVI.
Definition: kmrbase.c:1369
int kmr_pairing(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Replaces a value part with a key-value pairing.
Definition: kmrmoreops.c:212
Handy Copy of a Key-Value Field.
Definition: kmr.h:358
int kmr_sort_large(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Sorts a key-value stream by the regular or the random sampling-sort.
Definition: kmrmoreops.c:469
void kmr_init_pushoff_fast_notice_(MPI_Comm, _Bool verbose)
Initializes RDMA for fast-notice.
Definition: kmraltkvs.c:726
int kmr_dump_kv(struct kmr_kv_box kv, const KMR_KVS *kvs, char *buf, int buflen)
Dumps contents of a key-value.
Definition: kmrutil.c:1585
int kmr_dump_kvs(KMR_KVS *kvs, int flag)
Dumps contents of a key-value stream to stdout.
Definition: kmrutil.c:1609
Options to Mapping by Spawns.
Definition: kmr.h:662
int kmr_fin(void)
Clears the environment.
Definition: kmrbase.c:124
Key-Value Stream with Shuffling at Addition of Key-Values.
Definition: kmr.h:542
int kmr_get_element_count(KMR_KVS *kvs, long *v)
Gets the total number of key-value pairs.
Definition: kmrmoreops.c:114
int kmr_move_kvs(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Moves the contents of the input KVI to the output KVO.
Definition: kmrbase.c:534
int kmr_sort(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Sorts a key-value stream globally.
Definition: kmrmoreops.c:575
int kmr_dump_kvs_stats(KMR_KVS *, int level)
Dumps contents of a key-value stream, with values are pairs.
Definition: kmrutil.c:1659
int kmr_size_ntuple(struct kmr_ntuple *u)
Returns the storage size of an n-tuple.
Definition: kmrmoreops.c:1211
int kmr_separate_ntuples(KMR *mr, const struct kmr_kv_box kv[], const long n, struct kmr_ntuple **vv[2], long cnt[2], int markers[2], _Bool disallow_other_entries)
Separates the n-tuples stored in the value part of KV into the two sets by their marker values...
Definition: kmrmoreops.c:1318
State during kmr_map_ms().
Definition: kmr.h:408
int kmr_put_ntuple_long(KMR *mr, struct kmr_ntuple *u, const int sz, long v)
Adds an integer value in an n-tuple U whose size is limited to SIZE.
Definition: kmrmoreops.c:1274
int kmr_match(KMR_KVS *kvi0, KMR_KVS *kvi1, KMR_KVS *kvo, struct kmr_option opt)
Makes key-value pairs as products of the two values in two key-value stream.
Definition: kmrmoreops.c:696
int kmr_map_skipping(long from, long stride, long limit, _Bool stop_when_some_added, KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps by skipping the number of entries.
Definition: kmrbase.c:1134
int kmr_product_ntuples(KMR_KVS *kvo, struct kmr_ntuple **vv[2], long cnt[2], int newmarker, int slots[][2], int nslots, int keys[][2], int nkeys)
Makes a direct product of the two sets of n-tuples VV[0] and VV[1] with their counts in CNT[0] and CN...
Definition: kmrmoreops.c:1528
void kmr_dump_opaque(const char *p, int siz, char *buf, int buflen)
Puts the string of the key or value field into a buffer BUF as printable string.
Definition: kmrutil.c:1511
int kmr_map_ms_commands(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, struct kmr_spawn_option sopt, kmr_mapfn_t m)
Maps in master-slave mode, specialized to run serial commands.
Definition: kmrmapms.c:2198
int kmr_shuffle_leveling_pair_count(KMR_KVS *kvi, KMR_KVS *kvo)
Shuffles key-values so that each rank has approximately the same number of pairs. ...
Definition: kmrmoreops.c:1074
int kmr_read_files_reassemble(KMR *mr, char *file, int color, off_t offset, off_t bytes, void **buffer, off_t *readsize)
Reassembles files reading by ranks.
Definition: kmrfiles.c:653
int kmr_map_via_spawn(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, MPI_Info info, struct kmr_spawn_option opt, kmr_mapfn_t mapfn)
Maps on processes started by MPI_Comm_spawn().
Definition: kmrmapms.c:1870
int kmr_histogram_count_by_ranks(KMR_KVS *kvs, long *frq, double *var, _Bool rankzeroonly)
Fills an integer array FRQ[i] with the count of the elements of each rank.
Definition: kmrmoreops.c:1569
int kmr_ranking(KMR_KVS *kvi, KMR_KVS *kvo, long *count, struct kmr_option opt)
Assigns a ranking to key-value pairs, and returns the number of the total elements in COUNT...
Definition: kmrmoreops.c:764
int kmr_restore_kvs(KMR_KVS *kvo, void *data, size_t sz, struct kmr_option opt)
Unpacks locally the contents of a key-value stream from a byte array.
Definition: kmrbase.c:1034
int kmr_free_context(KMR *mr)
Releases a context created with kmr_create_context().
Definition: kmrbase.c:326
int kmr_add_identity_fn(const struct kmr_kv_box kv, const KMR_KVS *kvi, KMR_KVS *kvo, void *arg, const long i)
Adds a given key-value pair unmodified.
Definition: kmrbase.c:937
int kmr_map_ms(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps in master-slave mode.
Definition: kmrmapms.c:310
int kmr_map_rank_by_rank(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_mapfn_t m)
Maps sequentially with rank by rank for debugging.
Definition: kmrbase.c:1339
int kmr_legal_minimum_field_size(KMR *mr, enum kmr_kv_field f)
Returns a minimum byte size of the field: 8 for INTEGER and FLOAT8, 0 for others. ...
Definition: kmrbase.c:2847
Options to Mapping on Files.
Definition: kmr.h:638
Unit-Sized Storage.
Definition: kmr.h:340
int kmr_replicate(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Replicates key-value pairs to be visible on all ranks, that is, it has the effect of bcast or all-gat...
Definition: kmrbase.c:2182
int kmr_sort_small(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Sorts a key-value stream, by partitioning to equal ranges.
Definition: kmrmoreops.c:388
int kmr_add_string(KMR_KVS *kvs, const char *k, const char *v)
Adds a key-value pair of strings.
Definition: kmrbase.c:913
int kmr_put_ntuple_entry(KMR *mr, struct kmr_ntuple *u, const int sz, struct kmr_ntuple_entry e)
Adds an n-tuple entry E in an n-tuple U whose size is limited to SIZE.
Definition: kmrmoreops.c:1284
Key-Value Stream (DUMMY); Mandatory Entries.
Definition: kmr.h:568
int kmr_receive_kvs_from_spawned_fn(const struct kmr_kv_box kv, const KMR_KVS *kvi, KMR_KVS *kvo, void *arg, const long index)
Collects key-value pairs generated by spawned processes.
Definition: kmrmapms.c:2039
int kmr_sort_locally(KMR_KVS *kvi, KMR_KVS *kvo, _Bool shuffling, struct kmr_option opt)
Reorders key-value pairs in a single rank.
Definition: kmrbase.c:1993
N-Tuple.
Definition: kmr.h:731
int kmr_reduce_as_one(KMR_KVS *kvi, KMR_KVS *kvo, void *arg, struct kmr_option opt, kmr_redfn_t r)
Calls a reduce-function once as if all key-value pairs had the same key.
Definition: kmrbase.c:2625
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_local_element_count(KMR_KVS *kvs, long *v)
Gets the number of key-value pairs locally on each rank.
Definition: kmrutil.c:349
KMR_KVS * kmr_create_kvs7(KMR *mr, enum kmr_kv_field k, enum kmr_kv_field v, struct kmr_option opt, const char *, const int, const char *)
Makes a new key-value stream with the specified field data-types.
Definition: kmrbase.c:510
int kmr_reverse(KMR_KVS *kvi, KMR_KVS *kvo, struct kmr_option opt)
Makes a new pair by swapping the key and the value in each pair.
Definition: kmrmoreops.c:159
N-Tuple Argument.
Definition: kmr.h:740
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
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
Record of Push-Off Key-Value Stream for a Rank.
Definition: kmr.h:525
int kmr_copy_info_to_kvs(MPI_Info src, KMR_KVS *kvo)
Copies mpi-info entires into kvs.
Definition: kmrutil.c:982
int kmr_choose_first_part(KMR_KVS *kvi, KMR_KVS *kvo, long n, struct kmr_option opt)
Chooses the first N entries from a key-value stream KVI.
Definition: kmrmoreops.c:1145
int kmr_map_processes(_Bool nonmpi, KMR_KVS *kvi, KMR_KVS *kvo, void *arg, MPI_Info info, struct kmr_spawn_option opt, kmr_mapfn_t mapfn)
Maps on processes started by MPI_Comm_spawn() to run independent processes.
Definition: kmrmapms.c:1965
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