KMR
Macros | Functions | Variables
kmrutil.c File Reference

Utilities. More...

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include "kmr.h"
#include "kmrimpl.h"

Go to the source code of this file.

Macros

#define CONTNL   0x010000
 
#define kmr_load_properties_check_getc_error(C)
 
#define kmr_load_properties_grow()
 
#define kmr_load_properties_hex(C)
 
#define kmr_load_properties_putc(C)
 
#define kmr_load_properties_replace_cr()
 
#define kmr_load_properties_reset()   {pos = -1; valpos = -1; scan = ForKey;}
 
#define MAX(a, b)   (((a)>(b))?(a):(b))
 
#define MIN(a, b)   (((a)<(b))?(a):(b))
 
#define NEVERHERE   0
 

Functions

int kmr_assert_sorted (KMR_KVS *kvi, _Bool locally, _Bool shuffling, _Bool ranking)
 Checks a key-value stream is sorted. More...
 
static unsigned long kmr_bitreverse (unsigned long bits)
 
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. More...
 
static _Bool kmr_check_command_existence (KMR *mr, char *command, _Bool search, char *msg)
 
int kmr_check_options (KMR *mr, MPI_Info info)
 
int kmr_copy_info_to_kvs (MPI_Info src, KMR_KVS *kvo)
 Copies mpi-info entires into kvs. More...
 
int kmr_copy_kvs_to_info (KMR_KVS *kvi, MPI_Info dst)
 Copies kvs entires into mpi-info. More...
 
int kmr_copy_mpi_info (MPI_Info src, MPI_Info dst)
 Copies contents of MPI_Info. More...
 
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. More...
 
long kmr_dblint_ff (double v)
 
int kmr_dump_keyed_records (const struct kmr_keyed_record *ev, KMR_KVS *kvi)
 
int kmr_dump_kv (const struct kmr_kv_box kv, const KMR_KVS *kvs, char *buf, int buflen)
 Dumps contents of a key-value. More...
 
int kmr_dump_kvs (KMR_KVS *kvs, int flag)
 Dumps contents of a key-value stream to stdout. More...
 
static int kmr_dump_kvs_fn (const struct kmr_kv_box kv, const KMR_KVS *kvs, KMR_KVS *kvso, void *p, const long i)
 
int kmr_dump_kvs_stats (KMR_KVS *kvs, int level)
 Dumps contents of a key-value stream, with values are pairs. More...
 
int kmr_dump_mpi_info (char *prefix, MPI_Info info)
 Dumps simply contents in MPI_Info. More...
 
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. More...
 
void kmr_dump_slot (union kmr_unit_sized e, int len, enum kmr_kv_field data, char *buf, int buflen)
 
void kmr_error (KMR *mr, char *m)
 
void kmr_error2 (KMR *mr, char *m, const char *file, const int line, const char *func)
 
void kmr_error_at_site (KMR *mr, char *m, struct kmr_code_line *site)
 
void kmr_error_kvs (KMR *mr, char *m, KMR_KVS *kvs)
 
void kmr_error_kvs2 (KMR *mr, char *m, KMR_KVS *kvs, const char *file, const int line, const char *func)
 
void kmr_error_kvs_at_site (KMR *mr, char *m, KMR_KVS *kvs, struct kmr_code_line *site)
 
void kmr_error_mpi (KMR *mr, char *m, int errorcode)
 
int kmr_fgetc (FILE *f)
 Does fgetc, avoiding EINTR. More...
 
unsigned long kmr_fix_bits_endian_ff (unsigned long b)
 Fixes little-endian bits used in Fortran to host-endian. More...
 
FILE * kmr_fopen (const char *n, const char *m)
 Does fopen, avoiding EINTR. More...
 
int kmr_get_key_type_ff (const KMR_KVS *kvs)
 
int kmr_get_nprocs (const KMR *mr)
 
int kmr_get_nprocs_ff (const KMR_KVS *kvs)
 
int kmr_get_rank (const KMR *mr)
 
int kmr_get_rank_ff (const KMR_KVS *kvs)
 
int kmr_get_value_type_ff (const KMR_KVS *kvs)
 
int kmr_getdtablesize (KMR *mr)
 Does getdtablesize(); it is defined, because it is not Posix. More...
 
int kmr_imax_one_fn (const struct kmr_kv_box kv[], const long n, const KMR_KVS *kvi, KMR_KVS *kvo, void *p)
 
int kmr_install_watch_program (KMR *mr, char *msg)
 
static char * kmr_install_watch_program_on_rank0 (KMR *mr, char *msg)
 
double kmr_intdbl_ff (long v)
 
void * kmr_intptr_ff (long p)
 
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. More...
 
