Skip to content

Commit 4e7c3b7

Browse files
committed
Ready for PR, Fix #438, include unit test for PDI C deactivation, to do : Fortran equivalent
1 parent 1385e76 commit 4e7c3b7

File tree

7 files changed

+146
-12
lines changed

7 files changed

+146
-12
lines changed

AUTHORS

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Please note this is the list for the distribution mechanism of PDI. The list for
66
each sub-project (including PDI itself) is located in the dedicated sub-project
77
AUTHORS file.
88

9+
Julian Auriac - CEA ([email protected])
10+
* Maintainer (Nov. 2024 - ...)
911

1012
Julien Bigot - CEA ([email protected])
1113
* Maintainer (Dec. 2014 - ...)
@@ -36,6 +38,3 @@ project co-financed by Polish Ministry of Science and Higher Education.
3638

3739
Yushan Wang - CEA ([email protected])
3840
* Maintainer (Sept. 2023 - ...)
39-
40-
Julian Auriac - CEA ([email protected])
41-
* Maintainer (Nov. 2024 - ...)

pdi/docs/Using_PDI.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ variables set up.
3636

3737
If source files (of application that uses %PDI) and specification tree file are ready, the compilation step can be made.
3838
For C make sure that source files that use %PDI API are including `pdi.h` header file.
39+
%PDI can be disabled by using `pdi_deactivation.h` instead of `pdi.h`, and re-enabled by doing the opposite.
3940
For Fortran make sure that source files that use %PDI API are using `%PDI` module file (`USE %PDI`).
4041

4142
### Compiling by hand {#compiling_by_hand}
@@ -92,4 +93,4 @@ plugins in 4 steps (it will use the first plugin found):
9293
1. `PDI_PLUGIN_PATH` environment variable that is colon separated list with paths,
9394
2. `plugin_path` subtree in specification tree: \ref plugin_path_map_node,
9495
3. Relative path of used %PDI shared object `libpdi.so`,
95-
4. `LD_LIBRARY_PATH` environment variable that is colon separated list.
96+
4. `LD_LIBRARY_PATH` environment variable that is colon separated list.

pdi/include/pdi_deactivation.h

+77-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
*
5353
*/
5454

55-
#ifdef PDI_H_
5655
#define PDI_H_
5756

