Skip to content

Commit 4145ddc

Browse files
committed
First API mockup
Signed-off-by: Aurelien Bouteiller <bouteill@icl.utk.edu>
1 parent 70ba4e9 commit 4145ddc

3 files changed

Lines changed: 195 additions & 0 deletions

File tree

parsec/include/parsec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "parsec/datatype.h"
1515
#include "parsec/scheduling.h"
1616
#include "parsec/utils/debug.h"
17+
#include "parsec/utils/info.h"
1718

1819
#include "parsec/interfaces/interface.h"
1920
#include "parsec/interfaces/dtd/insert_function.h"

parsec/utils/info.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "parsec_config.h"
2+
#include "parsec.h"
3+
#include "parsec/utils/info.h"
4+
#include "parsec/class/hashtable.h"
5+
#include "parsec/class/parsec_object.h"
6+
7+
PARSEC_OBJ_CLASS_INSTANCE(parsec_info_t, parsec_hashtable_t, NULL, NULL);
8+
9+
int parsec_info_set(parsec_info_t *info, const char *key, char *value) {
10+
return PARSEC_NOT_IMPLEMENTED;
11+
}
12+
13+
int parsec_info_get(parsec_info_t *info, const char *key, char **value) {
14+
return PARSEC_NOT_IMPLEMENTED;
15+
}
16+
17+
int parsec_info_clear(parsec_info_t *info) {
18+
/* must clear in-place as multiple refs ot the info may be held */
19+
return PARSEC_NOT_IMPLEMENTED;
20+
}
21+
22+
int parsec_context_get_info(parsec_context_t *ctx, parsec_info_t **info) {
23+
if(NULL == ctx->info) {
24+
ctx->info = PARSEC_OBJ_NEW(parsec_info_t);
25+
}
26+
return ctx->info;
27+
}
28+
29+
int parsec_taskpool_get_info(parsec_taskpool_t *tp, parsec_info_t **info) {
30+
if(NULL == tp->info) {
31+
tp->info = PARSEC_OBJ_NEW(parsec_info_t);
32+
}
33+
return tp->info;
34+
}

