2 * Copyright (c) 2017, Intel Corporation. All rights reserved.
3 * See LICENSE in this directory.
5 * Runtime functions used by OFI LRTS machine layer to exchange
6 * addresses during the initialization.
8 * This example uses the PMI2 API as described in pmi2.h.
17 /* For encode/decode functions */
18 #include "runtime-codec.h"
20 static int initialized
;
21 static int max_keylen
= PMI2_MAX_KEYLEN
;
22 static int max_valuelen
= PMI2_MAX_VALLEN
;
27 int runtime_init(int *rank
, int *jobsize
)
32 int max_kvsnamelen
= PMI2_MAX_VALLEN
;
34 ret
= PMI2_Init(&spawned
, jobsize
, rank
, &appnum
);
35 if (PMI2_SUCCESS
!= ret
) {
39 kvsname
= calloc(max_kvsnamelen
, sizeof(char));
44 ret
= PMI2_Job_GetId(kvsname
, max_kvsnamelen
);
45 if (PMI2_SUCCESS
!= ret
) {
49 key
= calloc(max_keylen
, sizeof(char));
55 value
= calloc(max_valuelen
, sizeof(char));
71 ret
= PMI2_Finalize();
72 if (PMI2_SUCCESS
!= ret
) {
94 int runtime_get_max_keylen(int *len
)
103 int runtime_kvs_put(const char *k
, const void *v
, int vlen
)
113 if (keylen
> max_keylen
) {
117 if (vlen
> max_valuelen
) {
121 ret
= encode(v
, vlen
, value
, max_valuelen
);
126 ret
= PMI2_KVS_Put(k
, value
);
134 int runtime_kvs_get(const char *k
, void *v
, int vlen
)
143 ret
= PMI2_KVS_Get(kvsname
, PMI2_ID_NULL
, k
, value
, max_valuelen
, &len
);
148 ret
= decode(value
, v
, vlen
);
156 int runtime_barrier()
164 ret
= PMI2_KVS_Fence();