5857
#include <paraconf.h>
@@ -64,9 +63,68 @@
6463
extern "C" {
6564
#endif
6665

67-
// /** \addtogroup error
68-
// * \{
69-
// */
66+
/** \addtogroup error
67+
* \{
68+
*/
69+
70+
/** Error codes of PDI
71+
*/
72+
typedef enum PDI_status_e {
73+
/// everything went well
74+
PDI_OK = 0,
75+
/// on an input call, no such data is available
76+
PDI_UNAVAILABLE,
77+
/// The configuration file is invalid
78+
PDI_ERR_CONFIG,
79+
/// A value expression is invalid
80+
PDI_ERR_VALUE,
81+
/// Tried to load a non-existing plugin
82+
PDI_ERR_PLUGIN,
83+
/// Implementation limitation (typically an unimplemented feature)
84+
PDI_ERR_IMPL,
85+
/// A system error occured (OS, etc.)
86+
PDI_ERR_SYSTEM,
87+
/** A call to a function has been made at a wrong time (e.g. closing an
88+
* unopened transaction)
89+
*/
90+
PDI_ERR_STATE,
91+
/// A conflict of onwership over a content has been raised
92+
PDI_ERR_RIGHT,
93+
/// Invalid type error
94+
PDI_ERR_TYPE
95+
96+
} PDI_status_t;
97+
98+
/** Type of a callback function used when an error occurs
99+
* \param status the error code
100+
* \param message the human-readable error message
101+
* \param context a user-provided context
102+
*/
103+
typedef void (*PDI_errfunc_f)(PDI_status_t status, const char* message, void* context);
104+
105+
/** Definition of an error handler
106+
*/
107+
typedef struct PDI_errhandler_s {
108+
/// The function to handle the error (none if NULL)
109+
PDI_errfunc_f func;
110+
111+
/// the context that will be provided to the function
112+
void* context;
113+
114+
} PDI_errhandler_t;
115+
116+
/** Prints the error message and aborts if the status is invalid
117+
*/
118+
extern const PDI_errhandler_t PDI_EXPORT PDI_ASSERT_HANDLER;
119+
120+
/** Prints the error message and continue if the status is invalid
121+
*/
122+
extern const PDI_errhandler_t PDI_EXPORT PDI_WARN_HANDLER;
123+
124+
/** Does nothing
125+
*/
126+
extern const PDI_errhandler_t PDI_EXPORT PDI_NULL_HANDLER;
127+
70128

71129
/** Return a human-readabe message describing the last error that occured in PDI
72130
*/
@@ -116,6 +174,21 @@ PDI_status_t PDI_EXPORT PDI_version(unsigned long* provided, unsigned long expec
116174
* \{
117175
*/
118176

177+
/**
178+
* Access directions
179+
*/
180+
typedef enum PDI_inout_e {
181+
/// No data transfert
182+
PDI_NONE = 0,
183+
/// data tranfer from PDI to the main code
184+
PDI_IN = 1,
185+
/// data transfer from the main code to PDI
186+
PDI_OUT = 2,
187+
/// data transfer in both direction
188+
PDI_INOUT = 3
189+
190+
} PDI_inout_t;
191+
119192
/** Shares some data with PDI. The user code should not modify it before
120193
* a call to either PDI_release or PDI_reclaim.
121194
* \param[in] name the data name
@@ -229,6 +302,3 @@ PDI_status_t PDI_DEPRECATED_EXPORT PDI_transaction_end(void){};
229302
#ifdef __cplusplus
230303
} // extern C
231304
#endif
232-
233-
234-
#endif // PDI_H_

tests/AUTHORS

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Multiple people have contributed to the PDI tests. To show our appreciation for
22
their public spirit, we list here in alphabetical order a condensed list of
33
their contributions.
44

5+
Julian Auriac - CEA ([email protected])
6+
* Maintainer (Nov. 2024 - ...)
57

68
Julien Bigot - CEA ([email protected])
79
* Initial buildsystem
@@ -15,4 +17,4 @@ project co-financed by Polish Ministry of Science and Higher Education.
1517
* Tests inspired by Parflow that combine Serialize & Decl'HDF5
1618

1719
Yushan Wang - CEA ([email protected])
18-
* Maintainer (Sept. 2023 - ...)
20+
* Maintainer (Sept. 2023 - ...)

tests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ add_executable(test_04_C test_04.c)
5656
target_link_libraries(test_04_C PDI::PDI_C)
5757
add_test(NAME test_04_C COMMAND "$<TARGET_FILE:test_04_C>" "${CMAKE_CURRENT_SOURCE_DIR}/test_04.yml")
5858

59+
add_executable(test_06_C test_06.c)
60+
target_link_libraries(test_06_C PDI::PDI_C)
61+
add_test(NAME test_06_C COMMAND "$<TARGET_FILE:test_06_C>" "${CMAKE_CURRENT_SOURCE_DIR}/test_06.yml")
62+
5963
endif("${BUILD_DECL_HDF5_PLUGIN}" AND "${BUILD_SERIALIZE_PLUGIN}")
6064
if("${BUILD_DECL_NETCDF_PLUGIN}" AND "${BUILD_SERIALIZE_PLUGIN}")
6165

tests/test_06.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2024 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the name of CEA nor the names of its contributors may be used to
14+
* endorse or promote products derived from this software without specific
15+
* prior written permission.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
******************************************************************************/
25+
26+
#include <assert.h>
27+
// #include <pdi.h>
28+
#include <pdi_deactivation.h>
29+
#include <stdio.h>
30+
31+
32+
int main(int argc, char* argv[])
33+
{
34+
PC_tree_t conf = PC_parse_path(argv[1]);
35+
36+
PDI_init(PC_get(conf, ".pdi"));
37+
printf("%s",argv[1]);
38+
39+
long longval;
40+
41+
int global_size[2];
42+
PC_int(PC_get(conf, ".global_size.height"), &longval); global_size[0] = longval;
43+
PC_int(PC_get(conf, ".global_size.width"), &longval); global_size[1] = longval;
44+
45+
// # As the value is shared with pdi.h, it can be reclaimed in a second time.
46+
// # In the case of pdi_deactivation.h, the value is never shared, hence the reclaim operation fails.
47+
// PDI_share("global_size", global_size, PDI_OUT) == NULL;
48+
PDI_reclaim("global_size");
49+
50+
PDI_finalize();
51+
return 0;
52+
}

tests/test_06.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global_size: { height: 60, width: 12 }
2+
3+
pdi:
4+
plugins:
5+
trace:
6+
logging: { pattern: '[PDI][%n-plugin] *** %l: %v' }

0 commit comments

Comments
 (0)