elpa_index.h 10 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

/*
 !f> interface
80
 !f>   function elpa_index_instance_c() result(index) bind(C, name="elpa_index_instance")
81
82
83
84
85
86
87
 !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_c(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
103
 !f>   function elpa_index_get_int_value_c(index, name, success) result(value) &
 !f>       bind(C, name="elpa_index_get_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
104
 !f>     import c_ptr, c_int, c_char
105
106
107
108
 !f>     type(c_ptr), value                         :: index
 !f>     character(kind=c_char), intent(in)         :: name(*)
 !f>     integer(kind=c_int), intent(out), optional :: success
 !f>     integer(kind=c_int)                        :: value
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
109
110
111
 !f>   end function
 !f> end interface
 */
112
int elpa_index_get_int_value(elpa_index_t index, char *name, int *success);
113

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
114
115
116

/*
 !f> interface
117
118
 !f>   function elpa_index_set_int_value_c(index, name, value, force_writable) result(success) &
 !f>       bind(C, name="elpa_index_set_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
119
120
121
122
 !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
123
 !f>     integer(kind=c_int),intent(in), value :: force_writable
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
124
125
126
127
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
128
int elpa_index_set_int_value(elpa_index_t index, char *name, int value, int force_writable);
129
130
131
132


/*
 !f> interface
133
 !f>   function elpa_index_int_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_int_value_is_set")
134
135
136
137
138
139
140
 !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
 */
141
142
143
144
145
int elpa_index_int_value_is_set(elpa_index_t index, char *name);


/*
 !f> interface
146
 !f>   function elpa_index_get_int_loc_c(index, name) result(loc) bind(C, name="elpa_index_get_int_loc")
147
148
149
150
151
152
153
154
 !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);
155
156
157
158


/*
 !f> interface
159
 !f>   function elpa_index_get_double_value_c(index, name, success) result(value) bind(C, name="elpa_index_get_double_value")
160
 !f>     import c_ptr, c_int, c_double, c_char
161
162
163
164
 !f>     type(c_ptr), value                              :: index
 !f>     character(kind=c_char), intent(in)              :: name(*)
 !f>     integer(kind=c_int), intent(out), optional      :: success
 !f>     real(kind=c_double)                             :: value
165
166
167
 !f>   end function
 !f> end interface
 */
168
169
170
171
172
double elpa_index_get_double_value(elpa_index_t index, char *name, int *success);


/*
 !f> interface
173
174
 !f>   function elpa_index_set_double_value_c(index, name, value, force_writable) result(success) &
 !f>       bind(C, name="elpa_index_set_double_value")
175
176
177
178
 !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
179
 !f>     integer(kind=c_int),intent(in), value :: force_writable
180
181
182
183
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
184
int elpa_index_set_double_value(elpa_index_t index, char *name, double value, int force_writable);
185
186
187
188


/*
 !f> interface
189
190
 !f>   function elpa_index_double_value_is_set_c(index, name) result(success) &
 !f>       bind(C, name="elpa_index_double_value_is_set")
191
192
193
194
195
196
197
198
 !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);
199
200
201
202


/*
 !f> interface
203
 !f>   function elpa_index_get_double_loc_c(index, name) result(loc) bind(C, name="elpa_index_get_double_loc")
204
205
206
207
208
209
210
 !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
 */
211
double* elpa_index_get_double_loc(elpa_index_t index, char *name);
212
213
214
215


/*
 !f> interface
216
 !f>   function elpa_index_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_value_is_set")
217
 !f>     import c_ptr, c_int, c_char
218
219
220
221
222
223
 !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
 */
224
225
226
227
228
int elpa_index_value_is_set(elpa_index_t index, char *name);


/*
 !f> interface
229
230
 !f>   function elpa_int_value_to_string_c(name, value, string) &
 !f>              result(error) bind(C, name="elpa_int_value_to_string")
231
232
233
234
235
236
237
238
239
 !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>
 */
240
int elpa_int_value_to_string(char *name, int value, const char **string);
241
242
243
244


/*
 !f> interface
245
246
 !f>   pure function elpa_int_value_to_strlen_c(name, value) &
 !f>                   result(length) bind(C, name="elpa_int_value_to_strlen")
247
248
249
 !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
250
 !f>     integer(kind=c_int) :: length
251
252
253
254
 !f>   end function
 !f> end interface
 !f>
 */
255
int elpa_int_value_to_strlen(char *name, int value);
256
257
258
259


/*
 !f> interface
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
 !f>   pure function elpa_index_int_value_to_strlen_c(index, name) &
 !f>                   result(length) bind(C, name="elpa_index_int_value_to_strlen")
 !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) :: length
 !f>   end function
 !f> end interface
 !f>
 */
int elpa_index_int_value_to_strlen(elpa_index_t index, char *name);


/*
 !f> interface
 !f>   function elpa_int_string_to_value_c(name, string, value) result(error) bind(C, name="elpa_int_string_to_value")
276
277
278
279
280
281
282
283
284
 !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>
 */
285
int elpa_int_string_to_value(char *name, char *string, int *value);
286
287
288
289


/*
 !f> interface
290
291
 !f>   function elpa_option_cardinality_c(name) result(n) bind(C, name="elpa_option_cardinality")
 !f>     import c_int, c_char
292
293
294
295
296
297
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int) :: n
 !f>   end function
 !f> end interface
 !f>
 */
298
int elpa_option_cardinality(char *name);
299
300
301

/*
 !f> interface
302
303
 !f>   function elpa_option_enumerate_c(name, i) result(value) bind(C, name="elpa_option_enumerate")
 !f>     import c_int, c_char
304
305
306
307
308
309
310
 !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>
 */
311
int elpa_option_enumerate(char *name, int i);
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326


/*
 !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);