parsec/utils/info.h

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* Copyright (c) 2022 The University of Tennessee and The University
3+
* of Tennessee Research Foundation. All rights
4+
* reserved.
5+
*
6+
* $COPYRIGHT$
7+
*
8+
* Additional copyrights may follow
9+
*
10+
* $HEADER$
11+
*/
12+
13+
/**
14+
* @file
15+
*
16+
* Generic routines for "info" handling. This is a sinple key-value store that
17+
* is independent from the main MCA param key-value store. Helpful for creating
18+
* info strings without affecting MCA params.
19+
*/
20+
21+
#ifndef PARSEC_INFO_H
22+
#define PARSEC_INFO_H
23+
24+
#include "parsec/parsec_config.h"
25+
26+
#ifdef PARSEC_HAVE_SYS_TYPES_H
27+
#include <sys/types.h>
28+
#endif
29+
#ifdef PARSEC_HAVE_STDBOOL_H
30+
#include <stdbool.h>
31+
#endif
32+
33+
BEGIN_C_DECLS
34+
35+
36+
typedef char* parsec_info_key_t;
37+
typedef char* parsec_info_value_t;
38+
39+
40+
struct parsec_info_value_s {
41+
char val[PARSEC_INFO_VALUE_LEN];
42+
} parsec_info_value_t;
43+
44+
45+
struct parsec_info_s {
46+
parsec_hashtable_t super;
47+
} parsec_info_t;
48+
49+
PARSEC_OBJ_CLASS(parsec_info_t);
50+
51+
} parsec_info_t;
52+
53+
#define PARSEC_INFO_VALUE_NULL NULL
54+
55+
56+
/**
57+
* Set the key-value pair in the target info object.
58+
*
59+
* @param info Pointer to the target info object. Must not be
60+
* NULL.
61+
* @param key String for the key, max length PARSEC_INFO_KEY_LEN.
62+
* @param value String for the value to attache to the key, max
63+
* length PARSEC_INFO_VALUE_LEN.
64+
*
65+
* @retval PARSEC_SUCCESS On success
66+
* @retval PARSEC_ERROR On failure, values lower than PARSEC_ERROR may
67+
* elaborate on the particular error type.
68+
*
69+
* This function associates a string value to the string key in the
70+
* key-value store info. The value string is copied to the internal
71+
* storage of the key-value store. To reiterate, there is no need to
72+
* keep a copy of the value.
73+
*
74+
* If the key is already set to a value, the previous value is
75+
* overwritten for te key. In particular, if the value is
76+
* PARSEC_INFO_VALUE_NULL, the previous key-value pair is removed
77+
* from the info.
78+
*/
79+
parsec_info_set(parsec_info_t *info, const char *key, const char *value);
80+
81+
/**
82+
* Get the value associated with the key in the target info object.
83+
*
84+
* @param info Pointer to the target info object. Must not be
85+
* NULL.
86+
* @param key String for the key, max length PARSEC_INFO_KEY_LEN.
87+
* @param value Pointer to the string of the value to retrieve;
88+
*
89+
* @retval PARSEC_SUCCESS On success
90+
* @retval PARSEC_ERROR On failure, values lower than PARSEC_ERROR may
91+
* elaborate on the particular error type.
92+
*
93+
* This function obtains the string value associated with the string
94+
* key in the key-value store info. A pointer to the internal value
95+
* string is returned. To reiterate, the value is shared with the
96+
* internal storage of the info object and must not be freed.
97+
*
98+
* If the key is not set to a value, the value is set to
99+
* PARSEC_INFO_VALUE_NULL.
100+
*/
101+
parsec_info_get(parsec_info_t *info, const char *key, char **value);
102+
103+
/**
104+
* Clear all key-values from the target info object.
105+
*
106+
* @param info Pointer to the target info object. Must not be
107+
* NULL.
108+
*
109+
* @retval PARSEC_SUCCESS On success
110+
* @retcal PARSEC_ERROR On failure, values lower than PARSEC_ERROR may
111+
* elaborate on the particular error type.
112+
*
113+
* This function clears all previously set key-values from the target
114+
* key-value store object; that is, it is equivalent to calling
115+
* parsec_info_set with the value PARSEC_INFO_VALUE_NULL, for any key
116+
* previously set on the info.
117+
*/
118+
parsec_info_clear(parserc_info_t *info);
119+
120+
/**
121+
* Obtain the info object associated with the givent context
122+
*
123+
* @param ctx The context to query
124+
* @param info Pointer to the info object associated with the context
125+
*
126+
* @retval PARSEC_SUCCESS On success
127+
* @retval PARSEC_ERROR On failure
128+
*
129+
* The returned info object may be empty (that is, it has no values
130+
* associated with any keys), but is always returns a reference to a
131+
* valid info object.
132+
*
133+
* Key-values added to the info object will be implicitly applied to
134+
* the context, that is, the info is a reference to the info object
135+
* internally held by the context.
136+
*/
137+
parsec_context_get_info(parsec_context_t *ctx, parsec_info_t **info);
138+
139+
/**
140+
* Obtain the info object associated with the givent taskpool
141+
*
142+
* @param tp The taskpool to query
143+
* @param info Pointer to the info object associated with the context
144+
*
145+
* @retval PARSEC_SUCCESS On success
146+
* @retval PARSEC_ERROR On failure
147+
*
148+
* The returned info object may be empty (that is, it has no values
149+
* associated with any keys), but is always returns a reference to a
150+
* valid info object.
151+
*
152+
* Key-values added to the info object will be implicitly applied to
153+
* the taskpool, that is, the info is a reference to the info object
154+
* internally held by the taskpool.
155+
*/
156+
parsec_taskpool_get_info(parsec_taskpool_t *tp, parsec_info_t **info);
157+
158+
END_C_DECLS
159+
160+
#endif /* PARSEC_INFO_H */

0 commit comments

Comments
 (0)