Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
20
30#include "shamcmdopt/cmdopt.hpp"
31#include "shamcmdopt/env.hpp"
32#include "shamcomm/logs.hpp"
35#include "shamrock/version.hpp"
40#include <pybind11/embed.h>
41#include <cstdlib>
42#include <stdexcept>
43#include <string>
44
45//%Impl status : Should rewrite
46
49
50int main(int argc, char *argv[]) {
51
53
55 "--smi", {}, "print information about available SYCL devices in the cluster");
57 "--smi-full", {}, "print information about EVERY available SYCL devices in the cluster");
58
59 opts::register_opt("--benchmark-mpi", {}, "micro benchmark for MPI");
60
61 opts::register_opt("--sycl-cfg", "(idcomp:idalt) ", "specify the compute & alt queue index");
62 opts::register_opt("--loglevel", "(logvalue)", "specify a log level");
63
64 opts::register_opt("--rscript", "(filepath)", "run shamrock with python runscirpt");
65 opts::register_opt("--ipython", {}, "run shamrock in Ipython mode");
66 opts::register_opt("--force-dgpu-on", {}, "for direct mpi comm on");
67 opts::register_opt("--force-dgpu-off", {}, "for direct mpi comm off");
68
69 opts::register_opt("--pypath", "(sys.path)", "python sys.path to set");
70 opts::register_opt("--pypath-from-bin", "(python binary)", "set sys.path from python binary");
71
72 // --show-completion zsh should call opts::print_completion_zsh()
73 opts::register_opt("--show-completion-zsh", {}, "show completion for zsh");
74
75 shamcmdopt::register_opt("--feenableexcept", "", "Enable FPE exceptions");
76
77 shamcmdopt::register_env_var_doc("SHAM_PROF_PREFIX", "Prefix of shamrock profile outputs");
78 shamcmdopt::register_env_var_doc("SHAM_PROF_USE_NVTX", "Enable NVTX profiling");
79 shamcmdopt::register_env_var_doc("SHAM_PROFILING", "Enable Shamrock profiling");
81 "SHAM_PROF_USE_COMPLETE_EVENT",
82 "Use complete event instead of begin end for chrome tracing");
84 "SHAM_PROF_EVENT_RECORD_THRES", "Change the event recording threshold");
85
86 opts::init(argc, argv);
87
88 if (opts::is_help_mode()) {
89 return 0;
90 }
91
92 if (opts::has_option("--show-completion-zsh")) {
94 return 0;
95 }
96
97 if (opts::has_option("--feenableexcept")) {
99 }
100
101 if (opts::has_option("--loglevel")) {
102 std::string level = std::string(opts::get_option("--loglevel"));
103
104 i32 a = atoi(level.c_str());
105
106 if (i8(a) != a) {
107 logger::err_ln("Cmd OPT", "you must select a loglevel in a 8bit integer range");
109 "you must select a loglevel in a 8bit integer range");
110 } else {
112 }
113 }
114
115 if (opts::has_option("--sycl-cfg")) {
116 shamsys::instance::init(argc, argv);
117 } else {
118 using namespace shamsys::instance;
119 start_mpi(MPIInitInfo{.argc = opts::get_argc(), .argv = opts::get_argv()});
120 if (shamcomm::world_rank() == 0) {
122 "Init", "No kernel can be run without a sycl configuration (--sycl-cfg x:x)");
123 }
124 }
125
126 if (shamcomm::world_rank() == 0) {
127 print_title_bar();
128
131 logger::raw_ln("MPI status : ");
132
133 shamsys::instance::print_mpi_comm_info();
134
136 " - MPI & SYCL init :",
138
139 shamsys::instance::print_mpi_capabilities();
140 }
141 }
142
144 shamsys::instance::check_dgpu_available();
145 auto sptr = shamsys::instance::get_compute_scheduler_ptr();
146 shamcomm::validate_comm(sptr);
147 }
148
149 if (shamcomm::world_rank() == 0) {
152 }
153
154 bool is_smi = opts::has_option("--smi");
155 bool is_smi_full = opts::has_option("--smi-full");
156
157 if (is_smi || is_smi_full) {
158 if (shamcomm::world_rank() == 0) {
160 }
161 shamsys::shamrock_smi(is_smi_full);
162 }
163
164 if (opts::has_option("--benchmark-mpi")) {
165 if (shamcomm::world_rank() == 0) {
167 }
170 } else {
172 "Init",
173 "--benchmark-mpi can't be run without a sycl configuration (--sycl-cfg x:x)");
174 }
175 }
176
180
181 if (opts::has_option("--pypath")) {
182 shambindings::setpypath(std::string(opts::get_option("--pypath")));
183 }
184
185 if (opts::has_option("--pypath-from-bin")) {
186 std::string pybin = std::string(opts::get_option("--pypath-from-bin"));
188 }
189
190 shamsys::register_signals();
191 {
192
193 if (opts::has_option("--ipython")) {
195
196 if (shamcomm::world_size() > 1) {
198 "cannot run ipython mode with > 1 processes");
199 }
200
201 shambindings::start_ipython(true, argc, argv);
202
203 } else if (opts::has_option("--rscript")) {
205 std::string fname = std::string(opts::get_option("--rscript"));
206
207 shambindings::run_py_file(fname, shamcomm::world_rank() == 0, argc, argv);
208
209 } else {
210 if (shamcomm::world_rank() == 0) {
211 logger::raw_ln("Nothing to do ... exiting");
212 }
213 }
214 }
215
217
218 } else {
219 if (shamcomm::world_rank() == 0) {
221 "Init", "No sycl configuration (--sycl-cfg x:x) has been set, early exit");
222 }
224 return 0;
225 }
226}
Shamrock communication buffers.
Header file describing a Node Instance.
void start_mpi(MPIInitInfo mpi_info)
Start MPI.
bool is_initialized()
to check whether the NodeInstance is initialized
void init(int argc, char *argv[])
initialize the NodeInstance from command line args in the main
void close()
close the NodeInstance Aka : Finalize both MPI & SYCL
void close_mpi()
Finalize MPI.
std::int8_t i8
8 bit integer
std::int32_t i32
32 bit integer
This header file contains utility functions related to exception handling in the code.
PYBIND11_EMBEDDED_MODULE(pyshamrock, m)
Call bindings init for the shamrock python module.
Definition main.cpp:48
void enable_fpe_exceptions()
Enable floating point exceptions.
void set_loglevel(i8 val)
Set the global log level.
Definition loglevel.hpp:45
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
bool is_help_mode()
Check if the help mode is enabled.
Definition cmdopt.cpp:281
bool has_option(const std::string_view &option_name)
Check if an option is present.
Definition cmdopt.cpp:128
std::string_view get_option(const std::string_view &option_name)
Get the value of an option.
Definition cmdopt.cpp:146
char ** get_argv()
Get the command line arguments.
Definition cmdopt.cpp:204
int get_argc()
Get the number of command line arguments.
Definition cmdopt.cpp:198
void init(int argc, char *argv[])
Initialize the command line option parser. We also process generic options in this call (color detect...
Definition cmdopt.cpp:184
void register_env_var_doc(std::string env_var, std::string desc)
Register the documentation of an environment variable.
Definition env.cpp:43
void print_completion_zsh()
print zsh completion script to be sourced
Definition cmdopt.cpp:232
void register_opt(std::string name, std::optional< std::string > args, std::string description)
Register a command line option.
Definition cmdopt.cpp:165
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
i32 world_size()
Gives the size of the MPI communicator.
Definition worldInfo.cpp:38
bool are_experimental_features_allowed()
Allow the use of experimental features.
void run_micro_benchmark()
Run latency & bandwidth benchmark those benchmark where adapted from osu_microbenchmark.
void shamrock_smi(bool list_all_devices)
Print information about all available SYCL devices in the cluster.
void init_embed(py::module &m, bool hook_stdout=true)
Init python bindings and register them to Python API.
void print_active_level()
Prints the active log levels.
Definition logs.cpp:33
void code_init_done_log()
Indicates that the code initialization is complete through various means ;).
Definition logs.cpp:57
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:90
void print_faint_row()
Prints a faint separator line to the log.
Definition logs.hpp:100
void warn_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:133
void err_ln(std::string module_name, Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:133
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.
void setpypath_from_binary(std::string binary_path)
set the value of sys.path before init from the supplied binary
void start_ipython(bool do_print, int argc, char *argv[])
Start shamrock embded ipython interpreter.
void setpypath(std::string path)
set the value of sys.path before init
void run_py_file(std::string file_path, bool do_print, int argc, char *argv[])
run python runscript
Struct containing MPI Init informations Usage.
const std::string reset()
Get the reset terminal escape char.
const std::string col8b_green()
Get the green terminal escape char.
typedefs and macros
Functions related to the MPI communicator.