elpa_index.h 9.42 KB
Newer Older
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
1
2
3
4
5
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <search.h>
6
7
#include <math.h>

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
8
9
10
11
#include <elpa/elpa.h>

#define nelements(x) (sizeof(x)/sizeof(x[0]))

12
13
14
15
#define FOR_ALL_TYPES(X) \
        X(int, "%d", -1) \
        X(double, "%g", NAN)

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
16
17
18
19
20
21
/* A simple structure for storing values to a pre-set
 * number of keys */

/* Forward declaration of configuration structure */
typedef struct elpa_index_struct* elpa_index_t;

22
/* Function type for the cardinality */
23
typedef int (*elpa_index_cardinality_t)(void);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
24

25
26
/* Function type to enumerate all possible values, starting from 0 */
typedef int (*elpa_index_enumerate_int_option_t)(int i);
27

28
/* Function types to check the validity of a value */
29
typedef int (*elpa_index_valid_int_t)(elpa_index_t index, int n, int new_value);
30
typedef int (*elpa_index_valid_double_t)(elpa_index_t index, int n, double new_value);
31
32

/* Function type to give a string representation of a value */
33
typedef const char* (*elpa_index_to_string_int_t)(int n);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
34
35
36


typedef struct {
37
38
39
40
41
42
43
        char *name;
        char *description;
        char *env_default;
        char *env_force;
        int once;
        int readonly;
} elpa_index_entry_t;
44
45


46
47
48
49
50
51
52
typedef struct {
        elpa_index_entry_t base;
        int default_value;
        elpa_index_valid_int_t valid;
        elpa_index_cardinality_t cardinality;
        elpa_index_enumerate_int_option_t enumerate;
        elpa_index_to_string_int_t to_string;
53
54
} elpa_index_int_entry_t;

55

56
typedef struct {
57
58
59
        elpa_index_entry_t base;
        double default_value;
        elpa_index_valid_double_t valid;
60
} elpa_index_double_entry_t;
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
61

62
63
64
65
66
enum NOTIFY_FLAGS {
        NOTIFY_ENV_DEFAULT = (1<<0),
        NOTIFY_ENV_FORCE   = (1<<1),
};

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
67
struct elpa_index_struct {
68
69
70
71
72
73
74
#define STRUCT_MEMBERS(TYPE, ...) \
        struct { \
        TYPE *values; \
        int *is_set; \
        int *notified; \
        } TYPE##_options;
        FOR_ALL_TYPES(STRUCT_MEMBERS)
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
75
76
};

77
78
79
80
81
82
83
84
85
86
87

/*
 !f> interface
 !f>   function elpa_index_instance() result(index) bind(C, name="elpa_index_instance")
 !f>     import c_ptr
 !f>     type(c_ptr) :: index
 !f>   end function
 !f> end interface
 */
elpa_index_t elpa_index_instance();

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
88
89
90

/*
 !f> interface
91
 !f>   subroutine elpa_index_free(index) bind(C, name="elpa_index_free")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
92
93
94
95
96
 !f>     import c_ptr
 !f>     type(c_ptr), value :: index
 !f>   end subroutine
 !f> end interface
 */
97
98
void elpa_index_free(elpa_index_t index);

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
99
100
101

/*
 !f> interface
102
 !f>   function elpa_index_get_int_value(index, name, success) result(value) bind(C, name="elpa_index_get_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
103
104
105
106
107
108
109
110
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int)                :: value
 !f>     integer(kind=c_int), optional      :: success
 !f>   end function
 !f> end interface
 */
111
int elpa_index_get_int_value(elpa_index_t index, char *name, int *success);
112

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
113
114
115

/*
 !f> interface
116
 !f>   function elpa_index_set_int_value(index, name, value) result(success) bind(C, name="elpa_index_set_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
117
118
119
120
121
122
123
124
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int),intent(in), value :: value
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
125
int elpa_index_set_int_value(elpa_index_t index, char *name, int value);
126
127
128
129
130
131
132
133
134
135
136
137


/*
 !f> interface
 !f>   function elpa_index_int_value_is_set(index, name) result(success) bind(C, name="elpa_index_int_value_is_set")
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
138
139
140
141
142
143
144
145
146
147
148
149
150
151
int elpa_index_int_value_is_set(elpa_index_t index, char *name);


/*
 !f> interface
 !f>   function elpa_index_get_int_loc(index, name) result(loc) bind(C, name="elpa_index_get_int_loc")
 !f>     import c_ptr, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     type(c_ptr)                        :: loc
 !f>   end function
 !f> end interface
 */
