From 47ee3948ffd511e2704b365503669a79648824d7 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Sat, 16 Nov 2024 23:55:18 +0300 Subject: [PATCH] Add wasm build instructions and fdtd3dbench target with predefined command line args --- Docs/Build.md | 29 +++++- README.md | 4 +- Source/CMakeLists.txt | 3 + Source/Settings/Settings.cpp | 30 +++--- Source/Settings/Settings.h | 10 +- Source/main.cpp | 181 +++++++++++++++++++---------------- 6 files changed, 153 insertions(+), 104 deletions(-) diff --git a/Docs/Build.md b/Docs/Build.md index a83550bf..afc24910 100644 --- a/Docs/Build.md +++ b/Docs/Build.md @@ -118,6 +118,33 @@ Add this to `cmake` command: -DLINK_NUMA=ON ``` -# Cross build for ARM +# Cross build See [cross build](CrossBuild.md). + +# Benchmark build + +Sequentual build +```sh +cmake .. -DCMAKE_BUILD_TYPE=Release -DSOLVER_DIM_MODES=DIM3 -DVALUE_TYPE=d -DCOMPLEX_FIELD_VALUES=ON -DPRINT_MESSAGE=ON -DPARALLEL_GRID=OFF +make fdtd3dbench +``` + +# WebAssembly build + +Steps: +- Add `emcmake` before `cmake` command +- Increase inital memory size with `-s INITIAL_MEMORY=134217728` +- Set `-g2` debuggability level +- Add `emmake` before `make` command +- In order to generate htlm directly, change `CMAKE_EXECUTABLE_SUFFIX` to `.html` in /usr/share/emscripten/cmake/Modules/Platform/Emscripten.cmake + +For example: +```sh +mkdir Release +cd Release +emcmake cmake .. -DCMAKE_CXX_FLAGS="-g2" -DCMAKE_EXE_LINKER_FLAGS="-s INITIAL_MEMORY=134217728" -DCMAKE_BUILD_TYPE=Release -DSOLVER_DIM_MODES=DIM3 -DVALUE_TYPE=d -DCOMPLEX_FIELD_VALUES=ON -DPRINT_MESSAGE=ON -DPARALLEL_GRID=OFF +emmake make fdtd3dbench +``` + +This will create `fdtd3d.js`, `fdtd3d.wasm` and `fdtd3d.html`. diff --git a/README.md b/README.md index d295e166..1b6901e5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # fdtd3d -This is an open-source implementation of FDTD Maxwell's equations solver for different dimensions (1, 2 or 3) with support of concurrency (MPI/OpenMP/Cuda) if required and for different architectures (x64, Arm, Arm64, RISC-V, PowerPC). The key idea is building of solver for your specific needs with different components, i.e. concurrency support with enabled MPI, OpenMP or GPU support, parallel buffer types, specific dimension and others. OpenMP support is WIP. +This is an open-source implementation of FDTD Maxwell's equations solver for different dimensions (1, 2 or 3) with support of concurrency (MPI/OpenMP/Cuda) if required and for different architectures (x64, Arm, Arm64, RISC-V, PowerPC, Wasm). The key idea is building of solver for your specific needs with different components, i.e. concurrency support with enabled MPI, OpenMP or GPU support, parallel buffer types, specific dimension and others. OpenMP support is WIP. For additional info on current project development status and future plans check issues and milestones, design docs are available at [documentation](Docs/Design.md). Also, doxygen documentation can be generated from config in `./Doxyfile`: @@ -26,7 +26,7 @@ Build is done using cmake: mkdir Release cd Release cmake .. -DCMAKE_BUILD_TYPE=Release -make +make fdtd3d ``` See [documentation](Docs/Build.md) for specific details. diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index df7ad8d7..30b0b56a 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -55,6 +55,9 @@ if ("${CUDA_ENABLED}") set_target_properties (fdtd3d PROPERTIES CUDA_SEPARABLE_COMPILATION ON) else () add_executable (fdtd3d main.cpp) + add_executable (fdtd3dbench main.cpp) + target_compile_definitions (fdtd3dbench PUBLIC PREDEFINED_ARGS) + target_link_libraries (fdtd3dbench Scheme) endif () target_link_libraries (fdtd3d Scheme) diff --git a/Source/Settings/Settings.cpp b/Source/Settings/Settings.cpp index 24f5d1e1..10b98597 100644 --- a/Source/Settings/Settings.cpp +++ b/Source/Settings/Settings.cpp @@ -20,6 +20,7 @@ #include "Settings.h" +#include #include #include #include @@ -70,12 +71,14 @@ Settings::Uninitialize () */ CUDA_HOST void -Settings::parseCoordinate (char *str, /**< string to parse */ +Settings::parseCoordinate (const char *str, /**< string to parse */ int &xval, /**< out: x value */ int &yval, /**< out: y value */ int &zval) /**< out: z value */ { - char *coordStr = str; + const char *coordStr = str; + const int tmpBufSize = 16; + char * tmpCoordStr = (char *) alloca (tmpBufSize); int i = 0; while (coordStr[i] != '\0') { @@ -90,20 +93,23 @@ Settings::parseCoordinate (char *str, /**< string to parse */ { isEnd = true; } - coordStr[i] = '\0'; - ASSERT (coordStr[1] == ':'); - int val = STOI (coordStr+2); + ASSERT (i < tmpBufSize); + strncpy (tmpCoordStr, coordStr, i); + tmpCoordStr[i] = '\0'; - if (coordStr[0] == 'x' || coordStr[0] == 'X') + ASSERT (tmpCoordStr[1] == ':'); + int val = STOI (tmpCoordStr+2); + + if (tmpCoordStr[0] == 'x' || tmpCoordStr[0] == 'X') { xval = val; } - else if (coordStr[0] == 'y' || coordStr[0] == 'Y') + else if (tmpCoordStr[0] == 'y' || tmpCoordStr[0] == 'Y') { yval = val; } - else if (coordStr[0] == 'z' || coordStr[0] == 'Z') + else if (tmpCoordStr[0] == 'z' || tmpCoordStr[0] == 'Z') { zval = val; } @@ -126,7 +132,7 @@ CUDA_HOST int Settings::parseArg (int &index, /**< out: current argument index */ int argc, /**< total number of indexes */ - char **argv, /**< vector of cmd args */ + const char * const * argv, /**< vector of cmd args */ bool isCmd) /**< flag, whether argumens are passed through actual command line */ { ASSERT (index >= 0 && index < argc); @@ -370,7 +376,7 @@ Settings::parseArg (int &index, /**< out: current argument index */ CUDA_HOST int Settings::setFromCmd (int argc, /**< number of arguments */ - char **argv, /**< arguments */ + const char * const * argv, /**< arguments */ bool isCmd) /**< flag, whether argumens are passed through actual command line */ { if (argc == (isCmd ? 1 : 0)) @@ -519,7 +525,7 @@ Settings::loadCmdFromFile (std::string fileName) /**< name of file to load from CUDA_HOST int Settings::saveCmdToFile (int argc, /**< number of arguments */ - char **argv, /**< arguments */ + const char * const * argv, /**< arguments */ std::string fileName) /**< name of file to save to */ { printf ("Saving command line to file %s\n", fileName.c_str ()); @@ -550,7 +556,7 @@ Settings::saveCmdToFile (int argc, /**< number of arguments */ CUDA_HOST void Settings::SetupFromCmd (int argc, /**< number of arguments */ - char **argv) /**< arguments */ + const char * const *argv) /**< arguments */ { int status = setFromCmd (argc, argv, true); diff --git a/Source/Settings/Settings.h b/Source/Settings/Settings.h index c7fbd4c3..eadd6a63 100644 --- a/Source/Settings/Settings.h +++ b/Source/Settings/Settings.h @@ -177,12 +177,12 @@ class Settings private: - CUDA_HOST int parseArg (int &, int, char **, bool); - CUDA_HOST int setFromCmd (int, char **, bool); + CUDA_HOST int parseArg (int &, int, const char * const *, bool); + CUDA_HOST int setFromCmd (int, const char * const *, bool); CUDA_HOST int loadCmdFromFile (std::string); - CUDA_HOST int saveCmdToFile (int, char **, std::string); + CUDA_HOST int saveCmdToFile (int, const char * const *, std::string); - CUDA_HOST void parseCoordinate (char *, int &, int &, int &); + CUDA_HOST void parseCoordinate (const char *, int &, int &, int &); #ifdef CUDA_ENABLED CUDA_HOST void prepareDeviceSettings (); @@ -226,7 +226,7 @@ class Settings CUDA_HOST void Uninitialize (); CUDA_HOST - void SetupFromCmd (int, char **); + void SetupFromCmd (int, const char * const *); #define SETTINGS_ELEM_FIELD_TYPE_NONE(fieldName, getterName, fieldType, defaultVal, cmdArg, description) \ CUDA_DEVICE CUDA_HOST fieldType getterName () \ diff --git a/Source/main.cpp b/Source/main.cpp index 6d4c56be..08a56af6 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -78,8 +78,7 @@ void initParallel (ParallelYeeGridLayout **yeeLayout, ParallelGridCoordinate overallSize, ParallelGridCoordinate pmlSize, ParallelGridCoordinate tfsfSizeLeft, - ParallelGridCoordinate tfsfSizeRight, - int argc, char** argv) + ParallelGridCoordinate tfsfSizeRight) { ParallelGridCoordinate topology (solverSettings.getTopologySizeX (), solverSettings.getTopologySizeY (), @@ -125,15 +124,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ex GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHy)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHy)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_ExHy)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_ExHy)), GridCoordinate1DTemplate, H_CENTERED> **layout, @@ -144,15 +142,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ex GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHy)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHy)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_ExHy)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_EX_HY */ @@ -166,15 +163,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ex GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHz)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHz)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_ExHz)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_ExHz)), GridCoordinate1DTemplate, H_CENTERED> **layout, @@ -185,15 +181,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ex GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHz)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_ExHz)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_ExHz)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_EX_HZ */ @@ -207,15 +202,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ey GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHx)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHx)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EyHx)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_EyHx)), GridCoordinate1DTemplate, H_CENTERED> **layout, @@ -226,15 +220,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ey GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHx)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHx)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EyHx)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_EY_HX */ @@ -248,15 +241,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ey GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHz)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHz)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EyHz)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_EyHz)), GridCoordinate1DTemplate, H_CENTERED> **layout, @@ -267,15 +259,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ey GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHz)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EyHz)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EyHz)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_EY_HZ */ @@ -289,15 +280,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ez GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHx)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHx)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EzHx)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_EzHx)), GridCoordinate1DTemplate, H_CENTERED> **layout, @@ -308,15 +298,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ez GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHx)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHx)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EzHx)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_EZ_HX */ @@ -330,15 +319,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ez GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHy)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHy)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EzHy)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_EzHy)), GridCoordinate1DTemplate, H_CENTERED> **layout, @@ -349,15 +337,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim1_Ez GridCoordinate1D overallSize, GridCoordinate1D pmlSize, GridCoordinate1D tfsfSizeLeft, - GridCoordinate1D tfsfSizeRight, - int argc, char** argv) + GridCoordinate1D tfsfSizeRight) { #ifdef GRID_1D ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHy)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim1_EzHy)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim1_EzHy)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_EZ_HY */ @@ -371,15 +358,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TE GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEx)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEx)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TEx)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TEx)), GridCoordinate2DTemplate, H_CENTERED> **layout, @@ -390,15 +376,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TE GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEx)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEx)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TEx)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_TEX */ @@ -412,15 +397,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TE GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEy)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEy)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TEy)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TEy)), GridCoordinate2DTemplate, H_CENTERED> **layout, @@ -431,15 +415,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TE GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEy)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEy)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TEy)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_TEY */ @@ -453,15 +436,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TE GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEz)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEz)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TEz)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TEz)), GridCoordinate2DTemplate, H_CENTERED> **layout, @@ -472,15 +454,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TE GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEz)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TEz)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TEz)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_TEZ */ @@ -494,15 +475,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TM GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMx)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMx)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TMx)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TMx)), GridCoordinate2DTemplate, H_CENTERED> **layout, @@ -513,15 +493,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TM GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMx)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMx)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TMx)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_TMX */ @@ -535,15 +514,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TM GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMy)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMy)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TMy)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TMy)), GridCoordinate2DTemplate, H_CENTERED> **layout, @@ -554,15 +532,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TM GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMy)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMy)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TMy)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_TMY */ @@ -576,15 +553,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TM GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMz)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMz)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TMz)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TMz)), GridCoordinate2DTemplate, H_CENTERED> **layout, @@ -595,15 +571,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim2_TM GridCoordinate2D overallSize, GridCoordinate2D pmlSize, GridCoordinate2D tfsfSizeLeft, - GridCoordinate2D tfsfSizeRight, - int argc, char** argv) + GridCoordinate2D tfsfSizeRight) { #ifdef GRID_2D ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMz)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim2_TMz)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim2_TMz)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_TMZ */ @@ -617,15 +592,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim3)), GridCoordinate3D overallSize, GridCoordinate3D pmlSize, GridCoordinate3D tfsfSizeLeft, - GridCoordinate3D tfsfSizeRight, - int argc, char** argv) + GridCoordinate3D tfsfSizeRight) { #ifdef GRID_3D ParallelYeeGridLayout<(static_cast (SchemeType::Dim3)), E_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim3)), E_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim3)), E_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim3)), GridCoordinate3DTemplate, H_CENTERED> **layout, @@ -636,15 +610,14 @@ void initParallel (YeeGridLayout<(static_cast (SchemeType::Dim3)), GridCoordinate3D overallSize, GridCoordinate3D pmlSize, GridCoordinate3D tfsfSizeLeft, - GridCoordinate3D tfsfSizeRight, - int argc, char** argv) + GridCoordinate3D tfsfSizeRight) { #ifdef GRID_3D ParallelYeeGridLayout<(static_cast (SchemeType::Dim3)), H_CENTERED> **pLayout = (ParallelYeeGridLayout<(static_cast (SchemeType::Dim3)), H_CENTERED> **) layout; initParallel<(static_cast (SchemeType::Dim3)), H_CENTERED> (pLayout, parallelGridCore, rank, numProcs, skipProcess, overallSize, pmlSize, - tfsfSizeLeft, tfsfSizeRight, argc, argv); + tfsfSizeLeft, tfsfSizeRight); #endif } #endif /* MODE_DIM3 */ @@ -1075,7 +1048,7 @@ initSettings<(static_cast (SchemeType::Dim3)), GridCoordinate3DTem #endif /* MODE_DIM3 */ template class TCoord, LayoutType layout_type> -int runMode (int argc, char** argv) +int runMode (int argc, const char * const * argv) { int rank = 0; int numProcs = 1; @@ -1098,7 +1071,14 @@ int runMode (int argc, char** argv) bool isParallel = false; #if defined (PARALLEL_GRID) - MPI_Init(&argc, &argv); + char **argv2 = new char *[argc]; + for (int i = 0; i < argc; ++i) + { + argv2[i] = new char[strlen(argv[i]) + 1]; + strcpy (argv2[i], argv[i]); + } + + MPI_Init(&argc, &argv2); #ifdef MPI_CLOCK DPRINTF (LOG_LEVEL_1, "MPI_Wtime resolution %.10f (seconds)\n", MPI_Wtick ()); @@ -1113,7 +1093,7 @@ int runMode (int argc, char** argv) { ALWAYS_ASSERT ((TCoord::dimension == ParallelGridCoordinateTemplate::dimension)); - initParallel (&yeeLayout, ¶llelGridCore, &rank, &numProcs, &skipProcess, overallSize, pmlSize, tfsfSizeLeft, tfsfSizeRight, argc, argv); + initParallel (&yeeLayout, ¶llelGridCore, &rank, &numProcs, &skipProcess, overallSize, pmlSize, tfsfSizeLeft, tfsfSizeRight); } else #endif @@ -1211,13 +1191,21 @@ int runMode (int argc, char** argv) delete parallelGridCore; MPI_Barrier (MPI_COMM_WORLD); - MPI_Finalize (); } #else UNREACHABLE; #endif } +#if defined (PARALLEL_GRID) + MPI_Finalize (); + for (int i = 0; i < argc; ++i) + { + delete[] argv2[i]; + } + delete[] argv2; +#endif + if (rank == 0) { printf ("Total time = %f seconds\n", @@ -1281,8 +1269,33 @@ int runMode (int argc, char** argv) return EXIT_OK; } +#ifdef PREDEFINED_ARGS +int main () +#else int main (int argc, char** argv) +#endif { +#ifdef PREDEFINED_ARGS + int argc = 28; + const char* argv[] = {"fdtd3dbench", + "--time-steps", "300", + "--size", "x:50,y:50,z:50", + "--3d", + "--angle-teta", "0", + "--angle-phi", "0", + "--angle-psi", "0", + "--dx", "0.0005", + "--wavelength", "0.02", + "--log-level", "0", + "--use-ca-cb", + "--use-ca-cb-pml", + "--pml-size", "x:10,y:10,z:10", + "--use-pml", + "--use-tfsf", + "--tfsf-size-left", "x:12,y:12,z:12", + "--tfsf-size-right", "x:12,y:12,z:12"}; +#endif + solverSettings.SetupFromCmd (argc, argv); int exit_code = EXIT_OK;