elpa_index.h 12.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
!
!    Copyright 2017, L. Hüdepohl and A. Marek, MPCDF
!
!    This file is part of ELPA.
!
!    The ELPA library was originally created by the ELPA consortium,
!    consisting of the following organizations:
!
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
!    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
!      Informatik,
!    - Technische Universität München, Lehrstuhl für Informatik mit
!      Schwerpunkt Wissenschaftliches Rechnen ,
!    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
!    - IBM Deutschland GmbH
!
!    This particular source code file contains additions, changes and
!    enhancements authored by Intel Corporation which is not part of
!    the ELPA consortium.
!
!    More information can be found here:
!    http://elpa.mpcdf.mpg.de/
!
!    ELPA is free software: you can redistribute it and/or modify
!    it under the terms of the version 3 of the license of the
!    GNU Lesser General Public License as published by the Free
!    Software Foundation.
!
!    ELPA is distributed in the hope that it will be useful,
!    but WITHOUT ANY WARRANTY; without even the implied warranty of
!    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!    GNU Lesser General Public License for more details.
!
!    You should have received a copy of the GNU Lesser General Public License
!    along with ELPA.  If not, see <http://www.gnu.org/licenses/>
!
!    ELPA reflects a substantial effort on the part of the original
!    ELPA consortium, and we ask you to respect the spirit of the
!    license that we chose: i.e., please contribute any changes you
!    may have back to the original ELPA library distribution, and keep
!    any derivatives of ELPA under the same license that we chose for
!    the original distribution, the GNU Lesser General Public License.
!
*/
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
50
51
52
53
54
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <search.h>
55
56
#include <math.h>

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
57
58
59
60
#include <elpa/elpa.h>

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

61
62
63
64
#define FOR_ALL_TYPES(X) \
        X(int, "%d", -1) \
        X(double, "%g", NAN)

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
65
66
67
68
69
70
/* 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;

71
/* Function type for the cardinality */
72
typedef int (*elpa_index_cardinality_t)(void);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
73

74
75
/* Function type to enumerate all possible values, starting from 0 */
typedef int (*elpa_index_enumerate_int_option_t)(int i);
76

77
/* Function types to check the validity of a value */
78
typedef int (*elpa_index_valid_int_t)(elpa_index_t index, int n, int new_value);
79
typedef int (*elpa_index_valid_double_t)(elpa_index_t index, int n, double new_value);
80
81

/* Function type to give a string representation of a value */
82
typedef const char* (*elpa_index_to_string_int_t)(int n);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
83
84
85


typedef struct {
86
87
88
89
90
91
        char *name;
        char *description;
        char *env_default;
        char *env_force;
        int once;
        int readonly;
92
        int private;
93
} elpa_index_entry_t;
94
95


96
97
98
99
100
101
102
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;
103
104
} elpa_index_int_entry_t;

105

106
typedef struct {
107
108
109
        elpa_index_entry_t base;
        double default_value;
        elpa_index_valid_double_t valid;
110
} elpa_index_double_entry_t;
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
111

112
113
114
115
116
enum NOTIFY_FLAGS {
        NOTIFY_ENV_DEFAULT = (1<<0),
        NOTIFY_ENV_FORCE   = (1<<1),
};

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
117
struct elpa_index_struct {
118
119
120
121
122
123
124
#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
125
126
};

127
128
129

/*
 !f> interface
130
 !f>   function elpa_index_instance_c() result(index) bind(C, name="elpa_index_instance")
131
132
133
134
135
136
137
 !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
138
139
140

/*
 !f> interface
141
 !f>   subroutine elpa_index_free_c(index) bind(C, name="elpa_index_free")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
142
143
144
145
146
 !f>     import c_ptr
 !f>     type(c_ptr), value :: index
 !f>   end subroutine
 !f> end interface
 */
147
148
void elpa_index_free(elpa_index_t index);

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
149
150
151

/*
 !f> interface
152
153
 !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
154
 !f>     import c_ptr, c_int, c_char
155
156
157
158
 !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
159
160
161
 !f>   end function
 !f> end interface
 */
162
int elpa_index_get_int_value(elpa_index_t index, char *name, int *success);
163

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
164
165
166

/*
 !f> interface
167
168
 !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
169
170
171
172
 !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
173
 !f>     integer(kind=c_int),intent(in), value :: force_writable
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
174
175
176
177
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
178
int elpa_index_set_int_value(elpa_index_t index, char *name, int value, int force_writable);
179
180
181
182


/*
 !f> interface
183
 !f>   function elpa_index_int_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_int_value_is_set")
184
185
186
187
188
189
190
 !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
 */