int kmr_isum_one_fn (const struct kmr_kv_box kv[], const long n, const KMR_KVS *kvi, KMR_KVS *kvo, void *p)
 
int kmr_k_node (KMR *mr, kmr_k_position_t p)
 Gets TOFU position (physical coordinates) of the node. More...
 
static int kmr_k_node_by_rank (KMR *mr, kmr_k_position_t p)
 
int kmr_load_preference (KMR *mr, MPI_Info info)
 
int kmr_load_properties (MPI_Info info, char *filename)
 Loads properties into MPI_Info (in Latin1 characters). More...
 
int kmr_local_element_count (KMR_KVS *kvs, long *v)
 Gets the number of key-value pairs locally on each rank. More...
 
void kmr_log_map (KMR *mr, KMR_KVS *kvs, struct kmr_kv_box *ev, long i, long cnt, kmr_mapfn_t m, double dt)
 
void kmr_log_reduce (KMR *mr, KMR_KVS *kvs, struct kmr_kv_box *ev, long n, kmr_redfn_t r, double dt)
 
void kmr_mfree (void *p, size_t sz)
 
uint64_t kmr_mpi_constant_value (char *s)
 
size_t kmr_mpi_type_size (char *s)
 
int kmr_msleep (int msec, int interval)
 
void kmr_open_log (KMR *mr)
 
int kmr_parse_boolean (char *s, int *r)
 
int kmr_parse_int (char *s, int *r)
 
static int kmr_parse_size_t (char *s, size_t *r)
 
void kmr_print_file_options (struct kmr_file_option opt)
 
void kmr_print_options (struct kmr_option opt)
 
void kmr_print_spawn_options (struct kmr_spawn_option opt)
 
void kmr_print_string (char *msg, char *s, int len)
 
long kmr_ptrint_ff (void *p)
 
char * kmr_ptrstr_ff (char *s)
 
static int kmr_put_property (MPI_Info info, char *b, int valpos, int end)
 
int kmr_scan_argv_strings (KMR *mr, char *s, size_t len, int maxargc, int *argc, char **argv, _Bool ws, char *msg)
 
static int kmr_set_info_fn (const struct kmr_kv_box kv, const KMR_KVS *kvi, KMR_KVS *kvo, void *p, const long i)
 
int kmr_set_option_by_strings (KMR *mr, char *k, char *v)
 
void * kmr_strdup (char *s)
 STRDUP, but aborts on failure. More...
 
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. More...
 
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 interfaces. More...
 
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 interfaces. More...
 
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 interfaces. More...
 
long kmr_strint_ff (char *p)
 
char * kmr_strptr_ff (char *s)
 Returns itself; this is for Fortran-binding. More...
 
void kmr_warning (KMR *mr, unsigned int mask, char *m)
 
double kmr_wtime ()
 

Variables

int kmr_kv_field_bad = KMR_KV_BAD
 
int kmr_kv_field_cstring = KMR_KV_CSTRING
 
int kmr_kv_field_float8 = KMR_KV_FLOAT8
 
int kmr_kv_field_integer = KMR_KV_INTEGER
 
int kmr_kv_field_opaque = KMR_KV_OPAQUE
 
int kmr_kv_field_pointer_owned = KMR_KV_POINTER_OWNED
 
int kmr_kv_field_pointer_unmanaged = KMR_KV_POINTER_UNMANAGED
 

Detailed Description

Utilities.

Definition in file kmrutil.c.

Macro Definition Documentation

#define kmr_load_properties_check_getc_error (   C)
Value:
if ((C) == EOF && errno != 0) { \
char *e = strerror(errno); \
snprintf(ee, sizeof(ee), "loading properties (%s), fgetc(): %s", \
filename, e); \
kmr_warning(0, 1, ee); \
fclose(f); \
free(b); \
return MPI_ERR_ARG; \
}
#define kmr_load_properties_grow ( )
Value:
if (pos >= (blen - 1)) { \
blen *= 2; b = realloc(b, (size_t)blen); assert(b != 0); }
#define kmr_load_properties_putc (   C)
Value:
{ \
assert(pos != -1); \
b[pos++] = (char)(C); kmr_load_properties_grow(); }
#define kmr_load_properties_hex (   C)
Value:
(('0' <= (C) && (C) <= '9') \
? ((C) - '0') \
: (('a' <= (C) && (C) <= 'f') \
? ((C) - 'a') : ((C) - 'A')))
#define kmr_load_properties_replace_cr ( )
Value:
if (c == '\r') { \
int c1 = kmr_fgetc(f); \
kmr_load_properties_check_getc_error(c1); \
if (c1 != '\n') { \
ungetc(c1, f); \
} \
c = '\n'; \
}
int kmr_fgetc(FILE *f)
Does fgetc, avoiding EINTR.
Definition: kmrutil.c:622