int* elpa_index_get_int_loc(elpa_index_t index, char *name);
152
153
154
155
156
157
158
159
160
161
162
163
164


/*
 !f> interface
 !f>   function elpa_index_get_double_value(index, name, success) result(value) bind(C, name="elpa_index_get_double_value")
 !f>     import c_ptr, c_int, c_double, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     real(kind=c_double)                :: value
 !f>     integer(kind=c_int), optional      :: success
 !f>   end function
 !f> end interface
 */
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
double elpa_index_get_double_value(elpa_index_t index, char *name, int *success);


/*
 !f> interface
 !f>   function elpa_index_set_double_value(index, name, value) result(success) bind(C, name="elpa_index_set_double_value")
 !f>     import c_ptr, c_int, c_double, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     real(kind=c_double),intent(in), value :: value
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
int elpa_index_set_double_value(elpa_index_t index, char *name, double value);


/*
 !f> interface
 !f>   function elpa_index_double_value_is_set(index, name) result(success) bind(C, name="elpa_index_double_value_is_set")
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
int elpa_index_double_value_is_set(elpa_index_t index, char *name);
193
194
195
196
197
198
199
200
201
202
203
204


/*
 !f> interface
 !f>   function elpa_index_get_double_loc(index, name) result(loc) bind(C, name="elpa_index_get_double_loc")
 !f>     import c_ptr, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     type(c_ptr)                        :: loc
 !f>   end function
 !f> end interface
 */
205
double* elpa_index_get_double_loc(elpa_index_t index, char *name);
206
207
208
209


/*
 !f> interface
210
211
 !f>   function elpa_index_value_is_set(index, name) result(success) bind(C, name="elpa_index_value_is_set")
 !f>     import c_ptr, c_int, c_char
212
213
214
215
216
217
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
int elpa_index_value_is_set(elpa_index_t index, char *name);


/*
 !f> interface
 !f>   function elpa_index_int_value_to_string_c(name, value, string) &
 !f>              result(error) bind(C, name="elpa_index_int_value_to_string")
 !f>     import c_int, c_ptr, c_char
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int), intent(in), value :: value
 !f>     type(c_ptr), intent(out) :: string
 !f>     integer(kind=c_int) :: error
 !f>   end function
 !f> end interface
 !f>
 */
int elpa_index_int_value_to_string(char *name, int value, const char **string);


/*
 !f> interface
 !f>   pure function elpa_index_int_value_to_string_helper_c(name, value) &
 !f>                   result(string) bind(C, name="elpa_index_int_value_to_string_helper")
 !f>     import c_int, c_ptr, c_char
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int), intent(in), value :: value
 !f>     type(c_ptr) :: string
 !f>   end function
 !f> end interface
 !f>
 */
const char *elpa_index_int_value_to_string_helper(char *name, int value);


/*
 !f> interface
 !f>   function elpa_index_int_string_to_value_c(name, string, value) result(error) bind(C, name="elpa_index_int_string_to_value")
 !f>     import c_int, c_ptr, c_char
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     character(kind=c_char), intent(in) :: string(*)
 !f>     integer(kind=c_int), intent(out) :: value
 !f>     integer(kind=c_int) :: error
 !f>   end function
 !f> end interface
 !f>
 */
int elpa_index_int_string_to_value(char *name, char *string, int *value);


/*
 !f> interface
 !f>   function elpa_index_cardinality_c(index, name) result(n) bind(C, name="elpa_index_cardinality")
 !f>     import c_int, c_ptr, c_char
 !f>     type(c_ptr), intent(in), value :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int) :: n
 !f>   end function
 !f> end interface
 !f>
 */
int elpa_index_cardinality(elpa_index_t index, char *name);

/*
 !f> interface
 !f>   function elpa_index_enumerate_c(index, name, i) result(value) bind(C, name="elpa_index_enumerate")
 !f>     import c_int, c_ptr, c_char
 !f>     type(c_ptr), intent(in), value :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int), intent(in), value :: i
 !f>     integer(kind=c_int) :: value
 !f>   end function
 !f> end interface
 !f>
 */
int elpa_index_enumerate(elpa_index_t index, char *name, int i);


/*
 !f> interface
 !f>   function elpa_index_int_is_valid_c(index, name, new_value) result(success) bind(C, name="elpa_index_int_is_valid")
 !f>     import c_int, c_ptr, c_char
 !f>     type(c_ptr), intent(in), value :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int), intent(in), value :: new_value
 !f>     integer(kind=c_int) :: success
 !f>   end function
 !f> end interface
 !f>
 */
int elpa_index_int_is_valid(elpa_index_t index, char *name, int new_value);