23 #include <sys/types.h> 25 #include <sys/resource.h> 29 #define MIN(a,b) (((a)<(b))?(a):(b)) 30 #define MAX(a,b) (((a)>(b))?(a):(b)) 35 int kmr_kv_field_bad = KMR_KV_BAD;
36 int kmr_kv_field_opaque = KMR_KV_OPAQUE;
37 int kmr_kv_field_cstring = KMR_KV_CSTRING;
38 int kmr_kv_field_integer = KMR_KV_INTEGER;
39 int kmr_kv_field_float8 = KMR_KV_FLOAT8;
40 int kmr_kv_field_pointer_owned = KMR_KV_POINTER_OWNED;
41 int kmr_kv_field_pointer_unmanaged = KMR_KV_POINTER_UNMANAGED;
48 kmr_warning(
KMR *mr,
unsigned int mask,
char *m)
50 assert(1 <= mask && mask <= 9);
55 print = (mask <= mr->verbosity);
57 int cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
58 assert(cc == MPI_SUCCESS);
63 fprintf(stderr,
";;KMR [%05d] warning: %s.\n", rank, m);
76 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
81 fprintf(stderr,
";;KMR [%05d] error: %s: %s; at %s:%d\n",
82 rank, site->func, m, site->file, site->line);
85 fprintf(stderr,
";;KMR [%05d] error: %s.\n", rank, m);
89 if (mr != 0 && mr->std_abort) {
92 (void)MPI_Abort(MPI_COMM_WORLD, 1);
99 kmr_error(
KMR *mr,
char *m)
101 kmr_error_at_site(mr, m, 0);
105 kmr_error2(
KMR *mr,
char *m,
106 const char *file,
const int line,
const char *func)
108 struct kmr_code_line site = {.file = file, .line = line, .func = func};
109 kmr_error_at_site(mr, m, &site);
113 kmr_error_kvs_at_site(
KMR *mr,
char *m,
KMR_KVS *kvs,
120 int cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
121 assert(cc == MPI_SUCCESS);
124 if (site != 0 && kvs->c.info_line0.file != 0) {
126 fprintf(stderr,
";;KMR [%05d] error: %s: %s" 127 " (kvs allocated at %s:%d: %s); at %s:%d\n",
128 rank, site->func, m, info->file, info->line, info->func,
129 site->file, site->line);
131 }
else if (kvs->c.info_line0.file != 0) {
133 fprintf(stderr,
";;KMR [%05d] error: %s" 134 " (kvs allocated at %s:%d: %s)\n",
135 rank, m, info->file, info->line, info->func);
137 }
else if (site != 0) {
138 fprintf(stderr,
";;KMR [%05d] error: %s: %s; at %s:%d\n",
139 rank, site->func, m, site->file, site->line);
142 fprintf(stderr,
";;KMR [%05d] error: %s\n",
147 if (mr != 0 && mr->std_abort) {
150 (void)MPI_Abort(MPI_COMM_WORLD, 1);
157 kmr_error_kvs_at_site(mr, m, kvs, 0);
161 kmr_error_kvs2(
KMR *mr,
char *m,
KMR_KVS *kvs,
162 const char *file,
const int line,
const char *func)
164 struct kmr_code_line site = {.file = file, .line = line, .func = func};
165 kmr_error_kvs_at_site(mr, m, kvs, &site);
169 kmr_error_mpi(
KMR *mr,
char *m,
int errorcode)
175 int cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
176 assert(cc == MPI_SUCCESS);
180 char s[MPI_MAX_ERROR_STRING];
181 int cc = MPI_Error_string(errorcode, s, &len);
182 if (cc != MPI_SUCCESS) {
183 snprintf(s, MPI_MAX_ERROR_STRING,
"(unknown MPI error)");
185 fprintf(stderr,
";;KMR [%05d] %s: %s\n", rank, m, s);
196 size_t m = strlen(s);
201 assert(s[sz - 1] == 0);
214 kmr_ptrstr_ff(
char *s)
220 kmr_ptrint_ff(
void *p)
226 kmr_intptr_ff(
long p)
232 kmr_dblint_ff(
double v)
234 union {
double d;
long i;} vv = {.d = v};
239 kmr_intdbl_ff(
long v)
241 union {
double d;
long i;} vv = {.i = v};
246 kmr_strint_ff(
char *p)
249 return (
long)(
void *)p;
261 memcpy(s, x, (
size_t)n);
262 return (
int)strnlen(x, (
size_t)n);
265 static inline unsigned long 266 kmr_bitreverse(
unsigned long bits)
268 bits = (((bits & 0xaaaaaaaaaaaaaaaaUL) >> 1)
269 | ((bits & 0x5555555555555555UL) << 1));
270 bits = (((bits & 0xccccccccccccccccUL) >> 2)
271 | ((bits & 0x3333333333333333UL) << 2));
272 bits = (((bits & 0xf0f0f0f0f0f0f0f0UL) >> 4)
273 | ((bits & 0x0f0f0f0f0f0f0f0fUL) << 4));
274 bits = (((bits & 0xff00ff00ff00ff00UL) >> 8)
275 | ((bits & 0x00ff00ff00ff00ffUL) << 8));
276 bits = (((bits & 0xffff0000ffff0000UL) >> 16)
277 | ((bits & 0x0000ffff0000ffffUL) << 16));
278 return ((bits >> 32) | (bits << 32));
286 static union {
struct {_Bool b : 1;} s;
unsigned long i;}
287 kmr_bitpos0 = {.s={.b=1}};
288 assert(kmr_bitpos0.i == 1 || kmr_bitpos0.i == 0x8000000000000000UL);
289 unsigned long optionbits;
290 if (kmr_bitpos0.i == 1) {
295 optionbits = kmr_bitreverse(b);
297 unsigned long optionmask = (kmr_optmask.bits
299 | kmr_soptmask.bits);
300 assert((optionbits & ~optionmask) == 0);
305 kmr_get_nprocs(
const KMR *mr)
312 kmr_get_rank(
const KMR *mr)
319 kmr_get_nprocs_ff(
const KMR_KVS *kvs)
322 return kvs->c.mr->nprocs;
326 kmr_get_rank_ff(
const KMR_KVS *kvs)
329 return kvs->c.mr->rank;
333 kmr_get_key_type_ff(
const KMR_KVS *kvs)
336 return kvs->c.key_data;
340 kmr_get_value_type_ff(
const KMR_KVS *kvs)
343 return kvs->c.value_data;
351 kmr_assert_kvs_ok(kvs, 0, 1, 0);
353 *v = kvs->c.element_count;
364 return "nothreading";
365 }
else if (o.inspect) {
367 }
else if (o.keep_open) {
369 }
else if (o.key_as_rank) {
370 return "key_as_rank";
371 }
else if (o.rank_zero) {
373 }
else if (o.collapse) {
375 }
else if (o.take_ckpt) {
390 }
else if (o.subdirectories) {
391 return "subdirectories";
392 }
else if (o.list_file) {
394 }
else if (o.shuffle_names) {
395 return "shuffle_names";
407 if (o.separator_space) {
408 return "separator_space";
409 }
else if (o.reply_each) {
411 }
else if (o.reply_root) {
413 }
else if (o.one_by_one) {
415 }
else if (o.take_ckpt) {
428 int cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
429 assert(cc == MPI_SUCCESS);
431 p[1] = (
unsigned short)rank;
444 int cc = kmr_k_node_by_rank(mr, p);
448 int cc = kmr_k_node_by_rank(mr, p);
455 int x, y, z, a, b, c;
456 cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
457 assert(cc == MPI_SUCCESS);
458 cc = FJMPI_Topology_sys_rank2xyzabc(rank, &x, &y, &z, &a, &b, &c);
459 assert(cc == MPI_SUCCESS);
460 p[0] = (
unsigned short)x;
461 p[1] = (
unsigned short)y;
462 p[2] = (
unsigned short)z;
463 p[3] = (
unsigned short)((a << 4) | (b << 2) | c);
464 printf(
"[%05d] Coord x=%d, y=%d, z=%d, a=%d, b=%d, c=%d\n",
465 rank, x, y, z, a, b, c);
470 int cc = kmr_k_node_by_rank(mr, p);
473 char *tofupos =
"/proc/tofu/position";
477 fd = open(tofupos, O_RDONLY, 0);
478 }
while (fd == -1 && errno == EINTR);
481 char *m = strerror(errno);
482 snprintf(ee, 80,
"open(%s): %s", tofupos, m);
487 while (rc <
sizeof(buf)) {
490 cx = read(fd, &buf[rc], (
sizeof(buf) - rc));
491 }
while (cx == -1 && errno == EINTR);
497 char *m = strerror(errno);
498 snprintf(ee, 80,
"read(%s): %s", tofupos, m);
505 }
while (cc == -1 && errno == EINTR);
506 assert(rc > 18 && rc <
sizeof(buf));
508 unsigned int x, y, z, a, b, c;
510 cc = sscanf(buf,
"TOFU NODE ADDRESS:%d,%d,%d,%d,%d,%d%c%c",
511 &x, &y, &z, &a, &b, &c, &nl, &gomi);
512 assert(cc == 7 && nl ==
'\n');
513 assert(a <= 1 && b <= 2 && c <= 1);
517 p[3] = ((a << 4) | (b << 2) | c);
537 #ifdef CLOCK_REALTIME 538 static double t0 = 0.0;
542 cc = clock_getres(CLOCK_REALTIME, &ts);
544 double timerres = (double)ts.tv_sec + ((
double)ts.tv_nsec * 1e-9);
546 assert(timerres <= 1e-4);
547 cc = clock_gettime(CLOCK_REALTIME, &ts);
549 t0 = (double)ts.tv_sec + ((
double)ts.tv_nsec * 1e-9);
552 cc = clock_gettime(CLOCK_REALTIME, &ts);
554 double t1 = (double)ts.tv_sec + ((
double)ts.tv_nsec * 1e-9);
565 kmr_bsearch(
const void *key,
const void *base,
size_t nel,
size_t size,
566 int (*compar)(
const void *,
const void *))
568 assert(key != 0 && base != 0 && compar != 0);
569 const char *lb = base;
572 const char *p = lb + (w >> 1) * size;
573 int r = (*compar)(key, p);
597 char *m = strerror(errno);
598 snprintf(ee, 80,
"strdup(%s): %s", s, m);
615 }
while (f == 0 && errno == EINTR);
628 }
while (c == EOF && errno == EINTR);
639 cc = getrlimit(RLIMIT_NOFILE, &r);
643 char *m = strerror(errno);
644 snprintf(ee,
sizeof(ee),
"getrlimit(RLIMIT_NOFILE) failed: %s", m);
645 kmr_warning(mr, 5, ee);
654 kmr_parse_int(
char *s,
int *r)
657 char gomi[
sizeof(int)];
658 int cc = sscanf(s,
"%d%c", &v, gomi);
659 if (cc == 1 && r != 0) {
666 kmr_parse_boolean(
char *s,
int *r)
670 char gomi[
sizeof(int)];
671 if (strcasecmp(s,
"true") == 0) {
673 }
else if (strcasecmp(s,
"false") == 0) {
675 }
else if (sscanf(s,
"%d%c", &vv, gomi) == 1) {
676 if (vv == 0 || vv == 1) {
680 if (v != -1 && r != 0) {
687 kmr_parse_size_t(
char *s,
size_t *r)
690 char gomi[
sizeof(int)];
691 int cc = sscanf(s,
"%ld%c", &v, gomi);
692 if (cc == 1 && r != 0) {
708 kmr_sorter_t cmp = kmr_choose_sorter(kvi);
714 struct kmr_option rankzero = {.rank_zero = 1};
716 assert(cc == MPI_SUCCESS);
718 if (locally || rank == 0) {
719 long cnt = kvs1->c.element_count;
720 size_t evsz = (
sizeof(
struct kmr_kvs_entry *) * (
size_t)cnt);
723 assert(cc == MPI_SUCCESS);
724 for (
long i = 1; i < cnt; i++) {
728 assert(cmp(&b0, &b1) <= 0);
732 int r0 = (ranking ? (int)b0.k.i : kmr_pitch_rank(b0, kvs1));
733 int r1 = (ranking ? (int)b1.k.i : kmr_pitch_rank(b1, kvs1));
742 assert(cc == MPI_SUCCESS);
762 kmr_scan_argv_strings(
KMR *mr,
char *s,
size_t len,
int maxargc,
763 int *argc,
char **argv, _Bool ws,
char *msg)
765 assert(s != 0 && len > 0);
766 assert(argc != 0 || argv != 0);
767 assert((maxargc != 0) == (argv != 0));
768 assert(!isblank(
'\0'));
769 if (s[len - 1] != 0) {
771 snprintf(ee,
sizeof(ee), (
"%s: argument strings" 772 " not terminated with a null"), msg);
776 _Bool counting = (argv == 0);
777 char *
const lim = &s[len - 1];
781 while (p < lim && (ws && isblank(*p))) {
787 if (!counting && index < (maxargc - 1)) {
791 while (p < lim && !(*p == 0 || (ws && isblank(*p)))) {
795 if (!counting && *p != 0) {
796 assert(ws && isblank(*p));
804 if (!counting && index > (maxargc - 1)) {
806 snprintf(ee,
sizeof(ee),
807 (
"%s: argument count exceeds the limit (%d)"), msg, maxargc);
810 if (!counting && index < maxargc) {
824 kmr_msleep(
int msec,
int interval)
826 assert(msec >= 1 && interval >= 1);
827 int gap = MIN(msec, interval);
828 double t0 = MPI_Wtime();
829 double t1 = (t0 + 1e-3 * msec);
834 int cc = MPI_Testany(0, 0, &index, &ok, &st);
835 assert(cc == MPI_SUCCESS);
836 double t2 = MPI_Wtime();
840 usleep((useconds_t)(gap * 1000));
850 kmr_mfree(
void *p,
size_t sz)
859 kmr_mpi_type_size(
char *s)
861 if (strcasecmp(s,
"MPI_Group") == 0) {
862 return sizeof(MPI_Group);
863 }
else if (strcasecmp(s,
"MPI_Comm") == 0) {
864 return sizeof(MPI_Comm);
865 }
else if (strcasecmp(s,
"MPI_Datatype") == 0) {
866 return sizeof(MPI_Datatype);
867 }
else if (strcasecmp(s,
"MPI_Request") == 0) {
868 return sizeof(MPI_Request);
869 }
else if (strcasecmp(s,
"MPI_Op") == 0) {
870 return sizeof(MPI_Op);
871 }
else if (strcasecmp(s,
"MPI_Errhandler") == 0) {
872 return sizeof(MPI_Errhandler);
873 }
else if (strcasecmp(s,
"MPI_Info") == 0) {
874 return sizeof(MPI_Info);
877 snprintf(ee,
sizeof(ee),
878 "kmr_mpi_type_size() unknown name (%s)", s);
879 kmr_warning(0, 5, ee);
888 kmr_mpi_constant_value(
char *s)
890 assert(
sizeof(MPI_Group) <=
sizeof(uint64_t)
891 &&
sizeof(MPI_Comm) <=
sizeof(uint64_t)
892 &&
sizeof(MPI_Datatype) <=
sizeof(uint64_t)
893 &&
sizeof(MPI_Request) <=
sizeof(uint64_t)
894 &&
sizeof(MPI_Op) <=
sizeof(uint64_t)
895 &&
sizeof(MPI_Errhandler) <=
sizeof(uint64_t)
896 &&
sizeof(MPI_Info) <=
sizeof(uint64_t));
898 if (strcasecmp(s,
"MPI_COMM_WORLD") == 0) {
899 return (uint64_t)MPI_COMM_WORLD;
900 }
else if (strcasecmp(s,
"MPI_COMM_SELF") == 0) {
901 return (uint64_t)MPI_COMM_SELF;
902 }
else if (strcasecmp(s,
"MPI_COMM_NULL") == 0) {
903 return (uint64_t)MPI_COMM_NULL;
904 }
else if (strcasecmp(s,
"MPI_GROUP_NULL") == 0) {
905 return (uint64_t)MPI_GROUP_NULL;
906 }
else if (strcasecmp(s,
"MPI_DATATYPE_NULL") == 0) {
907 return (uint64_t)MPI_DATATYPE_NULL;
908 }
else if (strcasecmp(s,
"MPI_REQUEST_NULL") == 0) {
909 return (uint64_t)MPI_REQUEST_NULL;
910 }
else if (strcasecmp(s,
"MPI_OP_NULL") == 0) {
911 return (uint64_t)MPI_OP_NULL;
912 }
else if (strcasecmp(s,
"MPI_ERRHANDLER_NULL") == 0) {
913 return (uint64_t)MPI_ERRHANDLER_NULL;
914 }
else if (strcasecmp(s,
"MPI_GROUP_EMPTY") == 0) {
915 return (uint64_t)MPI_GROUP_EMPTY;
916 }
else if (strcasecmp(s,
"MPI_INFO_NULL") == 0) {
917 return (uint64_t)MPI_INFO_NULL;
920 snprintf(ee,
sizeof(ee),
921 "kmr_mpi_constant_value() unknown name (%s)", s);
922 kmr_warning(0, 5, ee);
946 kmr_imax_one_fn(
const struct kmr_kv_box kv[],
const long n,
952 for (
long i = 0; i < n; i++) {
961 kmr_isum_one_fn(
const struct kmr_kv_box kv[],
const long n,
967 for (
long i = 0; i < n; i++) {
984 kmr_assert_kvs_ok(0, kvo, 0, 1);
985 assert(src != MPI_INFO_NULL);
988 char key[MPI_MAX_INFO_KEY + 1];
989 char value[MPI_MAX_INFO_VAL + 1];
990 cc = MPI_Info_get_nkeys(src, &nkeys);
991 assert(cc == MPI_SUCCESS);
992 for (
int i = 0; i < nkeys; i++) {
995 cc = MPI_Info_get_nthkey(src, i, key);
996 assert(cc == MPI_SUCCESS);
997 cc = MPI_Info_get_valuelen(src, key, &vlen, &flag);
998 assert(cc == MPI_SUCCESS && flag != 0);
999 assert(vlen <= MPI_MAX_INFO_VAL);
1000 cc = MPI_Info_get(src, key, MPI_MAX_INFO_VAL, value, &flag);
1001 assert(cc == MPI_SUCCESS && flag != 0);
1003 assert(cc == MPI_SUCCESS);
1006 assert(cc == MPI_SUCCESS);
1015 MPI_Info dst = *dstp;
1016 char *k = (
char *)kv.k.p;
1017 char *v = (
char *)kv.v.p;
1019 kmr_warning(0, 5,
"empty key string for MPI_Info_set(), ignored");
1020 }
else if (v[0] == 0) {
1022 kmr_warning(0, 5,
"empty value string for MPI_Info_set(), ignored");
1024 int cc = MPI_Info_set(dst, (
char *)kv.k.p, (
char *)kv.v.p);
1025 assert(cc == MPI_SUCCESS);
1036 kmr_assert_kvs_ok(kvi, 0, 1, 0);
1038 struct kmr_option nothreading = {.nothreading = 1};
1039 cc =
kmr_map(kvi, 0, &dst, nothreading, kmr_set_info_fn);
1040 assert(cc == MPI_SUCCESS);
1049 kmr_load_preference(
KMR *mr, MPI_Info info)
1053 cc = MPI_Info_create(&inforank0);
1054 assert(cc == MPI_SUCCESS);
1056 if (mr->rank == 0) {
1057 char *name = getenv(
"KMROPTION");
1062 if (cc != MPI_SUCCESS) {
1069 assert(cc == MPI_SUCCESS);
1072 assert(cc == MPI_SUCCESS);
1074 assert(cc == MPI_SUCCESS);
1075 MPI_Info_free(&inforank0);
1078 snprintf(ee,
sizeof(ee),
"[%05d]", mr->rank);
1079 printf(
"%s dumpinfo info...\n", ee);
1090 kmr_check_options(
KMR *mr, MPI_Info info)
1095 if (info == MPI_INFO_NULL) {
1098 cc = MPI_Info_get_nkeys(info, &n);
1099 assert(cc == MPI_SUCCESS);
1102 for (
int i = 0; i < n; i++) {
1103 char k[MPI_MAX_INFO_KEY + 1];
1104 char v[MPI_MAX_INFO_VAL + 1];
1106 cc = MPI_Info_get_nthkey(info, i, k);
1107 assert(cc == MPI_SUCCESS);
1108 cc = MPI_Info_get(info, k, MPI_MAX_INFO_VAL, v, &flag);
1109 assert(cc == MPI_SUCCESS && flag != 0);
1111 kmr_set_option_by_strings(mr, k, v);
1114 snprintf(ee, 80,
"option \"%s\" ignored", k);
1115 kmr_warning(mr, 1, ee);
1119 if (mr->verbosity == 9) {
1121 printf(
"[%05d] Dumping KMR options:\n", r);
1122 printf(
"[%05d] verbosity=%d\n", r, mr->verbosity);
1123 printf(
"[%05d] sort_threads_depth=%d\n", r, mr->sort_threads_depth);
1124 printf(
"[%05d] onk=%d\n", r, mr->onk);
1125 printf(
"[%05d] atoa_threshold=%ld\n", r, mr->atoa_threshold);
1126 printf(
"[%05d] single_thread=%d\n", r, mr->single_thread);
1127 printf(
"[%05d] step_sync=%d\n", r, mr->step_sync);
1128 printf(
"[%05d] trace_file_io=%d\n", r, mr->trace_file_io);
1129 printf(
"[%05d] trace_map_ms=%d\n", r, mr->trace_map_ms);
1130 printf(
"[%05d] trace_map_spawn=%d\n", r, mr->trace_map_spawn);
1131 printf(
"[%05d] trace_alltoall=%d\n", r, mr->trace_alltoall);
1132 printf(
"[%05d] trace_kmrdp=%d\n", r, mr->trace_kmrdp);
1133 printf(
"[%05d] std_abort=%d\n", r, mr->std_abort);
1134 printf(
"[%05d] log_traces=%d\n", r, (mr->log_traces != 0));
1135 printf(
"[%05d] ckpt_enable=%d\n", r, mr->ckpt_enable);
1136 printf(
"[%05d] ckpt_selective=%d\n", r, mr->ckpt_selective);
1137 printf(
"[%05d] ckpt_no_fsync=%d\n", r, mr->ckpt_no_fsync);
1138 printf(
"[%05d] pushoff_block_size=%zd\n", r, mr->pushoff_block_size);
1139 printf(
"[%05d] pushoff_poll_rate=%d\n", r, mr->pushoff_poll_rate);
1140 printf(
"[%05d] pushoff_fast_notice=%d\n", r, mr->pushoff_fast_notice);
1141 printf(
"[%05d] kmrviz_trace=%d\n", r, mr->kmrviz_trace);
1149 kmr_set_option_by_strings(
KMR *mr,
char *k,
char *v)
1152 if (strcasecmp(
"log_traces", k) == 0) {
1153 if (kmr_parse_boolean(v, &x)) {
1154 if (mr->log_traces == 0) {
1158 kmr_warning(mr, 1,
"option log_traces be boolean");
1160 }
else if (strcasecmp(
"sort_threads_depth", k) == 0) {
1161 if (kmr_parse_int(v, &x) && x >= 0) {
1162 mr->sort_threads_depth = x;
1164 kmr_warning(mr, 1, (
"option sort_threads_depth be" 1165 " non-negative integer"));
1167 }
else if (strcasecmp(
"verbosity", k) == 0) {
1168 if (kmr_parse_int(v, &x) && (1 <= x && x <= 9)) {
1169 mr->verbosity = (uint8_t)x;
1171 kmr_warning(mr, 1,
"option verbosity be 1-9");
1173 }
else if (strcasecmp(
"k", k) == 0) {
1174 if (kmr_parse_boolean(v, &x)) {
1177 kmr_warning(mr, 1,
"option k be boolean");
1179 }
else if (strcasecmp(
"single_thread", k) == 0) {
1180 if (kmr_parse_boolean(v, &x)) {
1181 mr->single_thread = (_Bool)x;
1183 kmr_warning(mr, 1,
"option single_thread be boolean");
1185 }
else if (strcasecmp(
"step_sync", k) == 0) {
1186 if (kmr_parse_boolean(v, &x)) {
1187 mr->step_sync = (_Bool)x;
1189 kmr_warning(mr, 1,
"option step_sync be boolean");
1191 }
else if (strcasecmp(
"trace_file_io", k) == 0) {
1192 if (kmr_parse_boolean(v, &x)) {
1193 mr->trace_file_io = (_Bool)x;
1195 kmr_warning(mr, 1,
"option trace_file_io be boolean");
1197 }
else if (strcasecmp(
"trace_map_ms", k) == 0) {
1198 if (kmr_parse_boolean(v, &x)) {
1199 mr->trace_map_ms = (_Bool)x;
1201 kmr_warning(mr, 1,
"option trace_map_ms be boolean");
1203 }
else if (strcasecmp(
"trace_map_spawn", k) == 0) {
1204 if (kmr_parse_boolean(v, &x)) {
1205 mr->trace_map_spawn = (_Bool)x;
1207 kmr_warning(mr, 1,
"option trace_map_spawn be boolean");
1209 }
else if (strcasecmp(
"std_abort", k) == 0) {
1210 if (kmr_parse_boolean(v, &x)) {
1211 mr->std_abort = (_Bool)x;
1213 kmr_warning(mr, 1,
"option std_abort be boolean");
1215 }
else if (strcasecmp(
"trace_alltoall", k) == 0) {
1216 if (kmr_parse_boolean(v, &x)) {
1217 mr->trace_alltoall = (_Bool)x;
1219 kmr_warning(mr, 1,
"option trace_alltoall be boolean");
1221 }
else if (strcasecmp(
"atoa_threshold", k) == 0) {
1222 if (kmr_parse_int(v, &x) && x >= 0) {
1223 mr->atoa_threshold = x;
1225 kmr_warning(mr, 1, (
"option atoa_threshold be" 1226 " non-negative integer"));
1228 }
else if (strcasecmp(
"spawn_max_processes", k) == 0) {
1229 if (kmr_parse_int(v, &x) && x >= 0) {
1230 mr->spawn_max_processes = x;
1232 kmr_warning(mr, 1, (
"option spawn_max_processes be" 1233 " non-negative integer"));
1235 }
else if (strcasecmp(
"ckpt_enable", k) == 0) {
1236 if (kmr_parse_boolean(v, &x)) {
1237 mr->ckpt_enable = (_Bool)x;
1239 kmr_warning(mr, 1,
"option ckpt_enable be boolean");
1241 }
else if (strcasecmp(
"ckpt_selective", k) == 0) {
1242 if (kmr_parse_boolean(v, &x)) {
1243 mr->ckpt_selective = (_Bool)x;
1245 kmr_warning(mr, 1,
"option ckpt_selective be boolean");
1247 }
else if (strcasecmp(
"ckpt_no_fsync", k) == 0) {
1248 if (kmr_parse_boolean(v, &x)) {
1249 mr->ckpt_no_fsync = (_Bool)x;
1251 kmr_warning(mr, 1,
"option ckpt_no_fsync be boolean");
1253 }
else if (strcasecmp(
"pushoff_block_size", k) == 0) {
1255 if (kmr_parse_size_t(v, &z)) {
1256 mr->pushoff_block_size = z;
1258 }
else if (strcasecmp(
"pushoff_poll_rate", k) == 0) {
1259 if (kmr_parse_int(v, &x)) {
1260 mr->pushoff_poll_rate = x;
1262 }
else if (strcasecmp(
"pushoff_fast_notice", k) == 0) {
1263 if (kmr_parse_boolean(v, &x)) {
1264 mr->pushoff_fast_notice = (_Bool)x;
1266 kmr_warning(mr, 1,
"option pushoff_fast_notice be boolean");
1268 }
else if (strcasecmp(
"kmrviz_trace", k) == 0) {
1269 if (kmr_parse_boolean(v, &x)) {
1270 mr->kmrviz_trace = (_Bool)x;
1272 kmr_warning(mr, 1,
"option kmrviz_trace be boolean");
1276 snprintf(ee, 80,
"option \"%s\" ignored", k);
1277 kmr_warning(mr, 1, ee);
1289 kmr_check_command_existence(
KMR *mr,
char *command, _Bool search,
char *msg)
1293 _Bool tracing7 = (mr->trace_map_spawn && (7 <= mr->verbosity));
1296 fprintf(stderr, (
";;KMR [%05d] %s:" 1297 " checking a watch-program: %s\n"),
1298 mr->rank, msg, command);
1302 cc = access(command, X_OK);
1303 }
while (cc != 0 && errno == EINTR);
1304 if (cc != 0 && !(errno == ENOENT || errno == EACCES)) {
1306 char *m = strerror(errno);
1307 snprintf(ee,
sizeof(ee),
"access() returned: %s", m);
1308 kmr_warning(mr, 1, ee);
1313 for (
char *p = command; *p != 0; p++) {
1319 char *path = getenv(
"PATH");
1320 if (fixed || path == 0) {
1321 _Bool ok = kmr_check_command_existence(mr, command, 0, msg);
1324 size_t s = strlen(path);
1326 memcpy(buf, path, (s + 1));
1330 while (p < &buf[s]) {
1331 while (p < &buf[s] && *p !=
':') {
1340 cc = snprintf(ss,
sizeof(ss),
"%s/%s", prefix, command);
1341 assert(cc < (
int)
sizeof(ss));
1342 ok = kmr_check_command_existence(mr, ss, 0, msg);
1348 kmr_free(buf, (s + 1));
1360 kmr_install_watch_program_on_rank0(
KMR *mr,
char *msg)
1362 char *name =
"kmrwatch0";
1363 assert(mr->rank == 0);
1365 static char command[256];
1367 cc = snprintf(command,
sizeof(command),
"%s", name);
1368 assert(cc < (
int)
sizeof(command));
1369 ok = kmr_check_command_existence(mr, command, 1, msg);
1373 if (mr->kmr_installation_path != 0) {
1374 char *prefix = mr->kmr_installation_path;
1375 cc = snprintf(command,
sizeof(command),
"%s/bin/%s", prefix, name);
1376 assert(cc < (
int)
sizeof(command));
1377 ok = kmr_check_command_existence(mr, command, 0, msg);
1381 cc = snprintf(command,
sizeof(command),
"%s/lib/%s", prefix, name);
1382 assert(cc < (
int)
sizeof(command));
1383 ok = kmr_check_command_existence(mr, command, 0, msg);
1388 if (mr->spawn_watch_prefix != 0) {
1389 char *prefix = mr->spawn_watch_prefix;
1390 cc = snprintf(command,
sizeof(command),
"%s/%s", prefix, name);
1391 assert(cc < (
int)
sizeof(command));
1392 ok = kmr_check_command_existence(mr, command, 0, msg);
1398 prefix = getenv(
"HOME");
1401 prefix = getenv(
"PJM_JOBDIR");
1404 kmr_error(mr, (
"installing a watch-program:" 1405 " environment variable HOME not set." 1406 " Try setting spawn_watch_prefix"));
1408 cc = snprintf(command,
sizeof(command),
"%s/%s", prefix, name);
1409 assert(cc < (
int)
sizeof(command));
1410 ok = kmr_check_command_existence(mr, command, 0, msg);
1415 #if !defined(KMRBINEMBED) 1417 cc = snprintf(command,
sizeof(command),
"%s", name);
1418 assert(cc < (
int)
sizeof(command));
1423 extern unsigned char kmr_binary_kmrwatch0_start[];
1424 extern unsigned char *kmr_binary_kmrwatch0_end;
1425 extern unsigned long kmr_binary_kmrwatch0_size;
1426 char *p0 = (
void *)kmr_binary_kmrwatch0_start;
1427 char *p1 = (
void *)kmr_binary_kmrwatch0_end;
1428 size_t sz = kmr_binary_kmrwatch0_size;
1429 assert((p1 - p0) == (
long)sz);
1432 mode_t mode = (S_IRWXU|S_IRWXG|S_IRWXO);
1433 fd = open(command, (O_WRONLY|O_CREAT|O_TRUNC), mode);
1434 }
while (fd == -1 && errno == EINTR);
1437 char *m = strerror(errno);
1438 snprintf(ee,
sizeof(ee),
"open(%s): %s", command, m);
1443 ssize_t xx = write(fd, &p0[ss], (sz - ss));
1446 char *m = strerror(errno);
1447 snprintf(ee,
sizeof(ee),
"write(%s): %s", command, m);
1452 snprintf(ee,
sizeof(ee),
"write(%s): write by zero size",
1461 snprintf(ee,
sizeof(ee),
1462 "a watch-program for spawning has been installed (%s)",
1464 kmr_warning(mr, 5, ee);
1474 kmr_install_watch_program(
KMR *mr,
char *msg)
1477 if (mr->spawn_watch_program == 0) {
1479 if (mr->rank == 0) {
1480 char *command = kmr_install_watch_program_on_rank0(mr, msg);
1481 assert(command != 0 && command[0] != 0);
1483 assert(cc == MPI_SUCCESS);
1486 assert(cc == MPI_SUCCESS);
1489 assert(cc == MPI_SUCCESS);
1492 assert(cc == MPI_SUCCESS);
1494 memcpy(b, kv.v.p, (
size_t)kv.vlen);
1495 mr->spawn_watch_program = b;
1497 assert(cc == MPI_SUCCESS);
1515 for (
int i = 0; i < sz; i++) {
1518 }
else if (!isprint(p[i])) {
1522 if (seezero && printable == 1) {
1527 if (printable == 1) {
1528 int z = (int)strnlen(p, (
size_t)sz);
1529 int n = MIN(z, ((
int)buflen - 5 - 1));
1531 snprintf(buf, (
size_t)(n + 3),
"\"%s\"", p);
1533 snprintf(buf, (
size_t)(n + 6),
"\"%s...\"", p);
1535 }
else if (printable == 2) {
1536 int z = (int)strnlen(p, (
size_t)sz);
1537 int n = MIN(z, (buflen - 5 - 1));
1539 snprintf(buf, (
size_t)(n + 6),
"\"%s???\"", p);
1541 snprintf(buf, (
size_t)(n + 6),
"\"%s...\"", p);
1544 int n = MIN(sz, ((buflen - 3 - 1) / 3));
1546 for (
int i = 0; i < n; i++) {
1547 snprintf(q, 4,
"%02x ", (p[i] & 0xff));
1551 snprintf(q, 4,
"...");
1558 char *buf,
int buflen)
1562 assert(data != KMR_KV_BAD);
1564 case KMR_KV_INTEGER:
1565 snprintf(buf, (
size_t)buflen,
"%ld", e.i);
1568 snprintf(buf, (
size_t)buflen,
"%e", e.d);
1571 case KMR_KV_CSTRING:
1572 case KMR_KV_POINTER_OWNED:
1573 case KMR_KV_POINTER_UNMANAGED:
1586 char *buf,
int buflen)
1588 char kbuf[48], vbuf[48];
1589 kmr_dump_slot(kv.k, kv.klen, kvs->c.key_data, kbuf,
sizeof(kbuf));
1590 kmr_dump_slot(kv.v, kv.vlen, kvs->c.value_data, vbuf,
sizeof(vbuf));
1591 snprintf(buf, (
size_t)buflen,
"k[%d]=%s;v[%d]=%s", kv.klen, kbuf, kv.vlen, vbuf);
1601 printf(
"[%05d][%ld] %s\n", kvs->c.mr->rank, i, b);
1611 assert(kvs->c.magic != KMR_KVS_BAD);
1612 int rank = kvs->c.mr->rank;
1613 printf(
"[%05d] element_count=%ld\n", rank, kvs->c.element_count);
1614 struct kmr_option opt = {.inspect = 1, .nothreading = 1};
1617 assert(cc == MPI_SUCCESS);
1627 char kbuf[48], vbuf[48];
1628 assert(kvs->c.magic != KMR_KVS_BAD);
1629 int rank = kvs->c.mr->rank;
1630 kmr_dump_slot(kv.k, kv.klen, kvs->c.key_data, kbuf,
sizeof(kbuf));
1632 printf(
"[%05d] k[%d]=%s;v[%d]=%s\n", rank, kv.klen, kbuf, kv.vlen, vbuf);
1641 kmr_dump_kvs_pair_value(
KMR_KVS *kvs,
int flag)
1643 assert(kvs->c.magic != KMR_KVS_BAD);
1644 assert(kvs->c.value_data == KMR_KV_OPAQUE
1645 || kvs->c.value_data == KMR_KV_CSTRING);
1646 int rank = kvs->c.mr->rank;
1647 printf(
"[%05d] element_count=%ld\n", rank, kvs->c.element_count);
1650 assert(cc == MPI_SUCCESS);
1663 if (kvs->c.mr->rank == 0) {
1664 printf(
"element_count=%ld\n", v);
1672 long cnt = kvi->c.element_count;
1673 for (
long i = 0; i < cnt; i++) {
1674 int rank = kvi->c.mr->rank;
1675 char kbuf[48], vbuf[48];
1677 kmr_dump_slot(kv.k, kv.klen, kvi->c.key_data, kbuf,
sizeof(kbuf));
1678 kmr_dump_slot(kv.v, kv.vlen, kvi->c.value_data, vbuf,
sizeof(vbuf));
1679 printf(
"[%05d] h=%ld;k[%d]=%s;v[%d]=%s\n", rank,
1680 ev[i].v, kv.klen, kbuf, kv.vlen, vbuf);
1688 printf(
".nothreading=%d," 1707 printf(
".each_rank=%d," 1708 " .subdirectories=%d," 1710 " .shuffle_names=%d\n",
1720 printf((
".separator_space=%d," 1724 " .take_ckpt=%d\n"),
1725 opt.separator_space,
1733 kmr_print_string(
char *msg,
char *s,
int len)
1737 printf(
"%s(len=%d)=", msg, len);
1738 for (
int i = 0; i < len; i++) {
1741 }
else if (isblank(s[i])) {
1743 }
else if (isprint(s[i])) {
1755 kmr_open_log(
KMR *mr)
1757 assert(mr->log_traces == 0);
1760 cc = snprintf(file,
sizeof(file),
"./%s_%05d",
1762 assert(cc < (
int)
sizeof(file));
1763 mr->log_traces = fopen(file,
"w");
1764 if (mr->log_traces == 0) {
1766 char *m = strerror(errno);
1767 snprintf(ee,
sizeof(ee),
1768 "Opening log file (%s) failed" 1769 " (disable tracing): %s",
1771 kmr_warning(mr, 1, ee);
1774 if (mr->log_traces != 0) {
1775 time_t ct = time(0);
1776 char *cs = ctime(&ct);
1777 fprintf(mr->log_traces,
"kmr trace (%s)\n", cs);
1787 assert(mr->log_traces != 0);
1788 if (mr->atwork != 0) {
1791 kmr_dump_slot(ev->k, ev->klen, kvs->c.key_data, s,
sizeof(s));
1792 fprintf(mr->log_traces,
1793 "file:%s, line:%d, kmr_func:%s," 1794 " user_func:%p, key:[%ld/%ld]%s, time:%.lf\n",
1795 info->file, info->line, info->func,
1796 (
void *)(intptr_t)m, (i + 1), cnt, s, (dt * 1000.0));
1806 assert(mr->log_traces != 0);
1807 if (mr->atwork != 0) {
1810 kmr_dump_slot(ev->k, ev->klen, kvs->c.key_data, s,
sizeof(s));
1811 fprintf(mr->log_traces,
1812 "file:%s, line:%d, kmr_func:%s," 1813 " user_func:%p, key:[%ld]%s, time:%.lf\n",
1814 info->file, info->line, info->func,
1815 (
void *)(intptr_t)r, n, s, (dt * 1000.0));
1827 kmr_put_property(MPI_Info info,
char *b,
int valpos,
int end)
1830 char *v = &b[valpos];
1833 kmr_warning(0, 5,
"empty key string for MPI_Info_set(), ignored");
1834 }
else if (v[0] == 0) {
1836 kmr_warning(0, 5,
"empty value string for MPI_Info_set(), ignored");
1838 int cc = MPI_Info_set(info, b, &b[valpos]);
1839 assert(cc == MPI_SUCCESS);
1853 #define CONTNL 0x010000 1854 #define kmr_load_properties_check_getc_error(C) \ 1855 if ((C) == EOF && errno != 0) { \ 1856 char *e = strerror(errno); \ 1857 snprintf(ee, sizeof(ee), "loading properties (%s), fgetc(): %s", \ 1859 kmr_warning(0, 1, ee); \ 1862 return MPI_ERR_ARG; \ 1864 #define kmr_load_properties_reset() \ 1865 {pos = -1; valpos = -1; scan = ForKey;} 1866 #define kmr_load_properties_grow() \ 1867 if (pos >= (blen - 1)) { \ 1868 blen *= 2; b = realloc(b, (size_t)blen); assert(b != 0); } 1869 #define kmr_load_properties_putc(C) { \ 1870 assert(pos != -1); \ 1871 b[pos++] = (char)(C); kmr_load_properties_grow(); } 1872 #define kmr_load_properties_hex(C) \ 1873 (('0' <= (C) && (C) <= '9') \ 1875 : (('a' <= (C) && (C) <= 'f') \ 1876 ? ((C) - 'a') : ((C) - 'A'))) 1877 #define kmr_load_properties_replace_cr() \ 1879 int c1 = kmr_fgetc(f); \ 1880 kmr_load_properties_check_getc_error(c1); \ 1893 char *e = strerror(errno);
1894 char *cwd = getcwd(b, 64);
1895 snprintf(ee,
sizeof(ee),
"loading properties, fopen(%s): %s (cwd=%s)",
1896 filename, e, (cwd == 0 ?
"?" : cwd));
1897 kmr_warning(0, 1, ee);
1902 enum {ForKey, Com, Key, KeySkp, ForSep, ForVal, Val, ValSkp} scan = ForKey;
1905 kmr_load_properties_reset();
1911 kmr_load_properties_check_getc_error(c);
1915 assert(pos == -1 && valpos == -1);
1918 assert(pos == -1 && valpos == -1);
1920 case Key:
case KeySkp:
1921 assert(pos != -1 && valpos == -1);
1922 kmr_put_property(info, b, valpos, pos);
1924 case ForSep:
case ForVal:
case Val:
case ValSkp:
1925 assert(pos != -1 && valpos != -1);
1926 kmr_put_property(info, b, valpos, pos);
1933 kmr_load_properties_replace_cr();
1941 kmr_load_properties_check_getc_error(c);
1943 snprintf(ee,
sizeof(ee),
1944 (
"loading properties (%s)," 1945 " file ends with a backslash"), filename);
1946 kmr_warning(0, 1, ee);
1957 case 'n':
case 'r':
case 't':
case 'f':
1959 case 'n': c =
'\n';
break;
1960 case 'r': c =
'\r';
break;
1961 case 't': c =
'\t';
break;
1962 case 'f': c =
'\f';
break;
1972 if (c1 == EOF || c2 == EOF || c3 == EOF) {
1974 char *e = strerror(errno);
1975 snprintf(ee,
sizeof(ee),
1976 (
"loading properties (%s)," 1979 kmr_warning(0, 1, ee);
1984 snprintf(ee,
sizeof(ee),
1985 (
"loading properties (%s)," 1986 " file ends amid unicode (at line %d)"),
1987 filename, (lines + 1));
1988 kmr_warning(0, 1, ee);
1994 if (!(isxdigit(c0) && isxdigit(c1)
1995 && isxdigit(c2) && isxdigit(c3))) {
1996 snprintf(ee,
sizeof(ee),
1997 (
"loading properties (%s)," 1998 " file includes bad character" 1999 " in unicode (at line %d)"),
2000 filename, (lines + 1));
2001 kmr_warning(0, 1, ee);
2006 c = (kmr_load_properties_hex(c0) << 12);
2007 c |= (kmr_load_properties_hex(c1) << 8);
2008 c |= (kmr_load_properties_hex(c2) << 4);
2009 c |= kmr_load_properties_hex(c3);
2012 snprintf(ee,
sizeof(ee),
2013 (
"loading properties (%s)," 2014 " file includes non-latin character" 2015 " in unicode (at line %d)"),
2016 filename, (lines + 1));
2017 kmr_warning(0, 1, ee);
2032 assert(pos == -1 && valpos == -1);
2035 assert(pos == -1 && valpos == -1);
2038 case Key:
case KeySkp:
2039 assert(pos != -1 && valpos == -1);
2042 case ForSep:
case ForVal:
2043 assert(pos != -1 && valpos != -1);
2045 case Val:
case ValSkp:
2046 assert(pos != -1 && valpos != -1);
2058 if (iscntrl(c) && !escaped) {
2059 snprintf(ee,
sizeof(ee),
2060 (
"loading properties (%s)," 2061 " file includes bad control code (at line %d)"),
2062 filename, (lines + 1));
2063 kmr_warning(0, 1, ee);
2070 assert(pos == -1 && valpos == -1);
2072 kmr_load_properties_putc(c);
2076 assert(pos == -1 && valpos == -1);
2079 case Key:
case KeySkp:
2080 assert(pos != -1 && valpos == -1);
2081 kmr_load_properties_putc(c);
2084 case ForSep:
case ForVal:
case Val:
case ValSkp:
2085 assert(pos != -1 && valpos != -1);
2086 kmr_load_properties_putc(c);
2096 assert(pos == -1 && valpos == -1);
2100 assert(pos == -1 && valpos == -1);
2103 case Key:
case KeySkp:
2104 assert(pos != -1 && valpos == -1);
2105 kmr_load_properties_putc(
'\0');
2107 kmr_load_properties_putc(
'\0');
2108 kmr_put_property(info, b, valpos, pos);
2109 kmr_load_properties_reset();
2111 case ForSep:
case ForVal:
case Val:
case ValSkp:
2112 assert(pos != -1 && valpos != -1);
2113 kmr_load_properties_putc(
'\0');
2114 kmr_put_property(info, b, valpos, pos);
2115 kmr_load_properties_reset();
2120 case ' ':
case '\t':
case '\f':
2123 assert(pos == -1 && valpos == -1);
2126 assert(pos == -1 && valpos == -1);
2129 assert(pos != -1 && valpos == -1);
2130 kmr_load_properties_putc(
'\0');
2135 assert(pos != -1 && valpos == -1);
2137 case ForSep:
case ForVal:
2138 assert(pos != -1 && valpos != -1);
2141 assert(pos != -1 && valpos != -1);
2142 kmr_load_properties_putc(c);
2145 assert(pos != -1 && valpos != -1);
2153 assert(pos == -1 && valpos == -1);
2157 assert(pos == -1 && valpos == -1);
2159 case Key:
case KeySkp:
2160 assert(pos != -1 && valpos == -1);
2161 kmr_load_properties_putc(c);
2164 case ForSep:
case ForVal:
case Val:
case ValSkp:
2165 assert(pos != -1 && valpos != -1);
2166 kmr_load_properties_putc(c);
2175 assert(pos == -1 && valpos == -1);
2177 kmr_load_properties_putc(
'\0');
2182 assert(pos == -1 && valpos == -1);
2184 case Key:
case KeySkp:
2185 assert(pos != -1 && valpos == -1);
2186 kmr_load_properties_putc(
'\0');
2191 assert(pos != -1 && valpos != -1);
2194 case ForVal:
case Val:
case ValSkp:
2195 assert(pos != -1 && valpos != -1);
2196 kmr_load_properties_putc(c);
2216 cc = MPI_Info_get_nkeys(info, &nkeys);
2217 assert(cc == MPI_SUCCESS);
2218 for (
int i = 0; i < nkeys; i++) {
2219 char key[MPI_MAX_INFO_KEY + 1];
2220 char value[MPI_MAX_INFO_VAL + 1];
2223 cc = MPI_Info_get_nthkey(info, i, key);
2224 assert(cc == MPI_SUCCESS);
2225 cc = MPI_Info_get_valuelen(info, key, &vlen, &flag);
2226 assert(cc == MPI_SUCCESS && flag != 0);
2227 assert(vlen <= MPI_MAX_INFO_VAL);
2228 cc = MPI_Info_get(info, key, MPI_MAX_INFO_VAL, value, &flag);
2229 assert(cc == MPI_SUCCESS && flag != 0);
2230 printf(
"%s \"%s\"=\"%s\"\n", prefix, key, value);
2242 cc = MPI_Info_get_nkeys(src, &nkeys);
2243 assert(cc == MPI_SUCCESS);
2244 for (
int i = 0; i < nkeys; i++) {
2245 char key[MPI_MAX_INFO_KEY + 1];
2246 char value[MPI_MAX_INFO_VAL + 1];
2249 cc = MPI_Info_get_nthkey(src, i, key);
2250 assert(cc == MPI_SUCCESS);
2251 cc = MPI_Info_get_valuelen(src, key, &vlen, &flag);
2252 assert(cc == MPI_SUCCESS && flag != 0);
2253 assert(vlen <= MPI_MAX_INFO_VAL);
2254 cc = MPI_Info_get(src, key, MPI_MAX_INFO_VAL, value, &flag);
2255 assert(cc == MPI_SUCCESS && flag != 0);
2257 cc = MPI_Info_set(dst, key, value);
2258 assert(cc == MPI_SUCCESS);
Key-Value Stream (abstract).
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...
int kmr_local_element_count(KMR_KVS *kvs, long *v)
Gets the number of key-value pairs locally on each rank.
Utilities Private Part (do not include from applications).
Options to Mapping, Shuffling, and Reduction.
int kmr_load_properties(MPI_Info info, char *filename)
Loads properties into MPI_Info (in Latin1 characters).
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...
#define kmr_malloc(Z)
Allocates memory, or aborts when failed.
#define KMR_TRACE_FILE_PREFIX
Prefix to Trace Files.
#define kmr_create_kvs(MR, KF, VF)
Makes a new key-value stream (of type KMR_KVS) with the specified field datatypes.
int kmr_dump_kvs_stats(KMR_KVS *kvs, int level)
Dumps contents of a key-value stream, with values are pairs.
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.
Keyed-Record for Sorting.
int kmr_add_kv_done(KMR_KVS *kvs)
Marks finished adding key-value pairs.
FILE * kmr_fopen(const char *n, const char *m)
Does fopen, avoiding EINTR.
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...
int kmr_free_kvs(KMR_KVS *kvs)
Releases a key-value stream (type KMR_KVS).
unsigned short kmr_k_position_t[4]
Positions of node by (X,Y,Z,ABC), with ABC axes collapsed.
int kmr_k_node(KMR *mr, kmr_k_position_t p)
Gets TOFU position (physical coordinates) of the node.
int kmr_copy_kvs_to_info(KMR_KVS *kvi, MPI_Info dst)
Copies kvs entires into mpi-info.
kmr_kv_field
Datatypes of Keys or Values.
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.
#define kmr_map(KVI, KVO, ARG, OPT, M)
Maps simply.
Handy Copy of a Key-Value Field.
Options to Mapping by Spawns.
int kmr_get_element_count(KMR_KVS *kvs, long *v)
Gets the total number of key-value pairs.
char * kmr_strptr_ff(char *s)
Returns itself; this is for Fortran-binding.
int kmr_ckpt_disable_ckpt(KMR *)
It temporally disables checkpoint/restart.
void * kmr_strdup(char *s)
STRDUP, but aborts on failure.
int kmr_copy_info_to_kvs(MPI_Info src, KMR_KVS *kvo)
Copies mpi-info entires into kvs.
int kmr_getdtablesize(KMR *mr)
Does getdtablesize(); it is defined, because it is not Posix.
int kmr_fgetc(FILE *f)
Does fgetc, avoiding EINTR.
unsigned long kmr_fix_bits_endian_ff(unsigned long b)
Fixes little-endian bits used in Fortran to host-endian.
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.
Options to Mapping on Files.
int kmr_copy_mpi_info(MPI_Info src, MPI_Info dst)
Copies contents of MPI_Info.
void kmr_dump_opaque(const char *p, int sz, char *buf, int buflen)
Puts the string of the key or value field into a buffer BUF as printable string.
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...
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...
int kmr_add_string(KMR_KVS *kvs, const char *k, const char *v)
Adds a key-value pair of strings.
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...
int kmr_dump_kv(const struct kmr_kv_box kv, const KMR_KVS *kvs, char *buf, int buflen)
Dumps contents of a key-value.
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().
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.
int kmr_ckpt_enable_ckpt(KMR *, int)
It temporally enables checkpoint/restart which has been disabled by calling kmr_ckpt_disable_ckpt().
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...
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.
Information of Source Code Line.
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.
int kmr_dump_mpi_info(char *prefix, MPI_Info info)
Dumps simply contents in MPI_Info.
int kmr_assert_sorted(KMR_KVS *kvi, _Bool locally, _Bool shuffling, _Bool ranking)
Checks a key-value stream is sorted.
int kmr_dump_kvs(KMR_KVS *kvs, int flag)
Dumps contents of a key-value stream to stdout.