Function Documentation

void kmr_string_truncation ( KMR mr,
size_t  sz,
char *  s 
)

Modifies the string end with by "..." for indicating truncation, used on the result of snprintf.

Definition at line 193 of file kmrutil.c.

char* kmr_strptr_ff ( char *  s)

Returns itself; this is for Fortran-binding.

Definition at line 208 of file kmrutil.c.

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.

It returns the string length in C limited by N.

Definition at line 257 of file kmrutil.c.

unsigned long kmr_fix_bits_endian_ff ( unsigned long  b)

Fixes little-endian bits used in Fortran to host-endian.

Definition at line 284 of file kmrutil.c.

int kmr_local_element_count ( KMR_KVS kvs,
long *  v 
)

Gets the number of key-value pairs locally on each rank.

Definition at line 349 of file kmrutil.c.

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 interfaces.

Definition at line 361 of file kmrutil.c.

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 interfaces.

Definition at line 386 of file kmrutil.c.

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 interfaces.

Definition at line 405 of file kmrutil.c.

int kmr_k_node ( KMR mr,
kmr_k_position_t  p 
)

Gets TOFU position (physical coordinates) of the node.

Errors are fatal (aborts).

Definition at line 441 of file kmrutil.c.

void* kmr_bsearch ( const void *  key,
const void *  base,
size_t  nel,
size_t  size,
int(*)(const void *, const void *)  compar 
)

Searches a key entry like bsearch(3C), but returns a next greater entry instead of null on no match.

Thus, it may return a pointer ((char *)base+(nel*size)) when a key is larger than all.

Definition at line 565 of file kmrutil.c.

void* kmr_strdup ( char *  s)

STRDUP, but aborts on failure.

Definition at line 592 of file kmrutil.c.

FILE* kmr_fopen ( const char *  n,
const char *  m 
)

Does fopen, avoiding EINTR.

Definition at line 610 of file kmrutil.c.

int kmr_fgetc ( FILE *  f)

Does fgetc, avoiding EINTR.

Definition at line 622 of file kmrutil.c.

int kmr_getdtablesize ( KMR mr)

Does getdtablesize(); it is defined, because it is not Posix.

Definition at line 635 of file kmrutil.c.

int kmr_assert_sorted ( KMR_KVS kvi,
_Bool  locally,
_Bool  shuffling,
_Bool  ranking 
)

Checks a key-value stream is sorted.

When not LOCALLY, it collects all the entries to rank-zero for checking.

Definition at line 702 of file kmrutil.c.

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.

It should be used with the INSPECT option for map, because the array entries may point into the input key-value stream. It is a map-function.

Definition at line 934 of file kmrutil.c.

int kmr_copy_info_to_kvs ( MPI_Info  src,
KMR_KVS kvo 
)

Copies mpi-info entires into kvs.

Definition at line 982 of file kmrutil.c.

int kmr_copy_kvs_to_info ( KMR_KVS kvi,
MPI_Info  dst 
)

Copies kvs entires into mpi-info.

It assumes keys/values are strings (no checks). It consumes KVI.

Definition at line 1034 of file kmrutil.c.

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.

Ellipses appear if string does not fit in the buffer.

Definition at line 1511 of file kmrutil.c.

int kmr_dump_kv ( const struct kmr_kv_box  kv,
const KMR_KVS kvs,
char *  buf,
int  buflen 
)

Dumps contents of a key-value.

Definition at line 1585 of file kmrutil.c.

int kmr_dump_kvs ( KMR_KVS kvs,
int  flag 
)

Dumps contents of a key-value stream to stdout.

Argument FLAG is nothing, ignored.

Definition at line 1609 of file kmrutil.c.

int kmr_dump_kvs_stats ( KMR_KVS kvs,
int  level 
)

Dumps contents of a key-value stream, with values are pairs.

Prints the total number of key-value pairs. It prints on the rank0 only.

Definition at line 1659 of file kmrutil.c.

int kmr_load_properties ( MPI_Info  info,
char *  filename 
)

Loads properties into MPI_Info (in Latin1 characters).

It runs only on the main-thread. It returns MPI_SUCCESS normally. It stores only Latin1 strings because MPI_Info does. Refer to the JDK document "java.util.Properties.load()" for the ".properties" format.

Definition at line 1851 of file kmrutil.c.

int kmr_dump_mpi_info ( char *  prefix,
MPI_Info  info 
)

Dumps simply contents in MPI_Info.

Definition at line 2212 of file kmrutil.c.

int kmr_copy_mpi_info ( MPI_Info  src,
MPI_Info  dst 
)

Copies contents of MPI_Info.

The destination info is modified.

Definition at line 2238 of file kmrutil.c.