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) {
414 }
else if (o.one_by_one) {
417 }
else if (o.no_set_infos) {
418 return "no_set_infos";
419 }
else if (o.take_ckpt) {
432 int cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
433 assert(cc == MPI_SUCCESS);
435 p[1] = (
unsigned short)rank;
448 int cc = kmr_k_node_by_rank(mr, p);
452 int cc = kmr_k_node_by_rank(mr, p);
459 int x, y, z, a, b, c;
460 cc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
461 assert(cc == MPI_SUCCESS);
462 cc = FJMPI_Topology_sys_rank2xyzabc(rank, &x, &y, &z, &a, &b, &c);
463 assert(cc == MPI_SUCCESS);
464 p[0] = (
unsigned short)x;
465 p[1] = (
unsigned short)y;
466 p[2] = (
unsigned short)z;
467 p[3] = (
unsigned short)((a << 4) | (b << 2) | c);
468 printf(
"[%05d] Coord x=%d, y=%d, z=%d, a=%d, b=%d, c=%d\n",
469 rank, x, y, z, a, b, c);
474 int cc = kmr_k_node_by_rank(mr, p);
477 char *tofupos =
"/proc/tofu/position";
481 fd = open(tofupos, O_RDONLY, 0);
482 }
while (fd == -1 && errno == EINTR);
485 char *m = strerror(errno);
486 snprintf(ee, 80,
"open(%s): %s", tofupos, m);
491 while (rc <
sizeof(buf)) {
494 cx = read(fd, &buf[rc], (
sizeof(buf) - rc));
495 }
while (cx == -1 && errno == EINTR);
501 char *m = strerror(errno);
502 snprintf(ee, 80,
"read(%s): %s", tofupos, m);
509 }
while (cc == -1 && errno == EINTR);
510 assert(rc > 18 && rc <
sizeof(buf));
512 unsigned int x, y, z, a, b, c;
514 cc = sscanf(buf,
"TOFU NODE ADDRESS:%d,%d,%d,%d,%d,%d%c%c",
515 &x, &y, &z, &a, &b, &c, &nl, &gomi);
516 assert(cc == 7 && nl ==
'\n');
517 assert(a <= 1 && b <= 2 && c <= 1);
521 p[3] = ((a << 4) | (b << 2) | c);
541 #ifdef CLOCK_REALTIME 542 static double t0 = 0.0;
546 cc = clock_getres(CLOCK_REALTIME, &ts);
548 double timerres = (double)ts.tv_sec + ((
double)ts.tv_nsec * 1e-9);
550 assert(timerres <= 1e-4);
551 cc = clock_gettime(CLOCK_REALTIME, &ts);
553 t0 = (double)ts.tv_sec + ((
double)ts.tv_nsec * 1e-9);
556 cc = clock_gettime(CLOCK_REALTIME, &ts);
558 double t1 = (double)ts.tv_sec + ((
double)ts.tv_nsec * 1e-9);
569 kmr_bsearch(
const void *key,
const void *base,
size_t nel,
size_t size,
570 int (*compar)(
const void *,
const void *))
572 assert(key != 0 && base != 0 && compar != 0);
573 const char *lb = base;
576 const char *p = lb + (w >> 1) * size;
577 int r = (*compar)(key, p);
601 char *m = strerror(errno);
602 snprintf(ee, 80,
"strdup(%s): %s", s, m);
614 size_t sz = (strlen(s) + 1);
630 }
while (f == 0 && errno == EINTR);
643 }
while (c == EOF && errno == EINTR);
654 cc = getrlimit(RLIMIT_NOFILE, &r);
658 char *m = strerror(errno);
659 snprintf(ee,
sizeof(ee),
"getrlimit(RLIMIT_NOFILE) failed: %s", m);
660 kmr_warning(mr, 5, ee);
669 kmr_parse_int(
char *s,
int *r)
672 char gomi[
sizeof(int)];
673 int cc = sscanf(s,
"%d%c", &v, gomi);
674 if (cc == 1 && r != 0) {
681 kmr_parse_boolean(
char *s,
int *r)
685 char gomi[
sizeof(int)];
686 if (strcasecmp(s,
"true") == 0) {
688 }
else if (strcasecmp(s,
"false") == 0) {
690 }
else if (sscanf(s,
"%d%c", &vv, gomi) == 1) {
691 if (vv == 0 || vv == 1) {
695 if (v != -1 && r != 0) {
702 kmr_parse_size_t(
char *s,
size_t *r)
705 char gomi[
sizeof(int)];
706 int cc = sscanf(s,
"%ld%c", &v, gomi);
707 if (cc == 1 && r != 0) {
723 kmr_sorter_t cmp = kmr_choose_sorter(kvi);
729 struct kmr_option rankzero = {.rank_zero = 1};
731 assert(cc == MPI_SUCCESS);
733 if (locally || rank == 0) {
734 long cnt = kvs1->c.element_count;
735 size_t evsz = (
sizeof(
struct kmr_kvs_entry *) * (
size_t)cnt);
738 assert(cc == MPI_SUCCESS);
739 for (
long i = 1; i < cnt; i++) {
743 assert(cmp(&b0, &b1) <= 0);
747 int r0 = (ranking ? (int)b0.k.i : kmr_pitch_rank(b0, kvs1));
748 int r1 = (ranking ? (int)b1.k.i : kmr_pitch_rank(b1, kvs1));
757 assert(cc == MPI_SUCCESS);
777 kmr_scan_argv_strings(
KMR *mr,
char *s,
size_t len,
int maxargc,
778 int *argc,
char **argv, _Bool ws,
char *msg)
780 assert(s != 0 && len > 0);
781 assert(argc != 0 || argv != 0);
782 assert((maxargc != 0) == (argv != 0));
783 assert(!isblank(
'\0'));
784 if (s[len - 1] != 0) {
786 snprintf(ee,
sizeof(ee), (
"%s: argument strings" 787 " not terminated with a null"), msg);
791 _Bool counting = (argv == 0);
792 char *
const lim = &s[len - 1];
796 while (p < lim && (ws && isblank(*p))) {
802 if (!counting && index < (maxargc - 1)) {
806 while (p < lim && !(*p == 0 || (ws && isblank(*p)))) {
810 if (!counting && *p != 0) {
811 assert(ws && isblank(*p));
819 if (!counting && index > (maxargc - 1)) {
821 snprintf(ee,
sizeof(ee),
822 (
"%s: argument count exceeds the limit (%d)"), msg, maxargc);
825 if (!counting && index < maxargc) {
839 kmr_msleep(
int msec,
int interval)
841 assert(msec >= 1 && interval >= 1);
842 int gap = MIN(msec, interval);
843 double t0 = MPI_Wtime();
844 double t1 = (t0 + 1e-3 * msec);
849 int cc = MPI_Testany(0, 0, &index, &ok, &st);
850 assert(cc == MPI_SUCCESS);
851 double t2 = MPI_Wtime();
855 usleep((useconds_t)(gap * 1000));
865 kmr_mfree(
void *p,
size_t sz)
874 kmr_mpi_type_size(
char *s)
876 if (strcasecmp(s,
"MPI_Group") == 0) {
877 return sizeof(MPI_Group);
878 }
else if (strcasecmp(s,
"MPI_Comm") == 0) {
879 return sizeof(MPI_Comm);
880 }
else if (strcasecmp(s,
"MPI_Datatype") == 0) {
881 return sizeof(MPI_Datatype);
882 }
else if (strcasecmp(s,
"MPI_Request") == 0) {
883 return sizeof(MPI_Request);
884 }
else if (strcasecmp(s,
"MPI_Op") == 0) {
885 return sizeof(MPI_Op);
886 }
else if (strcasecmp(s,
"MPI_Errhandler") == 0) {
887 return sizeof(MPI_Errhandler);
888 }
else if (strcasecmp(s,
"MPI_Info") == 0) {
889 return sizeof(MPI_Info);
892 snprintf(ee,
sizeof(ee),
893 "kmr_mpi_type_size() unknown name (%s)", s);
894 kmr_warning(0, 5, ee);
903 kmr_mpi_constant_value(
char *s)
905 assert(
sizeof(MPI_Group) <=
sizeof(uint64_t)
906 &&
sizeof(MPI_Comm) <=
sizeof(uint64_t)
907 &&
sizeof(MPI_Datatype) <=
sizeof(uint64_t)
908 &&
sizeof(MPI_Request) <=
sizeof(uint64_t)
909 &&
sizeof(MPI_Op) <=
sizeof(uint64_t)
910 &&
sizeof(MPI_Errhandler) <=
sizeof(uint64_t)
911 &&
sizeof(MPI_Info) <=
sizeof(uint64_t));
913 if (strcasecmp(s,
"MPI_COMM_WORLD") == 0) {
914 return (uint64_t)MPI_COMM_WORLD;
915 }
else if (strcasecmp(s,
"MPI_COMM_SELF") == 0) {
916 return (uint64_t)MPI_COMM_SELF;
917 }
else if (strcasecmp(s,
"MPI_COMM_NULL") == 0) {
918 return (uint64_t)MPI_COMM_NULL;
919 }
else if (strcasecmp(s,
"MPI_GROUP_NULL") == 0) {
920 return (uint64_t)MPI_GROUP_NULL;
921 }
else if (strcasecmp(s,
"MPI_DATATYPE_NULL") == 0) {
922 return (uint64_t)MPI_DATATYPE_NULL;
923 }
else if (strcasecmp(s,
"MPI_REQUEST_NULL") == 0) {
924 return (uint64_t)MPI_REQUEST_NULL;
925 }
else if (strcasecmp(s,
"MPI_OP_NULL") == 0) {
926 return (uint64_t)MPI_OP_NULL;
927 }
else if (strcasecmp(s,
"MPI_ERRHANDLER_NULL") == 0) {
928 return (uint64_t)MPI_ERRHANDLER_NULL;
929 }
else if (strcasecmp(s,
"MPI_GROUP_EMPTY") == 0) {
930 return (uint64_t)MPI_GROUP_EMPTY;
931 }
else if (strcasecmp(s,
"MPI_INFO_NULL") == 0) {
932 return (uint64_t)MPI_INFO_NULL;
935 snprintf(ee,
sizeof(ee),
936 "kmr_mpi_constant_value() unknown name (%s)", s);
937 kmr_warning(0, 5, ee);
961 kmr_imax_one_fn(
const struct kmr_kv_box kv[],
const long n,
967 for (
long i = 0; i < n; i++) {
976 kmr_isum_one_fn(
const struct kmr_kv_box kv[],
const long n,
982 for (
long i = 0; i < n; i++) {
999 kmr_assert_kvs_ok(0, kvo, 0, 1);
1000 assert(src != MPI_INFO_NULL);
1003 char key[MPI_MAX_INFO_KEY + 1];
1004 char value[MPI_MAX_INFO_VAL + 1];
1005 cc = MPI_Info_get_nkeys(src, &nkeys);
1006 assert(cc == MPI_SUCCESS);
1007 for (
int i = 0; i < nkeys; i++) {
1010 cc = MPI_Info_get_nthkey(src, i, key);
1011 assert(cc == MPI_SUCCESS);
1012 cc = MPI_Info_get_valuelen(src, key, &vlen, &flag);
1013 assert(cc == MPI_SUCCESS && flag != 0);
1014 assert(vlen <= MPI_MAX_INFO_VAL);
1015 cc = MPI_Info_get(src, key, MPI_MAX_INFO_VAL, value, &flag);
1016 assert(cc == MPI_SUCCESS && flag != 0);
1018 assert(cc == MPI_SUCCESS);
1021 assert(cc == MPI_SUCCESS);
1030 MPI_Info dst = *dstp;
1031 char *k = (
char *)kv.k.p;
1032 char *v = (
char *)kv.v.p;
1034 kmr_warning(0, 5,
"empty key string for MPI_Info_set(), ignored");
1035 }
else if (v[0] == 0) {
1037 kmr_warning(0, 5,
"empty value string for MPI_Info_set(), ignored");
1039 int cc = MPI_Info_set(dst, (
char *)kv.k.p, (
char *)kv.v.p);
1040 assert(cc == MPI_SUCCESS);
1051 kmr_assert_kvs_ok(kvi, 0, 1, 0);
1053 struct kmr_option nothreading = {.nothreading = 1};
1054 cc =
kmr_map(kvi, 0, &dst, nothreading, kmr_set_info_fn);
1055 assert(cc == MPI_SUCCESS);
1064 kmr_load_preference(
KMR *mr, MPI_Info info)
1068 cc = MPI_Info_create(&inforank0);
1069 assert(cc == MPI_SUCCESS);
1071 if (mr->rank == 0) {
1072 char *name = getenv(
"KMROPTION");
1077 if (cc != MPI_SUCCESS) {
1084 assert(cc == MPI_SUCCESS);
1087 assert(cc == MPI_SUCCESS);
1089 assert(cc == MPI_SUCCESS);
1090 MPI_Info_free(&inforank0);
1093 snprintf(ee,
sizeof(ee),
"[%05d]", mr->rank);
1094 printf(
"%s dumpinfo info...\n", ee);
1105 kmr_check_options(
KMR *mr, MPI_Info info)
1110 if (info == MPI_INFO_NULL) {
1113 cc = MPI_Info_get_nkeys(info, &n);
1114 assert(cc == MPI_SUCCESS);
1117 for (
int i = 0; i < n; i++) {
1118 char k[MPI_MAX_INFO_KEY + 1];
1119 char v[MPI_MAX_INFO_VAL + 1];
1121 cc = MPI_Info_get_nthkey(info, i, k);
1122 assert(cc == MPI_SUCCESS);
1123 cc = MPI_Info_get(info, k, MPI_MAX_INFO_VAL, v, &flag);
1124 assert(cc == MPI_SUCCESS && flag != 0);
1126 kmr_set_option_by_strings(mr, k, v);
1129 snprintf(ee, 80,
"option \"%s\" ignored", k);
1130 kmr_warning(mr, 1, ee);
1134 if (mr->verbosity == 9) {
1136 printf(
"[%05d] Dumping KMR options:\n", r);
1137 printf(
"[%05d] verbosity=%d\n", r, mr->verbosity);
1138 printf(
"[%05d] sort_threads_depth=%d\n", r, mr->sort_threads_depth);
1139 printf(
"[%05d] onk=%d\n", r, mr->onk);
1140 printf(
"[%05d] atoa_threshold=%ld\n", r, mr->atoa_threshold);
1141 printf(
"[%05d] atoa_size_limit=%ld\n", r, mr->atoa_size_limit);
1142 printf(
"[%05d] atoa_requests_limit=%d\n", r, mr->atoa_requests_limit);
1143 printf(
"[%05d] single_thread=%d\n", r, mr->single_thread);
1144 printf(
"[%05d] step_sync=%d\n", r, mr->step_sync);
1145 printf(
"[%05d] trace_file_io=%d\n", r, mr->trace_file_io);
1146 printf(
"[%05d] trace_map_ms=%d\n", r, mr->trace_map_ms);
1147 printf(
"[%05d] trace_map_spawn=%d\n", r, mr->trace_map_spawn);
1148 printf(
"[%05d] trace_alltoall=%d\n", r, mr->trace_alltoall);
1149 printf(
"[%05d] trace_kmrdp=%d\n", r, mr->trace_kmrdp);
1150 printf(
"[%05d] std_abort=%d\n", r, mr->std_abort);
1151 printf(
"[%05d] log_traces=%d\n", r, (mr->log_traces != 0));
1152 printf(
"[%05d] ckpt_enable=%d\n", r, mr->ckpt_enable);
1153 printf(
"[%05d] ckpt_selective=%d\n", r, mr->ckpt_selective);
1154 printf(
"[%05d] ckpt_no_fsync=%d\n", r, mr->ckpt_no_fsync);
1155 printf(
"[%05d] pushoff_block_size=%zd\n", r, mr->pushoff_block_size);
1156 printf(
"[%05d] pushoff_poll_rate=%d\n", r, mr->pushoff_poll_rate);
1157 printf(
"[%05d] pushoff_fast_notice=%d\n", r, mr->pushoff_fast_notice);
1158 printf(
"[%05d] kmrviz_trace=%d\n", r, mr->kmrviz_trace);
1159 printf(
"[%05d] map_ms_use_exec=%d\n", r, mr->map_ms_use_exec);
1160 printf(
"[%05d] map_ms_abort_on_signal=%d\n", r, mr->map_ms_abort_on_signal);
1168 kmr_set_option_by_strings(
KMR *mr,
char *k,
char *v)
1171 if (strcasecmp(
"log_traces", k) == 0) {
1172 if (kmr_parse_boolean(v, &x)) {
1173 if (mr->log_traces == 0) {
1177 kmr_warning(mr, 1,
"option log_traces be boolean");
1179 }
else if (strcasecmp(
"sort_threads_depth", k) == 0) {
1180 if (kmr_parse_int(v, &x) && x >= 0) {
1181 mr->sort_threads_depth = x;
1183 kmr_warning(mr, 1, (
"option sort_threads_depth be" 1184 " non-negative integer"));
1186 }
else if (strcasecmp(
"verbosity", k) == 0) {
1187 if (kmr_parse_int(v, &x) && (1 <= x && x <= 9)) {
1188 mr->verbosity = (uint8_t)x;
1190 kmr_warning(mr, 1,
"option verbosity be 1-9");
1192 }
else if (strcasecmp(
"k", k) == 0) {
1193 if (kmr_parse_boolean(v, &x)) {
1196 kmr_warning(mr, 1,
"option k be boolean");
1198 }
else if (strcasecmp(
"single_thread", k) == 0) {
1199 if (kmr_parse_boolean(v, &x)) {
1200 mr->single_thread = (_Bool)x;
1202 kmr_warning(mr, 1,
"option single_thread be boolean");
1204 }
else if (strcasecmp(
"step_sync", k) == 0) {
1205 if (kmr_parse_boolean(v, &x)) {
1206 mr->step_sync = (_Bool)x;
1208 kmr_warning(mr, 1,
"option step_sync be boolean");
1210 }
else if (strcasecmp(
"trace_file_io", k) == 0) {
1211 if (kmr_parse_boolean(v, &x)) {
1212 mr->trace_file_io = (_Bool)x;
1214 kmr_warning(mr, 1,
"option trace_file_io be boolean");
1216 }
else if (strcasecmp(
"trace_map_ms", k) == 0) {
1217 if (kmr_parse_boolean(v, &x)) {
1218 mr->trace_map_ms = (_Bool)x;
1220 kmr_warning(mr, 1,
"option trace_map_ms be boolean");
1222 }
else if (strcasecmp(
"trace_map_spawn", k) == 0) {
1223 if (kmr_parse_boolean(v, &x)) {
1224 mr->trace_map_spawn = (_Bool)x;
1226 kmr_warning(mr, 1,
"option trace_map_spawn be boolean");
1228 }
else if (strcasecmp(
"std_abort", k) == 0) {
1229 if (kmr_parse_boolean(v, &x)) {
1230 mr->std_abort = (_Bool)x;
1232 kmr_warning(mr, 1,
"option std_abort be boolean");
1234 }
else if (strcasecmp(
"trace_alltoall", k) == 0) {
1235 if (kmr_parse_boolean(v, &x)) {
1236 mr->trace_alltoall = (_Bool)x;
1238 kmr_warning(mr, 1,
"option trace_alltoall be boolean");
1240 }
else if (strcasecmp(
"atoa_threshold", k) == 0) {
1241 if (kmr_parse_int(v, &x) && x >= 0) {
1242 mr->atoa_threshold = x;
1244 kmr_warning(mr, 1, (
"option atoa_threshold be" 1245 " non-negative integer"));
1247 }
else if (strcasecmp(
"atoa_size_limit", k) == 0) {
1248 if (kmr_parse_int(v, &x) && x >= 0) {
1249 mr->atoa_size_limit = (long)x * 1024 * 1024;
1251 kmr_warning(mr, 1, (
"option atoa_size_limit be" 1252 " non-negative integer (in MB)"));
1254 }
else if (strcasecmp(
"atoa_requests_limit", k) == 0) {
1255 if (kmr_parse_int(v, &x) && x >= 0) {
1256 mr->atoa_requests_limit = x;
1258 kmr_warning(mr, 1, (
"option atoa_requests_limit be" 1259 " non-negative integer"));
1261 }
else if (strcasecmp(
"map_ms_use_exec", k) == 0) {
1262 if (kmr_parse_boolean(v, &x)) {
1263 mr->map_ms_use_exec = (_Bool)x;
1265 kmr_warning(mr, 1,
"option map_ms_use_exec be" 1268 }
else if (strcasecmp(
"map_ms_abort_on_signal", k) == 0) {
1269 if (kmr_parse_boolean(v, &x)) {
1270 mr->map_ms_abort_on_signal = (_Bool)x;
1272 kmr_warning(mr, 1,
"option map_ms_abort_on_signal be" 1275 }
else if (strcasecmp(
"spawn_max_processes", k) == 0) {
1276 if (kmr_parse_int(v, &x) && x >= 0) {
1277 mr->spawn_max_processes = x;
1279 kmr_warning(mr, 1, (
"option spawn_max_processes be" 1280 " non-negative integer"));
1282 }
else if (strcasecmp(
"spawn_retry_limit", k) == 0) {
1283 if (kmr_parse_int(v, &x) && x >= 0) {
1284 mr->spawn_retry_limit = x;
1286 kmr_warning(mr, 1, (
"option spawn_retry_limit be" 1287 " non-negative integer"));
1289 }
else if (strcasecmp(
"spawn_retry_gap_msec", k) == 0) {
1290 if (kmr_parse_int(v, &x) && x >= 0) {
1291 mr->spawn_retry_gap_msec = x;
1293 kmr_warning(mr, 1, (
"option spawn_retry_gap_msec be" 1294 " non-negative integer"));
1296 }
else if (strcasecmp(
"ckpt_enable", k) == 0) {
1297 if (kmr_parse_boolean(v, &x)) {
1298 mr->ckpt_enable = (_Bool)x;
1300 kmr_warning(mr, 1,
"option ckpt_enable be boolean");
1302 }
else if (strcasecmp(
"ckpt_selective", k) == 0) {
1303 if (kmr_parse_boolean(v, &x)) {
1304 mr->ckpt_selective = (_Bool)x;
1306 kmr_warning(mr, 1,
"option ckpt_selective be boolean");
1308 }
else if (strcasecmp(
"ckpt_no_fsync", k) == 0) {
1309 if (kmr_parse_boolean(v, &x)) {
1310 mr->ckpt_no_fsync = (_Bool)x;
1312 kmr_warning(mr, 1,
"option ckpt_no_fsync be boolean");
1314 }
else if (strcasecmp(
"pushoff_block_size", k) == 0) {
1316 if (kmr_parse_size_t(v, &z)) {
1317 mr->pushoff_block_size = z;
1319 }
else if (strcasecmp(
"pushoff_poll_rate", k) == 0) {
1320 if (kmr_parse_int(v, &x)) {
1321 mr->pushoff_poll_rate = x;
1323 }
else if (strcasecmp(
"pushoff_fast_notice", k) == 0) {
1324 if (kmr_parse_boolean(v, &x)) {
1325 mr->pushoff_fast_notice = (_Bool)x;
1327 kmr_warning(mr, 1,
"option pushoff_fast_notice be boolean");
1329 }
else if (strcasecmp(
"kmrviz_trace", k) == 0) {
1330 if (kmr_parse_boolean(v, &x)) {
1331 mr->kmrviz_trace = (_Bool)x;
1333 kmr_warning(mr, 1,
"option kmrviz_trace be boolean");
1335 }
else if (strcasecmp(
"swf_spawner_library", k) == 0) {
1337 }
else if (strcasecmp(
"swf_args_size", k) == 0) {
1339 if (kmr_parse_size_t(v, &z)) {
1340 mr->swf_args_size = z;
1342 }
else if (strcasecmp(
"swf_exec_so", k) == 0) {
1343 if (kmr_parse_boolean(v, &x)) {
1344 mr->swf_exec_so = (_Bool)x;
1346 kmr_warning(mr, 1,
"option swf_exec_so be boolean");
1348 }
else if (strcasecmp(
"swf_record_history", k) == 0) {
1349 if (kmr_parse_boolean(v, &x)) {
1350 mr->swf_record_history = (_Bool)x;
1352 kmr_warning(mr, 1,
"option swf_record_history be boolean");
1354 }
else if (strcasecmp(
"swf_debug_master", k) == 0) {
1355 if (kmr_parse_boolean(v, &x)) {
1356 mr->swf_debug_master = (_Bool)x;
1358 kmr_warning(mr, 1,
"option swf_debug_master be boolean");
1362 snprintf(ee, 80,
"option \"%s\" ignored", k);
1363 kmr_warning(mr, 1, ee);
1375 kmr_check_command_existence(
KMR *mr,
char *command, _Bool search,
char *msg)
1379 _Bool tracing7 = (mr->trace_map_spawn && (7 <= mr->verbosity));
1382 fprintf(stderr, (
";;KMR [%05d] %s:" 1383 " checking a watch-program: %s\n"),
1384 mr->rank, msg, command);
1388 cc = access(command, X_OK);
1389 }
while (cc != 0 && errno == EINTR);
1390 if (cc != 0 && !(errno == ENOENT || errno == EACCES)) {
1392 char *m = strerror(errno);
1393 snprintf(ee,
sizeof(ee),
"access() returned: %s", m);
1394 kmr_warning(mr, 1, ee);
1399 for (
char *p = command; *p != 0; p++) {
1405 char *path = getenv(
"PATH");
1406 if (fixed || path == 0) {
1407 _Bool ok = kmr_check_command_existence(mr, command, 0, msg);
1410 size_t s = strlen(path);
1412 memcpy(buf, path, (s + 1));
1416 while (p < &buf[s]) {
1417 while (p < &buf[s] && *p !=
':') {
1426 cc = snprintf(ss,
sizeof(ss),
"%s/%s", prefix, command);
1427 assert(cc < (
int)
sizeof(ss));
1428 ok = kmr_check_command_existence(mr, ss, 0, msg);
1434 kmr_free(buf, (s + 1));
1446 kmr_install_watch_program_on_rank0(
KMR *mr,
char *msg)
1448 char *name =
"kmrwatch0";
1449 assert(mr->rank == 0);
1451 static char command[256];
1453 cc = snprintf(command,
sizeof(command),
"%s", name);
1454 assert(cc < (
int)
sizeof(command));
1455 ok = kmr_check_command_existence(mr, command, 1, msg);
1459 if (mr->kmr_installation_path != 0) {
1460 char *prefix = mr->kmr_installation_path;
1461 cc = snprintf(command,
sizeof(command),
"%s/bin/%s", prefix, name);
1462 assert(cc < (
int)
sizeof(command));
1463 ok = kmr_check_command_existence(mr, command, 0, msg);
1467 cc = snprintf(command,
sizeof(command),
"%s/lib/%s", prefix, name);
1468 assert(cc < (
int)
sizeof(command));
1469 ok = kmr_check_command_existence(mr, command, 0, msg);
1474 if (mr->spawn_watch_prefix != 0) {
1475 char *prefix = mr->spawn_watch_prefix;
1476 cc = snprintf(command,
sizeof(command),
"%s/%s", prefix, name);
1477 assert(cc < (
int)
sizeof(command));
1478 ok = kmr_check_command_existence(mr, command, 0, msg);
1484 prefix = getenv(
"HOME");
1487 prefix = getenv(
"PJM_JOBDIR");
1490 kmr_error(mr, (
"installing a watch-program:" 1491 " environment variable HOME not set." 1492 " Try setting spawn_watch_prefix"));
1494 cc = snprintf(command,
sizeof(command),
"%s/%s", prefix, name);
1495 assert(cc < (
int)
sizeof(command));
1496 ok = kmr_check_command_existence(mr, command, 0, msg);
1501 #if !defined(KMRBINEMBED) 1503 cc = snprintf(command,
sizeof(command),
"%s", name);
1504 assert(cc < (
int)
sizeof(command));
1509 extern unsigned char kmr_binary_kmrwatch0_start[];
1510 extern unsigned char *kmr_binary_kmrwatch0_end;
1511 extern unsigned long kmr_binary_kmrwatch0_size;
1512 char *p0 = (
void *)kmr_binary_kmrwatch0_start;
1513 char *p1 = (
void *)kmr_binary_kmrwatch0_end;
1514 size_t sz = kmr_binary_kmrwatch0_size;
1515 assert((p1 - p0) == (
long)sz);
1518 mode_t mode = (S_IRWXU|S_IRWXG|S_IRWXO);
1519 fd = open(command, (O_WRONLY|O_CREAT|O_TRUNC), mode);
1520 }
while (fd == -1 && errno == EINTR);
1523 char *m = strerror(errno);
1524 snprintf(ee,
sizeof(ee),
"open(%s): %s", command, m);
1529 ssize_t xx = write(fd, &p0[ss], (sz - ss));
1532 char *m = strerror(errno);
1533 snprintf(ee,
sizeof(ee),
"write(%s): %s", command, m);
1538 snprintf(ee,
sizeof(ee),
"write(%s): write by zero size",
1547 snprintf(ee,
sizeof(ee),
1548 "a watch-program for spawning has been installed (%s)",
1550 kmr_warning(mr, 5, ee);
1560 kmr_install_watch_program(
KMR *mr,
char *msg)
1563 if (mr->spawn_watch_program == 0) {
1565 if (mr->rank == 0) {
1566 char *command = kmr_install_watch_program_on_rank0(mr, msg);
1567 assert(command != 0 && command[0] != 0);
1569 assert(cc == MPI_SUCCESS);
1572 assert(cc == MPI_SUCCESS);
1575 assert(cc == MPI_SUCCESS);
1578 assert(cc == MPI_SUCCESS);
1580 memcpy(b, kv.v.p, (
size_t)kv.vlen);
1581 mr->spawn_watch_program = b;
1583 assert(cc == MPI_SUCCESS);
1604 for (
int i = 0; i < sz; i++) {
1607 }
else if (!isprint((
unsigned char)p[i])) {
1612 if (seezero && printable == 1) {
1618 if (printable == 1) {
1619 int z = (int)strnlen(p, (
size_t)sz);
1620 int n = MIN(z, ((
int)buflen - 5 - 1));
1621 snprintf(buf, (
size_t)2,
"\"");
1622 snprintf((buf + 1), (
size_t)(n + 1),
"%s", p);
1624 snprintf((buf + n + 1), (
size_t)2,
"\"");
1627 snprintf((buf + n + 1), (
size_t)5,
"...\"");
1630 }
else if (printable == 2) {
1631 int z = (int)strnlen(p, (
size_t)sz);
1632 int n = MIN(z, (buflen - 5 - 1));
1633 snprintf(buf, (
size_t)2,
"\"");
1634 snprintf((buf + 1), (
size_t)(n + 1),
"%s", p);
1636 snprintf((buf + n + 1), (
size_t)5,
"???\"");
1639 snprintf((buf + n + 1), (
size_t)5,
"...\"");
1643 int n = MIN(sz, ((buflen - 3 - 1) / 3));
1645 for (
int i = 0; i < n; i++) {
1646 snprintf(q, 4,
"%02x ", (p[i] & 0xff));
1650 snprintf(q, 4,
"...");
1657 char *buf,
int buflen)
1661 assert(data != KMR_KV_BAD);
1663 case KMR_KV_INTEGER:
1664 snprintf(buf, (
size_t)buflen,
"%ld", e.i);
1667 snprintf(buf, (
size_t)buflen,
"%e", e.d);
1670 case KMR_KV_CSTRING:
1671 case KMR_KV_POINTER_OWNED:
1672 case KMR_KV_POINTER_UNMANAGED:
1685 char *buf,
int buflen)
1687 char kbuf[48], vbuf[48];
1688 kmr_dump_slot(kv.k, kv.klen, kvs->c.key_data, kbuf,
sizeof(kbuf));
1689 kmr_dump_slot(kv.v, kv.vlen, kvs->c.value_data, vbuf,
sizeof(vbuf));
1690 snprintf(buf, (
size_t)buflen,
"k[%d]=%s;v[%d]=%s", kv.klen, kbuf, kv.vlen, vbuf);
1700 printf(
"[%05d][%ld] %s\n", kvs->c.mr->rank, i, b);
1713 assert(kvs->c.magic != KMR_KVS_BAD);
1714 int rank = kvs->c.mr->rank;
1715 printf(
"[%05d] element_count=%ld\n", rank, kvs->c.element_count);
1716 struct kmr_option opt = {.inspect = 1, .nothreading = 1};
1719 assert(cc == MPI_SUCCESS);
1729 char kbuf[48], vbuf[48];
1730 assert(kvs->c.magic != KMR_KVS_BAD);
1731 int rank = kvs->c.mr->rank;
1732 kmr_dump_slot(kv.k, kv.klen, kvs->c.key_data, kbuf,
sizeof(kbuf));
1734 printf(
"[%05d] k[%d]=%s;v[%d]=%s\n", rank, kv.klen, kbuf, kv.vlen, vbuf);
1743 kmr_dump_kvs_pair_value(
KMR_KVS *kvs,
int flag)
1745 assert(kvs->c.magic != KMR_KVS_BAD);
1746 assert(kvs->c.value_data == KMR_KV_OPAQUE
1747 || kvs->c.value_data == KMR_KV_CSTRING);
1748 int rank = kvs->c.mr->rank;
1749 printf(
"[%05d] element_count=%ld\n", rank, kvs->c.element_count);
1752 assert(cc == MPI_SUCCESS);
1765 if (kvs->c.mr->rank == 0) {
1766 printf(
"element_count=%ld\n", v);
1774 long cnt = kvi->c.element_count;
1775 for (
long i = 0; i < cnt; i++) {
1776 int rank = kvi->c.mr->rank;
1777 char kbuf[48], vbuf[48];
1779 kmr_dump_slot(kv.k, kv.klen, kvi->c.key_data, kbuf,
sizeof(kbuf));
1780 kmr_dump_slot(kv.v, kv.vlen, kvi->c.value_data, vbuf,
sizeof(vbuf));
1781 printf(
"[%05d] h=%ld;k[%d]=%s;v[%d]=%s\n", rank,
1782 ev[i].v, kv.klen, kbuf, kv.vlen, vbuf);
1790 printf(
".nothreading=%d," 1809 printf(
".each_rank=%d," 1810 " .subdirectories=%d," 1812 " .shuffle_names=%d\n",
1822 printf((
".separator_space=%d," 1826 " .no_set_infos=%d," 1827 " .take_ckpt=%d\n"),
1828 opt.separator_space,
1837 kmr_print_string(
char *msg,
char *s,
int len)
1841 printf(
"%s(len=%d)=", msg, len);
1842 for (
int i = 0; i < len; i++) {
1845 }
else if (isblank(s[i])) {
1847 }
else if (isprint(s[i])) {
1869 for (
int i = 0; argv[i] != 0; i++) {
1870 cc = snprintf(&s[cnt], (sz - cnt),
"%s%s",
1871 (i == 0 ?
"" :
","), argv[i]);
1874 snprintf(&s[sz - 4], 4,
"...");
1888 char key[MPI_MAX_INFO_KEY + 1];
1889 char value[MPI_MAX_INFO_VAL + 1];
1897 cc = MPI_Info_get_nkeys(info, &nkeys);
1898 assert(cc == MPI_SUCCESS);
1902 for (
int i = 0; i < nkeys; i++) {
1903 cc = MPI_Info_get_nthkey(info, i, key);
1904 assert(cc == MPI_SUCCESS);
1905 key[MPI_MAX_INFO_KEY] = 0;
1907 cc = MPI_Info_get(info, key, MPI_MAX_INFO_VAL, value, &flag);
1908 assert(cc == MPI_SUCCESS && flag != 0);
1909 value[MPI_MAX_INFO_VAL] = 0;
1910 cc = snprintf(&s[cnt], (sz - cnt),
"%s%s=%s",
1911 (i == 0 ?
"" :
","), key, value);
1914 snprintf(&s[sz - 4], 4,
"...");
1924 kmr_open_log(
KMR *mr)
1926 assert(mr->log_traces == 0);
1929 cc = snprintf(file,
sizeof(file),
"./%s_%05d",
1931 assert(cc < (
int)
sizeof(file));
1932 mr->log_traces = fopen(file,
"w");
1933 if (mr->log_traces == 0) {
1935 char *m = strerror(errno);
1936 snprintf(ee,
sizeof(ee),
1937 "Opening log file (%s) failed" 1938 " (disable tracing): %s",
1940 kmr_warning(mr, 1, ee);
1943 if (mr->log_traces != 0) {
1944 time_t ct = time(0);
1945 char *cs = ctime(&ct);
1946 fprintf(mr->log_traces,
"kmr trace (%s)\n", cs);
1956 assert(mr->log_traces != 0);
1957 if (mr->atwork != 0) {
1960 kmr_dump_slot(ev->k, ev->klen, kvs->c.key_data, s,
sizeof(s));
1961 fprintf(mr->log_traces,
1962 "file:%s, line:%d, kmr_func:%s," 1963 " user_func:%p, key:[%ld/%ld]%s, time:%.lf\n",
1964 info->file, info->line, info->func,
1965 (
void *)(intptr_t)m, (i + 1), cnt, s, (dt * 1000.0));
1975 assert(mr->log_traces != 0);
1976 if (mr->atwork != 0) {
1979 kmr_dump_slot(ev->k, ev->klen, kvs->c.key_data, s,
sizeof(s));
1980 fprintf(mr->log_traces,
1981 "file:%s, line:%d, kmr_func:%s," 1982 " user_func:%p, key:[%ld]%s, time:%.lf\n",
1983 info->file, info->line, info->func,
1984 (
void *)(intptr_t)r, n, s, (dt * 1000.0));
1996 kmr_put_property(MPI_Info info,
char *b,
int valpos,
int end)
1999 char *v = &b[valpos];
2002 kmr_warning(0, 5,
"empty key string for MPI_Info_set(), ignored");
2003 }
else if (v[0] == 0) {
2005 kmr_warning(0, 5,
"empty value string for MPI_Info_set(), ignored");
2007 int cc = MPI_Info_set(info, b, &b[valpos]);
2008 assert(cc == MPI_SUCCESS);
2022 #define CONTNL 0x010000 2023 #define kmr_load_properties_check_getc_error(C) \ 2024 if ((C) == EOF && errno != 0) { \ 2025 char *e = strerror(errno); \ 2026 snprintf(ee, sizeof(ee), "loading properties (%s), fgetc(): %s", \ 2028 kmr_warning(0, 1, ee); \ 2031 return MPI_ERR_ARG; \ 2033 #define kmr_load_properties_reset() \ 2034 {pos = -1; valpos = -1; scan = ForKey;} 2035 #define kmr_load_properties_grow() \ 2036 if (pos >= (blen - 1)) { \ 2037 blen *= 2; b = realloc(b, (size_t)blen); assert(b != 0); } 2038 #define kmr_load_properties_putc(C) { \ 2039 assert(pos != -1); \ 2040 b[pos++] = (char)(C); kmr_load_properties_grow(); } 2041 #define kmr_load_properties_hex(C) \ 2042 (('0' <= (C) && (C) <= '9') \ 2044 : (('a' <= (C) && (C) <= 'f') \ 2045 ? ((C) - 'a') : ((C) - 'A'))) 2046 #define kmr_load_properties_replace_cr() \ 2048 int c1 = kmr_fgetc(f); \ 2049 kmr_load_properties_check_getc_error(c1); \ 2062 char *e = strerror(errno);
2063 char *cwd = getcwd(b, 64);
2064 snprintf(ee,
sizeof(ee),
"loading properties, fopen(%s): %s (cwd=%s)",
2065 filename, e, (cwd == 0 ?
"?" : cwd));
2066 kmr_warning(0, 1, ee);
2071 enum {ForKey, Com, Key, KeySkp, ForSep, ForVal, Val, ValSkp} scan = ForKey;
2074 kmr_load_properties_reset();
2080 kmr_load_properties_check_getc_error(c);
2084 assert(pos == -1 && valpos == -1);
2087 assert(pos == -1 && valpos == -1);
2089 case Key:
case KeySkp:
2090 assert(pos != -1 && valpos == -1);
2091 kmr_put_property(info, b, valpos, pos);
2093 case ForSep:
case ForVal:
case Val:
case ValSkp:
2094 assert(pos != -1 && valpos != -1);
2095 kmr_put_property(info, b, valpos, pos);
2102 kmr_load_properties_replace_cr();
2110 kmr_load_properties_check_getc_error(c);
2112 snprintf(ee,
sizeof(ee),
2113 (
"loading properties (%s)," 2114 " file ends with a backslash"), filename);
2115 kmr_warning(0, 1, ee);
2126 case 'n':
case 'r':
case 't':
case 'f':
2128 case 'n': c =
'\n';
break;
2129 case 'r': c =
'\r';
break;
2130 case 't': c =
'\t';
break;
2131 case 'f': c =
'\f';
break;
2141 if (c1 == EOF || c2 == EOF || c3 == EOF) {
2143 char *e = strerror(errno);
2144 snprintf(ee,
sizeof(ee),
2145 (
"loading properties (%s)," 2148 kmr_warning(0, 1, ee);
2153 snprintf(ee,
sizeof(ee),
2154 (
"loading properties (%s)," 2155 " file ends amid unicode (at line %d)"),
2156 filename, (lines + 1));
2157 kmr_warning(0, 1, ee);
2163 if (!(isxdigit(c0) && isxdigit(c1)
2164 && isxdigit(c2) && isxdigit(c3))) {
2165 snprintf(ee,
sizeof(ee),
2166 (
"loading properties (%s)," 2167 " file includes bad character" 2168 " in unicode (at line %d)"),
2169 filename, (lines + 1));
2170 kmr_warning(0, 1, ee);
2175 c = (kmr_load_properties_hex(c0) << 12);
2176 c |= (kmr_load_properties_hex(c1) << 8);
2177 c |= (kmr_load_properties_hex(c2) << 4);
2178 c |= kmr_load_properties_hex(c3);
2181 snprintf(ee,
sizeof(ee),
2182 (
"loading properties (%s)," 2183 " file includes non-latin character" 2184 " in unicode (at line %d)"),
2185 filename, (lines + 1));
2186 kmr_warning(0, 1, ee);
2201 assert(pos == -1 && valpos == -1);
2204 assert(pos == -1 && valpos == -1);
2207 case Key:
case KeySkp:
2208 assert(pos != -1 && valpos == -1);
2211 case ForSep:
case ForVal:
2212 assert(pos != -1 && valpos != -1);
2214 case Val:
case ValSkp:
2215 assert(pos != -1 && valpos != -1);
2228 if (iscntrl(c) && !escaped) {
2229 snprintf(ee,
sizeof(ee),
2230 (
"loading properties (%s)," 2231 " file includes bad control code (at line %d)"),
2232 filename, (lines + 1));
2233 kmr_warning(0, 1, ee);
2240 assert(pos == -1 && valpos == -1);
2242 kmr_load_properties_putc(c);
2246 assert(pos == -1 && valpos == -1);
2249 case Key:
case KeySkp:
2250 assert(pos != -1 && valpos == -1);
2251 kmr_load_properties_putc(c);
2254 case ForSep:
case ForVal:
case Val:
case ValSkp:
2255 assert(pos != -1 && valpos != -1);
2256 kmr_load_properties_putc(c);
2266 assert(pos == -1 && valpos == -1);
2270 assert(pos == -1 && valpos == -1);
2273 case Key:
case KeySkp:
2274 assert(pos != -1 && valpos == -1);
2275 kmr_load_properties_putc(
'\0');
2277 kmr_load_properties_putc(
'\0');
2278 kmr_put_property(info, b, valpos, pos);
2279 kmr_load_properties_reset();
2281 case ForSep:
case ForVal:
case Val:
case ValSkp:
2282 assert(pos != -1 && valpos != -1);
2283 kmr_load_properties_putc(
'\0');
2284 kmr_put_property(info, b, valpos, pos);
2285 kmr_load_properties_reset();
2290 case ' ':
case '\t':
case '\f':
2293 assert(pos == -1 && valpos == -1);
2296 assert(pos == -1 && valpos == -1);
2299 assert(pos != -1 && valpos == -1);
2300 kmr_load_properties_putc(
'\0');
2305 assert(pos != -1 && valpos == -1);
2307 case ForSep:
case ForVal:
2308 assert(pos != -1 && valpos != -1);
2311 assert(pos != -1 && valpos != -1);
2312 kmr_load_properties_putc(c);
2315 assert(pos != -1 && valpos != -1);
2323 assert(pos == -1 && valpos == -1);
2327 assert(pos == -1 && valpos == -1);
2329 case Key:
case KeySkp:
2330 assert(pos != -1 && valpos == -1);
2331 kmr_load_properties_putc(c);
2334 case ForSep:
case ForVal:
case Val:
case ValSkp:
2335 assert(pos != -1 && valpos != -1);
2336 kmr_load_properties_putc(c);
2345 assert(pos == -1 && valpos == -1);
2347 kmr_load_properties_putc(
'\0');
2352 assert(pos == -1 && valpos == -1);
2354 case Key:
case KeySkp:
2355 assert(pos != -1 && valpos == -1);
2356 kmr_load_properties_putc(
'\0');
2361 assert(pos != -1 && valpos != -1);
2364 case ForVal:
case Val:
case ValSkp:
2365 assert(pos != -1 && valpos != -1);
2366 kmr_load_properties_putc(c);
2386 cc = MPI_Info_get_nkeys(info, &nkeys);
2387 assert(cc == MPI_SUCCESS);
2388 for (
int i = 0; i < nkeys; i++) {
2389 char key[MPI_MAX_INFO_KEY + 1];
2390 char value[MPI_MAX_INFO_VAL + 1];
2393 cc = MPI_Info_get_nthkey(info, i, key);
2394 assert(cc == MPI_SUCCESS);
2395 cc = MPI_Info_get_valuelen(info, key, &vlen, &flag);
2396 assert(cc == MPI_SUCCESS && flag != 0);
2397 assert(vlen <= MPI_MAX_INFO_VAL);
2398 cc = MPI_Info_get(info, key, MPI_MAX_INFO_VAL, value, &flag);
2399 assert(cc == MPI_SUCCESS && flag != 0);
2400 printf(
"%s \"%s\"=\"%s\"\n", prefix, key, value);
2412 cc = MPI_Info_get_nkeys(src, &nkeys);
2413 assert(cc == MPI_SUCCESS);
2414 for (
int i = 0; i < nkeys; i++) {
2415 char key[MPI_MAX_INFO_KEY + 1];
2416 char value[MPI_MAX_INFO_VAL + 1];
2419 cc = MPI_Info_get_nthkey(src, i, key);
2420 assert(cc == MPI_SUCCESS);
2421 cc = MPI_Info_get_valuelen(src, key, &vlen, &flag);
2422 assert(cc == MPI_SUCCESS && flag != 0);
2423 assert(vlen <= MPI_MAX_INFO_VAL);
2424 cc = MPI_Info_get(src, key, MPI_MAX_INFO_VAL, value, &flag);
2425 assert(cc == MPI_SUCCESS && flag != 0);
2427 cc = MPI_Info_set(dst, key, value);
2428 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_free_string(char *s)
Frees a string strduped.
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.
int kmr_make_printable_info_string(char *s, size_t sz, MPI_Info info)
Fills the string buffer with the MPI_Info strings for printing.
#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_make_printable_argv_string(char *s, size_t sz, char **argv)
Fills the string buffer with the argv strings for printing.
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 KVS to stdout.