-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathmaxwell_cpu_mt.cu
More file actions
97 lines (78 loc) · 2.89 KB
/
Copy pathmaxwell_cpu_mt.cu
File metadata and controls
97 lines (78 loc) · 2.89 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2022 NVIDIA Corporation
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This file causes clangd to crash during parsing
#if !defined(STDEXEC_CLANGD_INVOKED)
# include "maxwell/snr.cuh"
# include "maxwell/std.cuh"
# include "maxwell/stdpar.cuh" // IWYU pragma: keep
# include "../../include/exec/static_thread_pool.hpp"
# include <iostream>
auto main(int argc, char *argv[]) -> int
{
auto params = parse_cmd(argc, argv);
if (value(params, "help") || value(params, "h"))
{
std::cout << "Usage: " << argv[0] << " [OPTION]...\n"
<< "\t--write-vtk\n"
<< "\t--iterations\n"
<< "\t--run-std\n"
<< (STDEXEC_NO_STDCPP_PARALLEL_ALGORITHMS() ? "" : "\t--run-stdpar\n")
<< "\t--run-thread-pool-scheduler\n"
<< "\t--N\n"
<< std::endl;
return 0;
}
bool const write_vtk = value(params, "write-vtk");
std::size_t const n_iterations = value(params, "iterations", 100);
std::size_t const N = value(params, "N", 512);
auto run_snr_on = [&](std::string_view scheduler_name, stdexec::scheduler auto &&scheduler)
{
grid_t grid{N, is_gpu_scheduler(scheduler)};
auto accessor = grid.accessor();
auto dt = calculate_dt(accessor.dx, accessor.dy);
run_snr(dt,
write_vtk,
n_iterations,
grid,
scheduler_name,
std::forward<decltype(scheduler)>(scheduler));
};
report_header();
if (value(params, "run-thread-pool-scheduler"))
{
exec::static_thread_pool pool{std::thread::hardware_concurrency()};
run_snr_on("CPU (snr thread pool)", pool.get_scheduler());
}
if (value(params, "run-std"))
{
grid_t grid{N, false /* !gpu */};
auto accessor = grid.accessor();
auto dt = calculate_dt(accessor.dx, accessor.dy);
run_std(dt, write_vtk, n_iterations, grid, "CPU (std)");
}
# if !STDEXEC_NO_STDCPP_PARALLEL_ALGORITHMS()
if (value(params, "run-stdpar"))
{
bool const gpu = is_gpu_policy(stdexec::par_unseq);
std::string_view method = gpu ? "GPU (stdpar)" : "CPU (stdpar)";
grid_t grid{N, gpu};
auto accessor = grid.accessor();
auto dt = calculate_dt(accessor.dx, accessor.dy);
run_stdpar(dt, write_vtk, n_iterations, grid, stdexec::par_unseq, method);
}
# endif
}
#endif // !defined(STDEXEC_CLANGD_INVOKED)