| 154 | } |
| 155 | |
| 156 | int test_concurrent_parser_construction () |
| 157 | { |
| 158 | amrex::Print() << test_number++ << ". Testing concurrent Parser/IParser construction "; |
| 159 | |
| 160 | constexpr int nthreads = 2; |
| 161 | constexpr int niters = 64; |
| 162 | std::vector<int> nfail(nthreads, 0); |
| 163 | std::vector<std::thread> threads; |
| 164 | threads.reserve(nthreads); |
| 165 | |
| 166 | for (int tid = 0; tid < nthreads; ++tid) { |
| 167 | threads.emplace_back([tid, &nfail] () |
| 168 | { |
| 169 | int local_nfail = 0; |
| 170 | for (int iter = 0; iter < niters; ++iter) { |
| 171 | try { |
| 172 | { |
| 173 | Parser parser("a*x + b"); |
| 174 | auto const a = static_cast<double>(tid+1); |
| 175 | auto const b = 0.25*static_cast<double>(iter+1); |
| 176 | auto const x = static_cast<double>((iter % 7) - 3); |
| 177 | parser.setConstant("a", a); |
| 178 | parser.setConstant("b", b); |
| 179 | parser.registerVariables({"x"}); |
| 180 | auto const exe = parser.compileHost<1>(); |
| 181 | if (std::abs(exe(x) - (a*x + b)) > 1.e-12) { |
| 182 | ++local_nfail; |
| 183 | } |
| 184 | } |
| 185 | { |
| 186 | Parser parser("if(x > threshold, x*x + c, c-x)"); |
| 187 | auto const threshold = static_cast<double>((tid % 3) - 1); |
| 188 | auto const c = 0.125*static_cast<double>(iter+1); |
| 189 | auto const x = static_cast<double>((iter % 5) - 2); |
| 190 | parser.setConstant("threshold", threshold); |
| 191 | parser.setConstant("c", c); |
| 192 | parser.registerVariables({"x"}); |
| 193 | auto const exe = parser.compileHost<1>(); |
| 194 | auto const expected = (x > threshold) ? x*x + c : c - x; |
| 195 | if (std::abs(exe(x) - expected) > 1.e-12) { |
| 196 | ++local_nfail; |
| 197 | } |
| 198 | } |
| 199 | { |
| 200 | IParser iparser("a*x + b"); |
| 201 | auto const a = static_cast<long long>(tid) + 1; |
| 202 | auto const b = static_cast<long long>(iter) + 3; |
| 203 | auto const x = static_cast<long long>((iter % 9) - 4); |
| 204 | iparser.setConstant("a", a); |
| 205 | iparser.setConstant("b", b); |
| 206 | iparser.registerVariables({"x"}); |
| 207 | auto const exe = iparser.compileHost<1>(); |
| 208 | if (exe(x) != a*x + b) { |
| 209 | ++local_nfail; |
| 210 | } |
| 211 | } |
| 212 | } catch (...) { |
| 213 | ++local_nfail; |
no test coverage detected