|
32 | 32 | #include "openPMD/IterationEncoding.hpp" |
33 | 33 | #include "openPMD/ThrowError.hpp" |
34 | 34 | #include "openPMD/auxiliary/Date.hpp" |
| 35 | +#include "openPMD/auxiliary/Environment.hpp" |
35 | 36 | #include "openPMD/auxiliary/Filesystem.hpp" |
36 | 37 | #include "openPMD/auxiliary/JSON_internal.hpp" |
37 | 38 | #include "openPMD/auxiliary/Mpi.hpp" |
@@ -160,9 +161,34 @@ namespace |
160 | 161 | current - start_parsing); |
161 | 162 | if (!printed_warning_already) |
162 | 163 | { |
163 | | - std::cerr |
164 | | - << R"(Warning: Parsing Iterations is taking a long time. Consider setting {"defer_iteration_parsing": true} for lazy opening of the Series and then explicitly opening Iterations with Iteration::open(). Refer also to the documentation at https://openpmd-api.readthedocs.io. Suppress this warning by setting {"hint_lazy_parsing_timeout": 0}.)" |
165 | | - << '\n'; |
| 164 | + std::cerr << &R"END( |
| 165 | +[openPMD] WARNING: Parsing Iterations is taking a long time. |
| 166 | +Consider using deferred Iteration parsing in order to open the Series lazily. |
| 167 | +This can be achieved by either setting an environment variable: |
| 168 | +
|
| 169 | +> export OPENPMD_DEFER_ITERATION_PARSING=1 |
| 170 | +
|
| 171 | +Or by specifying it as part of a JSON/TOML configuration: |
| 172 | +
|
| 173 | +> // C++: |
| 174 | +> Series simData("my_data_%T.%E", R"({"defer_iteration_parsing": true})"); |
| 175 | +> // Python: |
| 176 | +> simData = opmd.Series("my_data_%T.%E", {"defer_iteration_parsing": True}) |
| 177 | +
|
| 178 | +Iterations will then be parsed only upon explicit user request: |
| 179 | +
|
| 180 | +> series.snapshots()[100].open() // new API |
| 181 | +> series.iterations[100].open() // old API |
| 182 | +
|
| 183 | +Alternatively, Iterations will be opened implicitly when iterating in |
| 184 | +READ_LINEAR access mode. |
| 185 | +Refer also to the documentation at https://openpmd-api.readthedocs.io |
| 186 | +
|
| 187 | +This warning can be suppressed also by either specifying |
| 188 | +an environment variable: |
| 189 | +
|
| 190 | +> export OPENPMD_HINT_LAZY_PARSING_TIMEOUT=0 |
| 191 | +)END"[1] << '\n'; |
166 | 192 | printed_warning_already = true; |
167 | 193 | } |
168 | 194 | std::cerr << "Elapsed time: " << total_diff.count() |
@@ -3032,9 +3058,18 @@ namespace |
3032 | 3058 | * If yes, read it into the specified location. |
3033 | 3059 | */ |
3034 | 3060 | template <typename From, typename Dest = From> |
3035 | | - void |
3036 | | - getJsonOption(json::TracingJSON &config, std::string const &key, Dest &dest) |
| 3061 | + void getJsonOption( |
| 3062 | + json::TracingJSON &config, |
| 3063 | + std::string const &key, |
| 3064 | + Dest &dest, |
| 3065 | + std::optional<std::string> envVar = std::nullopt) |
3037 | 3066 | { |
| 3067 | + if (envVar.has_value()) |
| 3068 | + { |
| 3069 | + dest = auxiliary::getEnvNum(*envVar, dest); |
| 3070 | + std::cout << "Read from env var " << *envVar << " as: " << dest |
| 3071 | + << std::endl; |
| 3072 | + } |
3038 | 3073 | if (config.json().contains(key)) |
3039 | 3074 | { |
3040 | 3075 | dest = config[key].json().get<From>(); |
@@ -3077,11 +3112,15 @@ void Series::parseJsonOptions(TracingJSON &options, ParsedInput &input) |
3077 | 3112 | { |
3078 | 3113 | auto &series = get(); |
3079 | 3114 | getJsonOption<bool>( |
3080 | | - options, "defer_iteration_parsing", series.m_parseLazily); |
| 3115 | + options, |
| 3116 | + "defer_iteration_parsing", |
| 3117 | + series.m_parseLazily, |
| 3118 | + "OPENPMD_DEFER_ITERATION_PARSING"); |
3081 | 3119 | getJsonOption<uint64_t>( |
3082 | 3120 | options, |
3083 | 3121 | "hint_lazy_parsing_timeout", |
3084 | | - series.m_hintLazyParsingAfterTimeout); |
| 3122 | + series.m_hintLazyParsingAfterTimeout, |
| 3123 | + "OPENPMD_HINT_LAZY_PARSING_TIMEOUT"); |
3085 | 3124 | internal::SeriesData::SourceSpecifiedViaJSON rankTableSource; |
3086 | 3125 | if (getJsonOptionLowerCase(options, "rank_table", rankTableSource.value)) |
3087 | 3126 | { |
|
0 commit comments