191
192
193
int elpa_index_int_value_is_set(elpa_index_t index, char *name);


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 !f> interface
 !f>   function elpa_index_int_is_private_c(name) result(success) bind(C, name="elpa_index_int_is_private")
 !f>     import c_int, c_char
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
int elpa_index_int_is_private(char *name);


/*
 !f> interface
 !f>   function elpa_index_double_is_private_c(name) result(success) bind(C, name="elpa_index_double_is_private")
 !f>     import c_int, c_char
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
int elpa_index_double_is_private(char *name);


218
219
/*
 !f> interface
220
 !f>   function elpa_index_get_int_loc_c(index, name) result(loc) bind(C, name="elpa_index_get_int_loc")
221
222
223
224
225
226
227
228
 !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);
229
230
231
232


/*
 !f> interface
233
 !f>   function elpa_index_get_double_value_c(index, name, success) result(value) bind(C, name="elpa_index_get_double_value")
234
 !f>     import c_ptr, c_int, c_double, c_char
235
236
237
238
 !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
239
240
241
 !f>   end function
 !f> end interface
 */
242
243
244
245
246
double elpa_index_get_double_value(elpa_index_t index, char *name, int *success);


/*
 !f> interface
247
248
 !f>   function elpa_index_set_double_value_c(index, name, value, force_writable) result(success) &
 !f>       bind(C, name="elpa_index_set_double_value")
249
250
251
252
 !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
253
 !f>     integer(kind=c_int),intent(in), value :: force_writable
254
255
256
257
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
258
int elpa_index_set_double_value(elpa_index_t index, char *name, double value, int force_writable);
259
260
261
262


/*
 !f> interface
263
264
 !f>   function elpa_index_double_value_is_set_c(index, name) result(success) &
 !f>       bind(C, name="elpa_index_double_value_is_set")
265
266
267
268
269
270
271
272
 !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);
273
274
275
276


/*
 !f> interface
277
 !f>   function elpa_index_get_double_loc_c(index, name) result(loc) bind(C, name="elpa_index_get_double_loc")
278
279
280
281
282
283
284
 !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
 */
285
double* elpa_index_get_double_loc(elpa_index_t index, char *name);
286
287
288
289


/*
 !f> interface
290
 !f>   function elpa_index_value_is_set_c(index, name) result(success) bind(C, name="elpa_index_value_is_set")
291
 !f>     import c_ptr, c_int, c_char
292
293
294
295
296
297
 !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
 */
298
299
300
301
int elpa_index_value_is_set(elpa_index_t index, char *name);


/*
302
303
304
305
306
307
308
309
310
311
312
 !pf> interface
 !pf>   function elpa_int_value_to_string_c(name, value, string) &
 !pf>              result(error) bind(C, name="elpa_int_value_to_string")
 !pf>     import c_int, c_ptr, c_char
 !pf>     character(kind=c_char), intent(in) :: name(*)
 !pf>     integer(kind=c_int), intent(in), value :: value
 !pf>     type(c_ptr), intent(out) :: string
 !pf>     integer(kind=c_int) :: error
 !pf>   end function
 !pf> end interface
 !pf>
313
 */
314
int elpa_int_value_to_string(char *name, int value, const char **string);
315
316
317


/*
318
319
320
321
322
323
324
325
326
327
 !pf> interface
 !pf>   pure function elpa_int_value_to_strlen_c(name, value) &
 !pf>                   result(length) bind(C, name="elpa_int_value_to_strlen")
 !pf>     import c_int, c_ptr, c_char
 !pf>     character(kind=c_char), intent(in) :: name(*)
 !pf>     integer(kind=c_int), intent(in), value :: value
 !pf>     integer(kind=c_int) :: length
 !pf>   end function
 !pf> end interface
 !pf>
328
 */
329
int elpa_int_value_to_strlen(char *name, int value);
330
331
332
333


/*
 !f> interface
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
 !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")
350
351
352
353
354
355
356
357
358
 !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>
 */
359
int elpa_int_string_to_value(char *name, char *string, int *value);
360
361
362
363


/*
 !f> interface
364
365
 !f>   function elpa_option_cardinality_c(name) result(n) bind(C, name="elpa_option_cardinality")
 !f>     import c_int, c_char
366
367
368
369
370
371
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int) :: n
 !f>   end function
 !f> end interface
 !f>
 */
372
int elpa_option_cardinality(char *name);
373
374
375

/*
 !f> interface
376
377
 !f>   function elpa_option_enumerate_c(name, i) result(value) bind(C, name="elpa_option_enumerate")
 !f>     import c_int, c_char
378
379
380
381
382
383
384
 !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>
 */
385
int elpa_option_enumerate(char *name, int i);
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400


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