elpa_index.h 9.75 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
 !f>   function elpa_index_get_int_value_c(index, name, success) result(value) bind(C, name="elpa_index_get_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
103
 !f>     import c_ptr, c_int, c_char
104
105
106
107
 !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
108
109
110
 !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_c(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


/*
 !f> interface
130
 !f>   function elpa_index_int_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_int_value_is_set")
131
132
133
134
135
136
137
 !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
int elpa_index_int_value_is_set(elpa_index_t index, char *name);


/*
 !f> interface
143
 !f>   function elpa_index_get_int_loc_c(index, name) result(loc) bind(C, name="elpa_index_get_int_loc")
144
145
146
147
148
149
150
151
 !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


/*
 !f> interface
156
 !f>   function elpa_index_get_double_value_c(index, name, success) result(value) bind(C, name="elpa_index_get_double_value")
157
 !f>     import c_ptr, c_int, c_double, c_char
158
159
160
161
 !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
162
163
164
 !f>   end function
 !f> end interface
 */
165
166
167
168
169
double elpa_index_get_double_value(elpa_index_t index, char *name, int *success);


/*
 !f> interface
170
 !f>   function elpa_index_set_double_value_c(index, name, value) result(success) bind(C, name="elpa_index_set_double_value")
171
172
173
174
175
176
177
178
179
180
181
182
183
 !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
184
 !f>   function elpa_index_double_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_double_value_is_set")
185
186
187
188
189
190
191
192
 !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


/*
 !f> interface
197
 !f>   function elpa_index_get_double_loc_c(index, name) result(loc) bind(C, name="elpa_index_get_double_loc")
198
199
200
201
202
203
204
 !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
 !f>   function elpa_index_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_value_is_set")
211
 !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
int elpa_index_value_is_set(elpa_index_t index, char *name);


/*
 !f> interface
223
224
 !f>   function elpa_int_value_to_string_c(name, value, string) &
 !f>              result(error) bind(C, name="elpa_int_value_to_string")
225
226
227
228
229
230
231
232
233
 !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>
 */
234
int elpa_int_value_to_string(char *name, int value, const char **string);
235
236
237
238


/*
 !f> interface
239
240
 !f>   pure function elpa_int_value_to_strlen_c(name, value) &
 !f>                   result(length) bind(C, name="elpa_int_value_to_strlen")
241
242
243
 !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
244
 !f>     integer(kind=c_int) :: length
245
246
247
248
 !f>   end function
 !f> end interface
 !f>
 */
249
int elpa_int_value_to_strlen(char *name, int value);
250
251
252
253


/*
 !f> interface
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
 !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")
270
271
272
273
274
275
276
277
278
 !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>
 */
279
int elpa_int_string_to_value(char *name, char *string, int *value);
280
281
282
283


/*
 !f> interface
284
285
 !f>   function elpa_option_cardinality_c(name) result(n) bind(C, name="elpa_option_cardinality")
 !f>     import c_int, c_char
286
287
288
289
290
291
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int) :: n
 !f>   end function
 !f> end interface
 !f>
 */
292
int elpa_option_cardinality(char *name);
293
294
295

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


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