From 800aadf9fba63370b99bcd341c17e7e9673af5a9 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 14 Mar 2024 12:53:27 -0600 Subject: [PATCH 01/76] minimal restart output working --- src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/fclaw_options.c | 2 + src/fclaw_options.h | 1 + src/fclaw_output.c | 10 +++++ src/fclaw_restart.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ src/fclaw_restart.h | 48 ++++++++++++++++++++++ 7 files changed, 162 insertions(+) create mode 100644 src/fclaw_restart.c create mode 100644 src/fclaw_restart.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 324aa8a60..bfe45c71b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ add_library(forestclaw_c OBJECT fclaw_physical_bc.c fclaw_ghost_fill.c fclaw_output.c + fclaw_restart.c fclaw_run.c fclaw_diagnostics.c fclaw_rays.c @@ -112,6 +113,7 @@ install(FILES fclaw_patch.h fclaw_vtable.h fclaw_output.h + fclaw_restart.h fclaw_time_sync.h fclaw_update_single_step.h fclaw_physical_bc.h diff --git a/src/Makefile.am b/src/Makefile.am index 41c34e2b3..d2958918c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,7 @@ libforestclaw_installed_headers = \ src/fclaw_patch.h \ src/fclaw_vtable.h \ src/fclaw_output.h \ + src/fclaw_restart.h \ src/fclaw_time_sync.h \ src/fclaw_update_single_step.h \ src/fclaw_physical_bc.h \ @@ -92,6 +93,7 @@ libforestclaw_compiled_sources = \ src/fclaw_rays.c \ src/fclaw_ghost_fill.c \ src/fclaw_output.c \ + src/fclaw_restart.c \ src/fclaw_run.c \ src/fclaw_diagnostics.c \ src/fclaw_update_single_step.c \ diff --git a/src/fclaw_options.c b/src/fclaw_options.c index 6dd3803d0..d628fb83f 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -124,6 +124,8 @@ fclaw_register (fclaw_options_t* fclaw_opt, sc_options_t * opt) sc_options_add_bool (opt, 0, "output", &fclaw_opt->output, 0, "Enable output [F]"); + sc_options_add_bool (opt, 0, "restart-out", &fclaw_opt->restart_out, 0, + "Enable restart output [F]"); /* -------------------------------------- Gauges --------------------------------- */ /* Gauge options */ diff --git a/src/fclaw_options.h b/src/fclaw_options.h index 1dcf7b26a..2c7b907f6 100644 --- a/src/fclaw_options.h +++ b/src/fclaw_options.h @@ -228,6 +228,7 @@ struct fclaw_options int verbosity; /**< TODO: Do we have guidelines here? */ int output; + int restart_out; int tikz_out; /* Boolean */ const char *tikz_figsize_string; diff --git a/src/fclaw_output.c b/src/fclaw_output.c index 3a437cb5a..6cc172fb3 100644 --- a/src/fclaw_output.c +++ b/src/fclaw_output.c @@ -24,6 +24,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include #include #include @@ -69,6 +70,15 @@ fclaw_output_frame (fclaw_global_t * glob, int iframe) { fclaw2d_output_frame_tikz(glob,iframe); } + + if(fclaw_opt->restart_out) + { + fclaw_timer_start (&glob->timers[FCLAW_TIMER_OUTPUT]); + + fclaw_restart_output_frame(glob,iframe); + + fclaw_timer_stop (&glob->timers[FCLAW_TIMER_OUTPUT]); + } } diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c new file mode 100644 index 000000000..de0c024ce --- /dev/null +++ b/src/fclaw_restart.c @@ -0,0 +1,97 @@ +/* +Copyright (c) 2012-2024 Carsten Burstedde, Donna Calhoun, Scott Aiton +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include +#include + +typedef struct pack_iter +{ + fclaw_global_t * glob; + int curr_index; + size_t packsize; + sc_array_t* patches; + fclaw_patch_vtable_t *patch_vt; +}pack_iter_t; +static void +get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) +{ + pack_iter_t *user_data = (pack_iter_t*)user; + sc_array_t *patches = user_data->patches; + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); + sc_array_init_size (current_arr, user_data->packsize, 1); + void* buffer = sc_array_index (current_arr, 0); + user_data->patch_vt->partition_pack(user_data->glob, patch, blockno, patchno, buffer); + user_data->curr_index++; +} +/* ----------------------------------------------------------------------- + Public interface + -------------------------------------------------------------------- */ + +void +fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) +{ + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + + char filename[BUFSIZ]; + snprintf(filename, BUFSIZ, "fort_frame_%04d.restart", iframe); + + int errcode; + fclaw3d_file_context_t *fc + = fclaw3d_file_open_write (filename, "ForestClaw data file", + glob->domain->d3, &errcode); + + size_t packsize = patch_vt->partition_packsize(glob); + sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); + pack_iter_t user; + user.glob = glob; + user.curr_index = 0; + user.patches = patches; + user.packsize = packsize; + user.patch_vt = patch_vt; + fclaw_domain_iterate_patches(glob->domain, get_patches, &user); + + + fclaw3d_file_write_array(fc, "meqn", packsize, patches, &errcode); + + for(int i = 0; i < glob->domain->local_num_patches; i++) + { + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, i); + sc_array_reset(current_arr); + } + + sc_array_destroy(patches); + + fclaw3d_file_close(fc, &errcode); + fclaw_global_productionf("RESTATRTT!!\n"); +} + + + + diff --git a/src/fclaw_restart.h b/src/fclaw_restart.h new file mode 100644 index 000000000..fd802f799 --- /dev/null +++ b/src/fclaw_restart.h @@ -0,0 +1,48 @@ +/* +Copyright (c) 2012-2024 Carsten Burstedde, Donna Calhoun, Scott Aiton +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef FCLAW_RESTART_H +#define FCLAW_RESTART_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} +#endif +#endif + +struct fclaw_global; /* This is a hack !! */ + +void fclaw_restart_output_frame(struct fclaw_global * glob, int iframe); + +#ifdef __cplusplus +#if 0 +{ +#endif +} +#endif + +#endif From 62ad4ce1e7d0f0a764a953f62d846f673a14556a Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 14 Mar 2024 19:23:01 -0600 Subject: [PATCH 02/76] new domain / reading patches work --- src/fclaw_restart.c | 75 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index de0c024ce..e8695e06d 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -28,8 +28,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #include #include +#include +#include typedef struct pack_iter { @@ -47,9 +51,29 @@ get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); sc_array_init_size (current_arr, user_data->packsize, 1); void* buffer = sc_array_index (current_arr, 0); - user_data->patch_vt->partition_pack(user_data->glob, patch, blockno, patchno, buffer); + fclaw_patch_partition_pack(user_data->glob, patch, blockno, patchno, buffer); user_data->curr_index++; } +static void +set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) +{ + pack_iter_t *user_data = (pack_iter_t*)user; + sc_array_t *patches = user_data->patches; + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); + void* buffer = sc_array_index (current_arr, 0); + + fclaw_patch_partition_unpack(user_data->glob, user_data->glob->domain, patch, blockno, patchno, buffer); + + sc_array_reset(current_arr); + + user_data->curr_index++; +} +//TODO move this to header +void +fclaw_restart_from_file (fclaw_global_t * glob, + const char* restart_filename, + const char* partition_filename); + /* ----------------------------------------------------------------------- Public interface -------------------------------------------------------------------- */ @@ -60,7 +84,9 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); char filename[BUFSIZ]; + char parition_filename[BUFSIZ]; snprintf(filename, BUFSIZ, "fort_frame_%04d.restart", iframe); + snprintf(parition_filename, BUFSIZ, "fort_frame_%04d.partition", iframe); int errcode; fclaw3d_file_context_t *fc @@ -89,9 +115,56 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) sc_array_destroy(patches); fclaw3d_file_close(fc, &errcode); + fclaw3d_file_write_partition (parition_filename, + "Test partition write", + glob->domain->d3, &errcode); + + fclaw_restart_from_file(glob, filename, parition_filename); + fclaw_global_productionf("RESTATRTT!!\n"); } +void +fclaw_restart_from_file (fclaw_global_t * glob, + const char* restart_filename, + const char* partition_filename) +{ + fclaw_domain_reset(glob); + + int errcode; + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + sc_array_t* partition = sc_array_new(sizeof(p4est_gloidx_t)); + char user_string[FCLAW3D_FILE_USER_STRING_BYTES]; + if(partition_filename != NULL) + { + fclaw3d_file_read_partition(partition_filename, user_string, glob->mpicomm, partition, &errcode); + + } + fclaw3d_domain_t * domain_3d; + fclaw3d_file_context_t *fc + = fclaw3d_file_open_read (restart_filename, user_string, glob->mpicomm, partition, &domain_3d, &errcode); + glob->domain = fclaw_domain_wrap_3d(domain_3d); + fclaw_domain_setup(glob, glob->domain); + sc_array_destroy(partition); + + size_t packsize = patch_vt->partition_packsize(glob); + sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); + + fclaw3d_file_read_array(fc, user_string, packsize, patches, &errcode); + + pack_iter_t user; + user.glob = glob; + user.curr_index = 0; + user.patches = patches; + user.packsize = packsize; + user.patch_vt = patch_vt; + fclaw_domain_iterate_patches(glob->domain, set_patches, &user); + + sc_array_destroy(patches); + + fclaw3d_file_close(fc, &errcode); + fclaw_exchange_setup(glob,FCLAW_TIMER_OUTPUT); +} From 1797f3d939b851769842bef17cca8882289cc1f2 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 14 Mar 2024 19:56:23 -0600 Subject: [PATCH 03/76] (wip) pack glob in block --- src/fclaw_global.c | 10 +++++----- src/fclaw_global.h | 6 +++--- src/fclaw_global.h.TEST.cpp | 34 +++++++++++++++++----------------- src/fclaw_restart.c | 26 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 7205d822c..224fa35ff 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -116,7 +116,7 @@ pack_iterator_callback(const char* key, void* value, void* user) } size_t -fclaw2d_global_pack(const fclaw_global_t * glob, char* buffer) +fclaw_global_pack(const fclaw_global_t * glob, char* buffer) { const char* buffer_start = buffer; @@ -125,7 +125,7 @@ fclaw2d_global_pack(const fclaw_global_t * glob, char* buffer) buffer += fclaw_pack_size_t(fclaw_pointer_map_size(glob->options), buffer); - fclaw_pointer_map_iterate(glob->options, pack_iterator_callback, &buffer); + //fclaw_pointer_map_iterate(glob->options, pack_iterator_callback, &buffer); return (buffer-buffer_start); } @@ -140,15 +140,15 @@ packsize_iterator_callback(const char* key, void* value, void* user) } size_t -fclaw2d_global_packsize(const fclaw_global_t * glob) +fclaw_global_packsize(const fclaw_global_t * glob) { size_t options_size = sizeof(size_t); - fclaw_pointer_map_iterate(glob->options, packsize_iterator_callback, &options_size); + //fclaw_pointer_map_iterate(glob->options, packsize_iterator_callback, &options_size); return 2*sizeof(double) + options_size; } size_t -fclaw2d_global_unpack(char* buffer, fclaw_global_t ** glob_ptr) +fclaw_global_unpack(char* buffer, fclaw_global_t ** glob_ptr) { char* buffer_start = buffer; diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 3e88826ad..44b8920c5 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -143,7 +143,7 @@ struct fclaw_map_context* fclaw_map_get(fclaw_global_t* glob); * @param buffer the buffer to write to * @return size_t number of bytes written */ -size_t fclaw2d_global_pack(const fclaw_global_t * glob, char* buffer); +size_t fclaw_global_pack(const fclaw_global_t * glob, char* buffer); /** * @brief Get the number of bytes needed to pack the global structure @@ -151,7 +151,7 @@ size_t fclaw2d_global_pack(const fclaw_global_t * glob, char* buffer); * @param glob the structure * @return size_t the number of bytes needed to store structure */ -size_t fclaw2d_global_packsize(const fclaw_global_t * glob); +size_t fclaw_global_packsize(const fclaw_global_t * glob); /** * @brief Unpack global structure from buffer @@ -160,7 +160,7 @@ size_t fclaw2d_global_packsize(const fclaw_global_t * glob); * @param glob newly create global structure * @return size_t number of bytes read */ -size_t fclaw2d_global_unpack(char* buffer, fclaw_global_t** glob); +size_t fclaw_global_unpack(char* buffer, fclaw_global_t** glob); void fclaw_global_iterate_level (fclaw_global_t * glob, int level, fclaw_patch_callback_t pcb, void *user); diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 6a6dde604..9c92d1e5a 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -44,18 +44,18 @@ TEST_CASE("fclaw2d_global_pack with no options") glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; - size_t packsize = fclaw2d_global_packsize(glob1); + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); char buffer[packsize]; - size_t bytes_written = fclaw2d_global_pack(glob1, buffer); + size_t bytes_written = fclaw_global_pack(glob1, buffer); REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2; - size_t bytes_read = fclaw2d_global_unpack(buffer, &glob2); + size_t bytes_read = fclaw_global_unpack(buffer, &glob2); REQUIRE_EQ(bytes_read, packsize); @@ -145,17 +145,17 @@ TEST_CASE("fclaw_global_pack with no options structure") glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; - size_t packsize = fclaw2d_global_packsize(glob1); + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); char buffer[packsize]; - size_t bytes_written = fclaw2d_global_pack(glob1, buffer); + size_t bytes_written = fclaw_global_pack(glob1, buffer); REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2; - size_t bytes_read = fclaw2d_global_unpack(buffer, &glob2); + size_t bytes_read = fclaw_global_unpack(buffer, &glob2); REQUIRE_EQ(bytes_read, packsize); @@ -188,17 +188,17 @@ TEST_CASE("fclaw_global_pack with a single options structure") fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); - size_t packsize = fclaw2d_global_packsize(glob1); + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); char buffer[packsize]; - size_t bytes_written = fclaw2d_global_pack(glob1, buffer); + size_t bytes_written = fclaw_global_pack(glob1, buffer); REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2; - size_t bytes_read = fclaw2d_global_unpack(buffer, &glob2); + size_t bytes_read = fclaw_global_unpack(buffer, &glob2); REQUIRE_EQ(bytes_read, packsize); @@ -237,17 +237,17 @@ TEST_CASE("fclaw_global_pack with two options structure") fclaw_app_register_options_packing_vtable("dummy2", &dummy_opts_vt); fclaw_pointer_map_insert(glob1->options, "dummy2", options2, destroy_dummy_options); - size_t packsize = fclaw2d_global_packsize(glob1); + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); char buffer[packsize]; - size_t bytes_written = fclaw2d_global_pack(glob1, buffer); + size_t bytes_written = fclaw_global_pack(glob1, buffer); REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2; - size_t bytes_read = fclaw2d_global_unpack(buffer, &glob2); + size_t bytes_read = fclaw_global_unpack(buffer, &glob2); REQUIRE_EQ(bytes_read, packsize); @@ -282,7 +282,7 @@ TEST_CASE("fclaw_global_pack aborts with unregistered vtable") fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); char buffer[100]; - CHECK_SC_ABORTED(fclaw2d_global_pack(glob1, buffer)); + CHECK_SC_ABORTED(fclaw_global_pack(glob1, buffer)); } TEST_CASE("fclaw2d_global_packsize aborts with unregistered vtable") { @@ -294,7 +294,7 @@ TEST_CASE("fclaw2d_global_packsize aborts with unregistered vtable") dummy_options* options = new dummy_options(20, 'a'); fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); - CHECK_SC_ABORTED(fclaw2d_global_packsize(glob1)); + CHECK_SC_ABORTED(fclaw_global_packsize(glob1)); } TEST_CASE("fclaw_global_unppack aborts with unregistered vtable") { @@ -307,18 +307,18 @@ TEST_CASE("fclaw_global_unppack aborts with unregistered vtable") fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); - size_t packsize = fclaw2d_global_packsize(glob1); + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); char buffer[packsize]; - size_t bytes_written = fclaw2d_global_pack(glob1, buffer); + size_t bytes_written = fclaw_global_pack(glob1, buffer); REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2=nullptr; fclaw_app_register_options_packing_vtable("dummy1", nullptr); - CHECK_SC_ABORTED(fclaw2d_global_unpack(buffer, &glob2)); + CHECK_SC_ABORTED(fclaw_global_unpack(buffer, &glob2)); } TEST_CASE("fclaw_global_options_store and fclaw_global_get_options test") { fclaw_global_t* glob = fclaw_global_new(); diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index e8695e06d..9dcac5d9a 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -92,6 +92,20 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) fclaw3d_file_context_t *fc = fclaw3d_file_open_write (filename, "ForestClaw data file", glob->domain->d3, &errcode); + + size_t glob_packsize = fclaw_global_packsize(glob); + + sc_array_t globsize; + sc_array_init_size(&globsize, sizeof(size_t), 1); + *((size_t*) sc_array_index(&globsize, 0)) = glob_packsize; + fclaw3d_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); + sc_array_reset(&globsize); + + sc_array_t glob_buffer; + sc_array_init_size(&glob_buffer, glob_packsize, 1); + fclaw_global_pack(glob,(char *) sc_array_index(&glob_buffer, 0)); + fclaw3d_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); + sc_array_reset(&glob_buffer); size_t packsize = patch_vt->partition_packsize(glob); sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); @@ -148,6 +162,18 @@ fclaw_restart_from_file (fclaw_global_t * glob, fclaw_domain_setup(glob, glob->domain); sc_array_destroy(partition); + sc_array_t globsize; + sc_array_init_size(&globsize, sizeof(size_t), 1); + fclaw3d_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); + size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); + sc_array_reset(&globsize); + + sc_array_t glob_buffer; + sc_array_init_size(&glob_buffer, glob_packsize, 1); + fclaw3d_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); + sc_array_reset(&glob_buffer); + + size_t packsize = patch_vt->partition_packsize(glob); sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); From 3b83d00ab58dca9204aee7233e4405807621d7c2 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 09:49:53 -0600 Subject: [PATCH 04/76] update globl pack/unpack --- src/fclaw_global.c | 27 +++++++--------- src/fclaw_global.h | 4 +-- src/fclaw_global.h.TEST.cpp | 62 ++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 224fa35ff..d0f980d17 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -148,30 +148,27 @@ fclaw_global_packsize(const fclaw_global_t * glob) } size_t -fclaw_global_unpack(char* buffer, fclaw_global_t ** glob_ptr) +fclaw_global_unpack(char* buffer, fclaw_global_t * glob) { char* buffer_start = buffer; - fclaw_global_t* glob = fclaw_global_new(); - *glob_ptr = glob; - buffer += fclaw_unpack_double(buffer,&glob->curr_time); buffer += fclaw_unpack_double(buffer,&glob->curr_dt); size_t num_option_structs; buffer += fclaw_unpack_size_t(buffer,&num_option_structs); - for(size_t i = 0; i< num_option_structs; i++) - { - char * key; - buffer += fclaw_unpack_string(buffer,&key); - fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - check_vt(vt,key); - void * options; - buffer += vt->unpack(buffer,&options); - fclaw_pointer_map_insert(glob->options, key, options, vt->destroy); - FCLAW_FREE(key); - } + //for(size_t i = 0; i< num_option_structs; i++) + //{ + // char * key; + // buffer += fclaw_unpack_string(buffer,&key); + // fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); + // check_vt(vt,key); + // void * options; + // buffer += vt->unpack(buffer,&options); + // fclaw_pointer_map_insert(glob->options, key, options, vt->destroy); + // FCLAW_FREE(key); + //} return buffer-buffer_start; } diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 44b8920c5..3a6cd34ef 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -157,10 +157,10 @@ size_t fclaw_global_packsize(const fclaw_global_t * glob); * @brief Unpack global structure from buffer * * @param buffer the buffer to read from - * @param glob newly create global structure + * @param glob glob structure to write to * @return size_t number of bytes read */ -size_t fclaw_global_unpack(char* buffer, fclaw_global_t** glob); +size_t fclaw_global_unpack(char* buffer, fclaw_global_t* glob); void fclaw_global_iterate_level (fclaw_global_t * glob, int level, fclaw_patch_callback_t pcb, void *user); diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 9c92d1e5a..a0ea7af45 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -54,8 +54,8 @@ TEST_CASE("fclaw2d_global_pack with no options") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2; - size_t bytes_read = fclaw_global_unpack(buffer, &glob2); + fclaw_global_t* glob2 = fclaw_global_new(); + size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -154,8 +154,8 @@ TEST_CASE("fclaw_global_pack with no options structure") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2; - size_t bytes_read = fclaw_global_unpack(buffer, &glob2); + fclaw_global_t* glob2 = fclaw_global_new(); + size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -168,6 +168,7 @@ TEST_CASE("fclaw_global_pack with no options structure") fclaw_global_destroy(glob2); } } +#if 0 TEST_CASE("fclaw_global_pack with a single options structure") { @@ -184,9 +185,9 @@ TEST_CASE("fclaw_global_pack with a single options structure") glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; - dummy_options* options = new dummy_options(20, 'a'); + dummy_options* options1 = new dummy_options(20, 'a'); fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); + fclaw_pointer_map_insert(glob1->options, "dummy1", options1, destroy_dummy_options); size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -197,8 +198,10 @@ TEST_CASE("fclaw_global_pack with a single options structure") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2; - size_t bytes_read = fclaw_global_unpack(buffer, &glob2); + fclaw_global_t* glob2 = fclaw_global_new(); + dummy_options* options2 = new dummy_options(99, 'z'); + fclaw_pointer_map_insert(glob2->options, "dummy1", options2, destroy_dummy_options); + size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -207,13 +210,8 @@ TEST_CASE("fclaw_global_pack with a single options structure") REQUIRE_EQ(fclaw_pointer_map_size(glob2->options), 1); - dummy_options* options_unpacked = (dummy_options*) fclaw_pointer_map_get(glob2->options, "dummy1"); - REQUIRE(options_unpacked != nullptr); - - CHECK_EQ(options_unpacked->size, options->size); - CHECK_EQ(options_unpacked->value, options->value); - - + CHECK_EQ(options2->size, options1->size); + CHECK_EQ(options2->value, options1->value); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); @@ -230,12 +228,12 @@ TEST_CASE("fclaw_global_pack with two options structure") glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; - dummy_options* options = new dummy_options(20, 'a'); - dummy_options* options2 = new dummy_options(40, 'b'); + dummy_options* options1_1 = new dummy_options(20, 'a'); + dummy_options* options1_2 = new dummy_options(40, 'b'); fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); + fclaw_pointer_map_insert(glob1->options, "dummy1", options1_1, destroy_dummy_options); fclaw_app_register_options_packing_vtable("dummy2", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy2", options2, destroy_dummy_options); + fclaw_pointer_map_insert(glob1->options, "dummy2", options1_2, destroy_dummy_options); size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -246,8 +244,12 @@ TEST_CASE("fclaw_global_pack with two options structure") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2; - size_t bytes_read = fclaw_global_unpack(buffer, &glob2); + fclaw_global_t* glob2 = fclaw_global_new(); + dummy_options* options2_1 = new dummy_options(99, 'z'); + dummy_options* options2_2 = new dummy_options(99, 'z'); + fclaw_pointer_map_insert(glob2->options, "dummy1", options2_1, destroy_dummy_options); + fclaw_pointer_map_insert(glob2->options, "dummy2", options2_2, destroy_dummy_options); + size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -256,16 +258,11 @@ TEST_CASE("fclaw_global_pack with two options structure") REQUIRE_EQ(fclaw_pointer_map_size(glob2->options), 2); - dummy_options* options_unpacked = (dummy_options*) fclaw_pointer_map_get(glob2->options, "dummy1"); - dummy_options* options_unpacked2 = (dummy_options*) fclaw_pointer_map_get(glob2->options, "dummy2"); - REQUIRE(options_unpacked != nullptr); - REQUIRE(options_unpacked2 != nullptr); + CHECK_EQ(options2_1->size, options1_1->size); + CHECK_EQ(options2_1->value, options1_1->value); - CHECK_EQ(options_unpacked->size, options->size); - CHECK_EQ(options_unpacked->value, options->value); - - CHECK_EQ(options_unpacked2->size, options2->size); - CHECK_EQ(options_unpacked2->value, options2->value); + CHECK_EQ(options2_2->size, options1_2->size); + CHECK_EQ(options2_2->value, options1_2->value); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); @@ -316,10 +313,11 @@ TEST_CASE("fclaw_global_unppack aborts with unregistered vtable") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2=nullptr; + fclaw_global_t* glob2=fclaw_global_new(); fclaw_app_register_options_packing_vtable("dummy1", nullptr); - CHECK_SC_ABORTED(fclaw_global_unpack(buffer, &glob2)); + CHECK_SC_ABORTED(fclaw_global_unpack(buffer, glob2)); } +#endif TEST_CASE("fclaw_global_options_store and fclaw_global_get_options test") { fclaw_global_t* glob = fclaw_global_new(); From 8ac3b84a1691b8a04bbc609d977b704e962abaa8 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 10:11:08 -0600 Subject: [PATCH 05/76] add test for global default values --- src/fclaw_global.h.TEST.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index a0ea7af45..5f2b2c7a3 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -32,6 +32,39 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +TEST_CASE("fclaw_global_new default options") +{ + fclaw_global_t* glob = fclaw_global_new(); + + + CHECK_EQ(glob->curr_time, 0.0); + CHECK_EQ(glob->curr_dt, 0.0); + + CHECK_EQ(glob->count_amr_advance, 0); + CHECK_EQ(glob->count_ghost_exchange, 0); + CHECK_EQ(glob->count_amr_regrid, 0); + CHECK_EQ(glob->count_amr_new_domain, 0); + CHECK_EQ(glob->count_single_step, 0); + CHECK_EQ(glob->count_elliptic_grids, 0); + CHECK_EQ(glob->count_multiproc_corner, 0); + CHECK_EQ(glob->count_grids_per_proc, 0); + CHECK_EQ(glob->count_grids_remote_boundary, 0); + CHECK_EQ(glob->count_grids_local_boundary, 0); + + CHECK_EQ(glob->mpisize, 0); + CHECK_EQ(glob->mpirank, -1); + + CHECK_EQ(fclaw_pointer_map_size(glob->vtables), 0); + CHECK_EQ(fclaw_pointer_map_size(glob->options), 0); + CHECK(glob->cont == nullptr); + CHECK(glob->domain == nullptr); + CHECK(glob->acc != nullptr); + CHECK(glob->gauge_info == nullptr); + CHECK(glob->user == nullptr); + + + fclaw_global_destroy(glob); +} TEST_CASE("fclaw2d_global_pack with no options") { From 91012b911edc6d985a1c3506fc2e3b310f82df7b Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 11:27:25 -0600 Subject: [PATCH 06/76] add tests for attributes --- src/fclaw_global.c | 34 +++++++++++++++++++++ src/fclaw_global.h | 60 +++++++++++++++++++++++++++++++++++-- src/fclaw_global.h.TEST.cpp | 40 +++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index d0f980d17..7b10f320a 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -52,6 +52,7 @@ fclaw_global_t* fclaw_global_new (void) glob->pkg_container = fclaw_package_container_new (); glob->vtables = fclaw_pointer_map_new (); glob->options = fclaw_pointer_map_new (); + glob->attributes = fclaw_pointer_map_new (); glob->count_amr_advance = 0; glob->count_ghost_exchange = 0; @@ -209,6 +210,7 @@ fclaw_global_destroy (fclaw_global_t * glob) if(glob->pkg_container != NULL) fclaw_package_container_destroy ((fclaw_package_container_t *)glob->pkg_container); if(glob->vtables != NULL) fclaw_pointer_map_destroy (glob->vtables); if(glob->options != NULL) fclaw_pointer_map_destroy (glob->options); + if(glob->attributes != NULL) fclaw_pointer_map_destroy (glob->attributes); #ifndef P4_TO_P8 FCLAW_FREE (glob->acc); @@ -287,6 +289,38 @@ void* fclaw_global_get_options (fclaw_global_t* glob, const char* key) return options; } +void +fclaw_global_attribute_store (fclaw_global_t * glob, + const char * key, + void* attribute, + const char * packing_key, + fclaw_pointer_map_value_destroy_t destroy) +{ + +} + +void * +fclaw_global_get_attribute (fclaw_global_t* glob, const char* key) +{ + return NULL; +} + +void +fclaw_global_register_options_packing_vtable(fclaw_global_t * glob, + const char*name, + fclaw_packing_vtable_t* vtable, + fclaw_pointer_map_value_destroy_t destroy) +{ + // +} + +fclaw_packing_vtable_t * +fclaw_global_get_options_packing_vtable(fclaw_global_t * glob, const char*name) +{ + // + return NULL; +} + static fclaw_global_t* fclaw2d_global_glob = NULL; void fclaw_global_set_static (fclaw_global_t* glob) diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 3a6cd34ef..5d94fa766 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include /* Needed to store the map context */ #include /* Needed to create statically allocated array of timers */ +#include /* Needed to store vtables and options */ #ifdef __cplusplus extern "C" @@ -79,8 +80,10 @@ struct fclaw_global /** Solver packages for internal use. */ struct fclaw_package_container *pkg_container; - struct fclaw_pointer_map *vtables; /**< Vtables */ - struct fclaw_pointer_map *options; /**< options */ + fclaw_pointer_map_t *vtables; /**< Vtables */ + fclaw_pointer_map_t *options; /**< options */ + + fclaw_pointer_map_t *attributes; /**< attributes */ struct fclaw_map_context* cont; struct fclaw_domain *domain; @@ -201,6 +204,59 @@ void fclaw_global_options_store (fclaw_global_t* glob, const char* key, void* op */ void* fclaw_global_get_options (fclaw_global_t* glob, const char* key); +/** + * @brief Store an attribute structure in the glob + * + * @param glob the global context + * @param key the key to store the attribute under + * @param attribute the attribute structure + * @param packing_key the key to use for packing the attribute, NULL if not needed + * @param destroy the callback to destroy the attribute, NULL if not needed + */ +void +fclaw_global_attribute_store (fclaw_global_t * glob, + const char * key, + void* attribute, + const char * packing_key, + fclaw_pointer_map_value_destroy_t destroy); + +/** + * @brief Get an attribute structure from the glob + * + * @param glob the global context + * @param key the key to retrieve the attribute from + * @return void* the attribute + */ +void * +fclaw_global_get_attribute (fclaw_global_t* glob, const char* key); + + +/** + * @brief Register a vtable used for packing attributes + * + * These should be done alongside the intialization of other vtables + * + * @param glob the global context + * @param key the key, this should be the same key used in packing_key when storing attributes + * @param destroy the callback to destroy the vtable, NULL if not needed + * @param vtable the vtable + */ +void +fclaw_global_register_attribute_packing_vtable(fclaw_global_t * glob, + const char * key, + fclaw_packing_vtable_t * vtable, + fclaw_pointer_map_value_destroy_t destroy); + +/** + * @brief Get an attribute packing vtable + * + * @param glob the global context + * @param key the key, this should be the same key used in packing_key when storing attributes + * @return fclaw_packing_vtable_t* the vtable + */ +fclaw_packing_vtable_t * +fclaw_global_get_attribute_packing_vtable(fclaw_global_t * glob, const char * key); + /** * @brief Store a glob variable in static memory * diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 5f2b2c7a3..7a52f73fb 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -56,6 +56,7 @@ TEST_CASE("fclaw_global_new default options") CHECK_EQ(fclaw_pointer_map_size(glob->vtables), 0); CHECK_EQ(fclaw_pointer_map_size(glob->options), 0); + CHECK_EQ(fclaw_pointer_map_size(glob->attributes), 0); CHECK(glob->cont == nullptr); CHECK(glob->domain == nullptr); CHECK(glob->acc != nullptr); @@ -426,4 +427,43 @@ TEST_CASE("fclaw2d_global_get_global assert fails when NULL") CHECK_SC_ABORTED(fclaw_global_get_static_global()); } +TEST_CASE("fclaw_global_attribute_store and fclaw_global_get_attribute test") { + fclaw_global_t* glob = fclaw_global_new(); + + // Test with an integer + int attribute1 = 10; + const char* key1 = "attribute1"; + fclaw_global_attribute_store(glob, key1, &attribute1, nullptr, nullptr); + + int* retrieved_attribute1 = static_cast(fclaw_global_get_attribute(glob, key1)); + CHECK_EQ(*retrieved_attribute1, attribute1); + + // Test with a string + const char* attribute2 = "Test string"; + const char* key2 = "attribute2"; + fclaw_global_attribute_store(glob, key2, &attribute2, nullptr, nullptr); + + const char** retrieved_attribute2 = static_cast(fclaw_global_get_attribute(glob, key2)); + CHECK_EQ(*retrieved_attribute2, attribute2); + +#ifdef FCLAW_ENABLE_DEBUG + // TEST inserting twice + CHECK_SC_ABORTED(fclaw_global_attribute_store(glob, key2, &attribute2, nullptr, nullptr)); +#endif + // Test with a non-existing key + const char* key3 = "non-existing key"; + void* retrieved_attribute3 = fclaw_global_get_attribute(glob, key3); + CHECK_EQ(retrieved_attribute3, nullptr); + + // Test with a destroy callback + int* attribute4 = new int(20); + const char* key4 = "attribute4"; + fclaw_global_attribute_store(glob, key4, attribute4, nullptr, [](void* ptr) { delete static_cast(ptr); }); + + int* retrieved_attribute4 = static_cast(fclaw_global_get_attribute(glob, key4)); + CHECK_EQ(*retrieved_attribute4, *attribute4); + + fclaw_global_destroy(glob); +} + #endif From ae6207737f0d6cbca0466e735847a479dbfc648b Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 11:27:47 -0600 Subject: [PATCH 07/76] call fclaw_app_destroy for tests --- test/test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test.cpp b/test/test.cpp index fe85e6018..53da703e6 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,5 +1,6 @@ #include #include +#include #define DOCTEST_CONFIG_IMPLEMENT #include @@ -88,13 +89,13 @@ int main(int argc, char *argv[]) } } else { // global setup... - fclaw_mpi_init(nullptr, nullptr, sc_MPI_COMM_WORLD, SC_LP_PRODUCTION); + fclaw_app_t * app = fclaw_app_new(&argc, &argv, nullptr); sc_set_abort_handler(throw_exception); result = context.run(); // global clean-up... - //fclaw_mpi_finalize(); + fclaw_app_destroy (app); return result; } From 81846766a8e52f11588366bbc234a8c15d53493c Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 14:05:55 -0600 Subject: [PATCH 08/76] fix leaks in tests --- src/fclaw_global.h | 6 +++ src/fclaw_options.h.TEST.cpp | 7 ++++ .../clawpatch/fclaw_clawpatch.h.3d.TEST.cpp | 12 +++--- .../fclaw_clawpatch.h.3d.average.TEST.cpp | 8 ++-- .../fclaw_clawpatch.h.3d.ghostfill.TEST.cpp | 41 +++++++++++-------- .../fclaw_clawpatch.h.3d.interpolate.TEST.cpp | 8 ++-- .../clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp | 2 + .../fclaw_clawpatch_options.h.TEST.cpp | 4 +- .../fc2d_clawpack46.h.TEST.cpp | 16 ++++++-- .../fc2d_clawpack46_options.h.TEST.cpp | 6 ++- .../fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp | 14 +++++-- .../fc2d_clawpack5_options.h.TEST.cpp | 6 ++- .../fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp | 26 +++++++++--- .../fc2d_geoclaw_options.h.TEST.cpp | 6 ++- .../fc2d_thunderegg.h.TEST.cpp | 3 ++ .../fc2d_thunderegg_options.h.TEST.cpp | 6 ++- .../fc3d_clawpack46.h.TEST.cpp | 12 ++++-- .../fc3d_clawpack46_options.h.TEST.cpp | 6 ++- 18 files changed, 137 insertions(+), 52 deletions(-) diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 5d94fa766..adcfbf9a2 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -123,6 +123,12 @@ fclaw_global_t* fclaw_global_new (void); fclaw_global_t* fclaw_global_new_comm (sc_MPI_Comm mpicomm, int mpisize, int mpirank); +/** + * @brief Destroy a global structure. + * This will not destroy the domain or map. + * + * @param glob the global structure + */ void fclaw_global_destroy (fclaw_global_t * glob); void fclaw_global_store_domain (fclaw_global_t* glob, diff --git a/src/fclaw_options.h.TEST.cpp b/src/fclaw_options.h.TEST.cpp index 46502d97c..f0b67fbf4 100644 --- a/src/fclaw_options.h.TEST.cpp +++ b/src/fclaw_options.h.TEST.cpp @@ -48,6 +48,9 @@ TEST_CASE("fclaw_options can store options in two seperate globs") fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); } #ifdef FCLAW_ENABLE_DEBUG @@ -285,6 +288,10 @@ TEST_CASE("fclaw_options packing/unpacking") CHECK_UNARY(!strcmp(opts->logging_prefix, output_opts->logging_prefix)); CHECK_UNARY(output_opts->is_unpacked); + + vt->destroy(output_opts); + + FCLAW_FREE(opts); } #endif \ No newline at end of file diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp index 1a0e23a0d..57198d449 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp @@ -99,7 +99,7 @@ struct SinglePatchDomain { fclaw_vtables_initialize(glob); fclaw_clawpatch_vtable_initialize(glob, 4); - } + } void setup(){ fclaw_build_mode_t build_mode = FCLAW_BUILD_FOR_UPDATE; fclaw_patch_build(glob, &domain->blocks[0].patches[0], 0, 0, &build_mode); @@ -107,8 +107,8 @@ struct SinglePatchDomain { ~SinglePatchDomain(){ fclaw_patch_data_delete(glob, &domain->blocks[0].patches[0]); fclaw_clawpatch_options_destroy(opts); - fclaw_domain_destroy(domain); - //fclaw2d_map_destroy(map); + fclaw_domain_reset(glob); + fclaw_map_destroy(glob->cont); fclaw_global_destroy(glob); } }; @@ -167,8 +167,8 @@ struct OctDomain { fclaw_patch_data_delete(glob, &domain->blocks[0].patches[i]); } fclaw_clawpatch_options_destroy(opts); - fclaw_domain_destroy(domain); - //fclaw3d_map_destroy(map); + fclaw_domain_reset(glob); + fclaw_map_destroy(glob->cont); fclaw_global_destroy(glob); } }; @@ -243,6 +243,7 @@ TEST_CASE("3d fclaw_clawpatch_vtable_initialize") //ghost filling CHECK(patch_vt->copy_edge != NULL); + fclaw_clawpatch_options_destroy(opts); fclaw_domain_destroy(domain); fclaw_global_destroy(glob); } @@ -353,6 +354,7 @@ TEST_CASE("3d fclaw_clawpatch patch_build") } fclaw_patch_data_delete(glob, &domain->blocks[0].patches[0]); + fclaw_clawpatch_options_destroy(opts); fclaw_domain_destroy(domain); fclaw_map_destroy(map); fclaw_global_destroy(glob); diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3d.average.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3d.average.TEST.cpp index 1e18f54a8..2b2d05a2c 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3d.average.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3d.average.TEST.cpp @@ -67,6 +67,7 @@ struct CubeDomain { fopts.compute_error = true; fopts.subcycle = true; fopts.init_ghostcell = false; + fopts.regression_check = ""; fclaw_options_store(glob, &fopts); opts->mx = 5; @@ -88,15 +89,14 @@ struct CubeDomain { fclaw_vtables_initialize(glob); fclaw_clawpatch_vtable_initialize(glob, 4); - } + } void setup(){ fclaw_initialize(glob); } ~CubeDomain(){ - fclaw_clawpatch_options_destroy(opts); - //fclaw_domain_destroy(domain); - //fclaw3d_map_destroy(map); + fclaw_finalize(glob); fclaw_global_destroy(glob); + fclaw_clawpatch_options_destroy(opts); } }; diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp index ffd4d0a7b..1212ff7fc 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp @@ -74,6 +74,7 @@ struct TestData { fopts.compute_error = true; fopts.subcycle = true; fopts.init_ghostcell = false; + fopts.regression_check = ""; fclaw_options_store(glob, &fopts); opts->mx = 5; @@ -112,11 +113,9 @@ struct TestData { fclaw_initialize(glob); } ~TestData(){ - fclaw_clawpatch_options_destroy(opts); - fclaw_domain_reset(glob); - //fclaw_domain_destroy(glob->domain); - //fclaw3d_map_destroy(map); + fclaw_finalize(glob); fclaw_global_destroy(glob); + fclaw_clawpatch_options_destroy(opts); } }; @@ -519,7 +518,8 @@ TEST_CASE("3d clawpatch ghost fill on uniform cube") //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* map_out = fclaw_map_new_nomap(); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.opts->mx = mx+2*mbc; test_data_out.opts->my = my+2*mbc; @@ -614,12 +614,12 @@ TEST_CASE("3d clawpatch ghost fill on cube with refinement") CHECK_EQ(test_data.glob->domain->global_num_patches, 64); test_data.setup(); CHECK_EQ(test_data.glob->domain->global_num_patches, 127); - domain = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* map_out = fclaw_map_new_nomap(); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.opts->mx = mx+2*mbc; test_data_out.opts->my = my+2*mbc; @@ -725,7 +725,8 @@ TEST_CASE("3d clawpatch ghost fill on cube with refinement coarse interior") //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* map_out = fclaw_map_new_nomap(); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.opts->mx = mx+2*mbc; test_data_out.opts->my = my+2*mbc; @@ -786,7 +787,9 @@ TEST_CASE("3d clawpatch ghost fill on uniform brick") //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_3d_brick(sc_MPI_COMM_WORLD, mi, mj, mk, 0, 0, 0, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* brick_out = fclaw_map_new_3d_brick(domain_out, mi, mj, mk, 0, 0, 0); + fclaw_map_context_t* map_out = fclaw_map_new_nomap_brick(brick_out); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.fopts.mi = mi; test_data_out.fopts.mj = mj; @@ -882,12 +885,13 @@ TEST_CASE("3d clawpatch ghost fill on 2x2x2 brick with refinement on one block") CHECK_EQ(test_data.glob->domain->global_num_patches, (8*8)); test_data.setup(); CHECK_EQ(test_data.glob->domain->global_num_patches, (8*7 + 8*8)); - domain = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_3d_brick(sc_MPI_COMM_WORLD, 2, 2, 2, 0, 0, 0, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* brick_out = fclaw_map_new_3d_brick(domain_out, 2, 2, 2, 0, 0, 0); + fclaw_map_context_t* map_out = fclaw_map_new_nomap_brick(brick_out); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.fopts.mi = 2; test_data_out.fopts.mj = 2; @@ -992,12 +996,13 @@ TEST_CASE("3d clawpatch ghost fill on 2x2x2 brick with refinement on all but one CHECK_EQ(test_data.glob->domain->global_num_patches, 8*8); test_data.setup(); CHECK_EQ(test_data.glob->domain->global_num_patches, 8*1 + 8*8*7); - domain = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_3d_brick(sc_MPI_COMM_WORLD, 2, 2, 2, 0, 0, 0, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* brick_out = fclaw_map_new_3d_brick(domain_out, 2, 2, 2, 0, 0, 0); + fclaw_map_context_t* map_out = fclaw_map_new_nomap_brick(brick_out); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.fopts.mi = 2; test_data_out.fopts.mj = 2; @@ -1107,12 +1112,13 @@ TEST_CASE("3d clawpatch ghost fill on 2x2x2 brick with refinement coarse interio CHECK_EQ(test_data.glob->domain->global_num_patches, 8*8); test_data.setup(); CHECK_EQ(test_data.glob->domain->global_num_patches, 505); - domain = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_3d_brick(sc_MPI_COMM_WORLD, 2, 2, 2, 0, 0, 0, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* brick_out = fclaw_map_new_3d_brick(domain_out, 2, 2, 2, 0, 0, 0); + fclaw_map_context_t* map_out = fclaw_map_new_nomap_brick(brick_out); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.fopts.mi = 2; test_data_out.fopts.mj = 2; @@ -1222,12 +1228,13 @@ TEST_CASE("3d clawpatch ghost fill on 2x2x2 brick with refinement 2") CHECK_EQ(test_data.glob->domain->global_num_patches, 8*8); test_data.setup(); CHECK_EQ(test_data.glob->domain->global_num_patches, 113); - domain = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, minlevel); //create output domain with bigger size, so that we can see ghost cells //in the vtk output fclaw_domain_t* domain_out = fclaw_domain_new_3d_brick(sc_MPI_COMM_WORLD, 2, 2, 2, 0, 0, 0, minlevel); - TestData test_data_out(domain_out, map, minlevel, maxlevel); + fclaw_map_context_t* brick_out = fclaw_map_new_3d_brick(domain_out, 2, 2, 2, 0, 0, 0); + fclaw_map_context_t* map_out = fclaw_map_new_nomap_brick(brick_out); + TestData test_data_out(domain_out, map_out, minlevel, maxlevel); test_data_out.fopts.mi = 2; test_data_out.fopts.mj = 2; diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3d.interpolate.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3d.interpolate.TEST.cpp index a41629166..ffa679a18 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3d.interpolate.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3d.interpolate.TEST.cpp @@ -67,6 +67,7 @@ struct CubeDomain { fopts.compute_error = true; fopts.subcycle = true; fopts.init_ghostcell = false; + fopts.regression_check = ""; fclaw_options_store(glob, &fopts); opts->mx = 5; @@ -86,15 +87,14 @@ struct CubeDomain { fclaw_vtables_initialize(glob); fclaw_clawpatch_vtable_initialize(glob, 4); - } + } void setup(){ fclaw_initialize(glob); } ~CubeDomain(){ - fclaw_clawpatch_options_destroy(opts); - //fclaw_domain_destroy(domain); - //fclaw3d_map_destroy(map); + fclaw_finalize(glob); fclaw_global_destroy(glob); + fclaw_clawpatch_options_destroy(opts); } }; diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp index 99911f0bc..9717d31fd 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp @@ -240,6 +240,7 @@ TEST_CASE("3dx fclaw_clawpatch_vtable_initialize") CHECK(patch_vt->build_from_fine != NULL); CHECK(patch_vt->setup == NULL); + fclaw_clawpatch_options_destroy(opts); fclaw_domain_destroy(domain); fclaw_global_destroy(glob); } @@ -350,6 +351,7 @@ TEST_CASE("3dx fclaw_clawpatch patch_build") } fclaw_patch_data_delete(glob, &domain->blocks[0].patches[0]); + fclaw_clawpatch_options_destroy(opts); fclaw_domain_destroy(domain); fclaw_map_destroy(map); fclaw_global_destroy(glob); diff --git a/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp index ae80d663f..02d2831f2 100644 --- a/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp @@ -149,7 +149,7 @@ TEST_CASE("2d fclaw_clawpatch_options packing/unpacking") CHECK_EQ(output_opts->is_registered,opts->is_registered); vt->destroy(output_opts); - FCLAW_FREE(opts); + fclaw_clawpatch_options_destroy(opts); } TEST_CASE("3d fclaw_clawpatch_options packing/unpacking") @@ -196,5 +196,5 @@ TEST_CASE("3d fclaw_clawpatch_options packing/unpacking") CHECK_EQ(output_opts->is_registered,opts->is_registered); vt->destroy(output_opts); - FCLAW_FREE(opts); + fclaw_clawpatch_options_destroy(opts); } \ No newline at end of file diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp index 1e8c16617..80a03d452 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp @@ -45,8 +45,10 @@ TEST_CASE("fc2d_clawpack46_solver_initialize stores two seperate vtables in two fclaw_clawpatch_options_store(glob1, clawpatch_opts); fclaw_clawpatch_options_store(glob2, clawpatch_opts); - fc2d_clawpack46_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1)); - fc2d_clawpack46_options_store(glob2, FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1)); + fc2d_clawpack46_options_t *opts1 = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); + fc2d_clawpack46_options_t *opts2 = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); + fc2d_clawpack46_options_store(glob1, opts1); + fc2d_clawpack46_options_store(glob2, opts2); fclaw_vtables_initialize(glob1); fc2d_clawpack46_solver_initialize(glob1); @@ -59,6 +61,9 @@ TEST_CASE("fc2d_clawpack46_solver_initialize stores two seperate vtables in two fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + fclaw_clawpatch_options_destroy(clawpatch_opts); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); } TEST_CASE("fc2d_clawpack46_solver_initialize sets is_set flag") @@ -70,7 +75,9 @@ TEST_CASE("fc2d_clawpack46_solver_initialize sets is_set flag") /* create some empty options structures */ fclaw_clawpatch_options_t* clawpatch_opts = fclaw_clawpatch_options_new(2); fclaw_clawpatch_options_store(glob, clawpatch_opts); - fc2d_clawpack46_options_store(glob, FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1)); + + fc2d_clawpack46_options_t *opts = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); + fc2d_clawpack46_options_store(glob, opts); fclaw_vtables_initialize(glob); fc2d_clawpack46_solver_initialize(glob); @@ -80,6 +87,8 @@ TEST_CASE("fc2d_clawpack46_solver_initialize sets is_set flag") fclaw_domain_destroy(domain); fclaw_global_destroy(glob); + fclaw_clawpatch_options_destroy(clawpatch_opts); + FCLAW_FREE(opts); } #ifdef FCLAW_ENABLE_DEBUG @@ -130,6 +139,7 @@ TEST_CASE("fc2d_clawpack46_vtable_initialize fails if called twice on a glob") fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + fclaw_clawpatch_options_destroy(clawpatch_opts); } #endif \ No newline at end of file diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp index 4f7089554..06aba5569 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp @@ -36,15 +36,19 @@ TEST_CASE("fc2d_clawpack46_options can store options in two seperate globs") fc2d_clawpack46_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); fc2d_clawpack46_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); + fclaw_options_t* fopts2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); fc2d_clawpack46_options_store(glob1, opts1); /* glob1 has one package glob2 has two */ - fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); + fclaw_options_store(glob2, fopts2); fc2d_clawpack46_options_store(glob2, opts2); CHECK_EQ(fc2d_clawpack46_get_options(glob1), opts1); CHECK_EQ(fc2d_clawpack46_get_options(glob2), opts2); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); + FCLAW_FREE(fopts2); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); } diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp b/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp index 5af0d08fe..886a075ac 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp @@ -45,8 +45,10 @@ TEST_CASE("fc2d_clawpack5_solver_initialize stores two seperate vtables in two s fclaw_clawpatch_options_store(glob2, clawpatch_opts); /* create some empty options structures */ - fc2d_clawpack5_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1)); - fc2d_clawpack5_options_store(glob2, FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1)); + fc2d_clawpack5_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1); + fc2d_clawpack5_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1); + fc2d_clawpack5_options_store(glob1, opts1); + fc2d_clawpack5_options_store(glob2, opts2); fclaw_vtables_initialize(glob1); fc2d_clawpack5_solver_initialize(glob1); @@ -59,6 +61,9 @@ TEST_CASE("fc2d_clawpack5_solver_initialize stores two seperate vtables in two s fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); + fclaw_clawpatch_options_destroy(clawpatch_opts); } TEST_CASE("fc2d_clawpack5_solver_initialize sets is_set flag") @@ -72,7 +77,8 @@ TEST_CASE("fc2d_clawpack5_solver_initialize sets is_set flag") fclaw_clawpatch_options_store(glob, clawpatch_opts); /* create some empty options structures */ - fc2d_clawpack5_options_store(glob, FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1)); + fc2d_clawpack5_options_t* opts = FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1); + fc2d_clawpack5_options_store(glob, opts); fclaw_vtables_initialize(glob); fc2d_clawpack5_solver_initialize(glob); @@ -82,6 +88,8 @@ TEST_CASE("fc2d_clawpack5_solver_initialize sets is_set flag") fclaw_domain_destroy(domain); fclaw_global_destroy(glob); + FCLAW_FREE(opts); + fclaw_clawpatch_options_destroy(clawpatch_opts); } #ifdef FCLAW_ENABLE_DEBUG diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp index 2a644bfd2..4b7ae9904 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp @@ -39,7 +39,8 @@ TEST_CASE("fc2d_clawpack5_options can store options in two seperate globs") fc2d_clawpack5_options_store(glob1, opts1); /* glob1 has one package glob2 has two */ - fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); + fclaw_options_t* fopts2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fclaw_options_store(glob2, fopts2); fc2d_clawpack5_options_store(glob2, opts2); CHECK_EQ(fc2d_clawpack5_get_options(glob1), opts1); @@ -47,6 +48,9 @@ TEST_CASE("fc2d_clawpack5_options can store options in two seperate globs") fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); + FCLAW_FREE(fopts2); } #ifdef FCLAW_ENABLE_DEBUG diff --git a/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp b/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp index 528158efa..71bcf2462 100644 --- a/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp +++ b/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp @@ -46,11 +46,15 @@ TEST_CASE("fc2d_geoclaw_solver_initialize stores two seperate vtables in two sep fclaw_clawpatch_options_store(glob2, clawpatch_opt); /* create some empty options structures */ - fclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); - fc2d_geoclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1)); + fclaw_options_t *fclaw_opt1 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fc2d_geoclaw_options_t *geoclaw_opt1 = FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1); + fclaw_options_store(glob1, fclaw_opt1); + fc2d_geoclaw_options_store(glob1, geoclaw_opt1); - fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); - fc2d_geoclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1)); + fclaw_options_t *fclaw_opt2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fc2d_geoclaw_options_t *geoclaw_opt2 = FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1); + fclaw_options_store(glob2, fclaw_opt2); + fc2d_geoclaw_options_store(glob2, geoclaw_opt2); fclaw_vtables_initialize(glob1); fc2d_geoclaw_solver_initialize(glob1); @@ -63,6 +67,11 @@ TEST_CASE("fc2d_geoclaw_solver_initialize stores two seperate vtables in two sep fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(fclaw_opt1); + FCLAW_FREE(geoclaw_opt1); + FCLAW_FREE(fclaw_opt2); + FCLAW_FREE(geoclaw_opt2); + fclaw_clawpatch_options_destroy(clawpatch_opt); } TEST_CASE("fc2d_geoclaw_solver_initialize sets is_set flag") @@ -75,8 +84,10 @@ TEST_CASE("fc2d_geoclaw_solver_initialize sets is_set flag") fclaw_clawpatch_options_store(glob, clawpatch_opt); /* create some empty options structures */ - fclaw_options_store(glob, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); - fc2d_geoclaw_options_store(glob, FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1)); + fclaw_options_t *fclaw_opt = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fc2d_geoclaw_options_t *geoclaw_opt = FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1); + fclaw_options_store(glob, fclaw_opt); + fc2d_geoclaw_options_store(glob, geoclaw_opt); fclaw_vtables_initialize(glob); fc2d_geoclaw_solver_initialize(glob); @@ -86,6 +97,9 @@ TEST_CASE("fc2d_geoclaw_solver_initialize sets is_set flag") fclaw_domain_destroy(domain); fclaw_global_destroy(glob); + FCLAW_FREE(fclaw_opt); + FCLAW_FREE(geoclaw_opt); + fclaw_clawpatch_options_destroy(clawpatch_opt); } #ifdef FCLAW_ENABLE_DEBUG diff --git a/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp b/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp index b3bf37fb3..6ead6a5b6 100644 --- a/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp +++ b/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp @@ -38,7 +38,8 @@ TEST_CASE("fc2d_geoclaw_options can store options in two seperate globs") fc2d_geoclaw_options_store(glob1, opts1); /* glob1 has one package glob2 has two */ - fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); + fclaw_options_t* fopts2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fclaw_options_store(glob2, fopts2); fc2d_geoclaw_options_store(glob2, opts2); CHECK_EQ(fc2d_geoclaw_get_options(glob1), opts1); @@ -46,6 +47,9 @@ TEST_CASE("fc2d_geoclaw_options can store options in two seperate globs") fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); + FCLAW_FREE(fopts2); } #ifdef FCLAW_ENABLE_DEBUG diff --git a/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp b/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp index 68f5a199b..df026918b 100644 --- a/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp +++ b/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp @@ -54,6 +54,7 @@ TEST_CASE("fc2d_thunderegg_solver_initialize stores two seperate vtables in two fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + fclaw_clawpatch_options_destroy(clawpatch_opt); } TEST_CASE("fc2d_thunderegg_solver_initialize sets is_set flag") @@ -74,6 +75,7 @@ TEST_CASE("fc2d_thunderegg_solver_initialize sets is_set flag") fclaw_domain_destroy(domain); fclaw_global_destroy(glob); + fclaw_clawpatch_options_destroy(clawpatch_opt); } #ifdef FCLAW_ENABLE_DEBUG @@ -102,6 +104,7 @@ TEST_CASE("fc2d_thunderegg_vtable_initialize fails if called twice on a glob") fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + fclaw_clawpatch_options_destroy(clawpatch_opt); } #endif \ No newline at end of file diff --git a/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp b/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp index b4b83de88..df5dbb260 100644 --- a/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp +++ b/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp @@ -38,7 +38,8 @@ TEST_CASE("fc2d_thunderegg_options can store options in two seperate globs") fc2d_thunderegg_options_store(glob1, opts1); /* glob1 has one package glob2 has two */ - fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); + fclaw_options_t* fopts2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fclaw_options_store(glob2, fopts2); fc2d_thunderegg_options_store(glob2, opts2); CHECK_EQ(fc2d_thunderegg_get_options(glob1), opts1); @@ -46,6 +47,9 @@ TEST_CASE("fc2d_thunderegg_options can store options in two seperate globs") fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); + FCLAW_FREE(fopts2); } #ifdef FCLAW_ENABLE_DEBUG diff --git a/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp b/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp index afd2e2741..db481095b 100644 --- a/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp +++ b/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp @@ -43,12 +43,14 @@ TEST_CASE("fc3d_clawpack46_solver_initialize stores two seperate vtables in two fclaw_clawpatch_options_t* opts1 = fclaw_clawpatch_options_new(3); fclaw_clawpatch_options_t* opts2 = fclaw_clawpatch_options_new(3); + fc3d_clawpack46_options_t* clawpack_opts1 = FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1); + fc3d_clawpack46_options_t* clawpack_opts2 = FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1); /* create some empty options structures */ fclaw_clawpatch_options_store(glob1, opts1); - fc3d_clawpack46_options_store(glob1, FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1)); + fc3d_clawpack46_options_store(glob1, clawpack_opts1); fclaw_clawpatch_options_store(glob2, opts2); - fc3d_clawpack46_options_store(glob2, FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1)); + fc3d_clawpack46_options_store(glob2, clawpack_opts2); fclaw_vtables_initialize(glob1); fc3d_clawpack46_solver_initialize(glob1); @@ -63,6 +65,8 @@ TEST_CASE("fc3d_clawpack46_solver_initialize stores two seperate vtables in two fclaw_domain_destroy(domain); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(clawpack_opts1); + FCLAW_FREE(clawpack_opts2); } TEST_CASE("fc3d_clawpack46_solver_initialize sets is_set flag") @@ -72,10 +76,11 @@ TEST_CASE("fc3d_clawpack46_solver_initialize sets is_set flag") fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); + fc3d_clawpack46_options_t* clawpack_opts = FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1); /* create some empty options structures */ fclaw_clawpatch_options_store(glob, opts); - fc3d_clawpack46_options_store(glob, FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1)); + fc3d_clawpack46_options_store(glob, clawpack_opts); fclaw_vtables_initialize(glob); fc3d_clawpack46_solver_initialize(glob); @@ -86,6 +91,7 @@ TEST_CASE("fc3d_clawpack46_solver_initialize sets is_set flag") fclaw_clawpatch_options_destroy(opts); fclaw_domain_destroy(domain); fclaw_global_destroy(glob); + FCLAW_FREE(clawpack_opts); } #ifdef FCLAW_ENABLE_DEBUG diff --git a/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp b/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp index 2490f3f7f..30b9962ac 100644 --- a/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp +++ b/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp @@ -38,7 +38,8 @@ TEST_CASE("fc3d_clawpack46_options can store options in two seperate globs") fc3d_clawpack46_options_store(glob1, opts1); /* glob1 has one package glob2 has two */ - fclaw_options_store(glob2, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); + fclaw_options_t* fopts2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); + fclaw_options_store(glob2, fopts2); fc3d_clawpack46_options_store(glob2, opts2); CHECK_EQ(fc3d_clawpack46_get_options(glob1), opts1); @@ -46,6 +47,9 @@ TEST_CASE("fc3d_clawpack46_options can store options in two seperate globs") fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); + FCLAW_FREE(opts1); + FCLAW_FREE(opts2); + FCLAW_FREE(fopts2); } #ifdef FCLAW_ENABLE_DEBUG From 6fc46f8fbc47d9e49e92554b5ff8ba63756b732e Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 14:22:10 -0600 Subject: [PATCH 09/76] add vtable functions to glob --- src/fclaw_global.c | 19 ++++++++++++++++-- src/fclaw_global.h | 32 ++++++++++++++---------------- src/fclaw_global.h.TEST.cpp | 39 +++++++++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 7b10f320a..babe15c0c 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -296,13 +296,28 @@ fclaw_global_attribute_store (fclaw_global_t * glob, const char * packing_key, fclaw_pointer_map_value_destroy_t destroy) { - + fclaw_pointer_map_insert(glob->options, key, attribute, destroy); } void * fclaw_global_get_attribute (fclaw_global_t* glob, const char* key) { - return NULL; + return fclaw_pointer_map_get(glob->options, key); +} + +void +fclaw_global_vtable_store (fclaw_global_t * glob, + const char * key, + void * vtable, + fclaw_pointer_map_value_destroy_t destroy) +{ + fclaw_pointer_map_insert(glob->vtables, key, vtable, destroy); +} + +void * +fclaw_global_get_vtable (fclaw_global_t* glob, const char* key) +{ + return fclaw_pointer_map_get(glob->vtables, key); } void diff --git a/src/fclaw_global.h b/src/fclaw_global.h index adcfbf9a2..8f1f964d3 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -216,14 +216,14 @@ void* fclaw_global_get_options (fclaw_global_t* glob, const char* key); * @param glob the global context * @param key the key to store the attribute under * @param attribute the attribute structure - * @param packing_key the key to use for packing the attribute, NULL if not needed + * @param packing_vtable_key the key to the packing vtable, NULL if not needed * @param destroy the callback to destroy the attribute, NULL if not needed */ void fclaw_global_attribute_store (fclaw_global_t * glob, const char * key, void* attribute, - const char * packing_key, + const char * packing_vtable_key, fclaw_pointer_map_value_destroy_t destroy); /** @@ -231,37 +231,35 @@ fclaw_global_attribute_store (fclaw_global_t * glob, * * @param glob the global context * @param key the key to retrieve the attribute from - * @return void* the attribute + * @return void* the attribute, NULL if not found */ void * fclaw_global_get_attribute (fclaw_global_t* glob, const char* key); /** - * @brief Register a vtable used for packing attributes + * @brief Store a vtable * - * These should be done alongside the intialization of other vtables - * * @param glob the global context - * @param key the key, this should be the same key used in packing_key when storing attributes - * @param destroy the callback to destroy the vtable, NULL if not needed + * @param key the key * @param vtable the vtable + * @param destroy the callback to destroy the vtable, NULL if not needed */ void -fclaw_global_register_attribute_packing_vtable(fclaw_global_t * glob, - const char * key, - fclaw_packing_vtable_t * vtable, - fclaw_pointer_map_value_destroy_t destroy); +fclaw_global_vtable_store(fclaw_global_t * glob, + const char * key, + void * vtable, + fclaw_pointer_map_value_destroy_t destroy); /** - * @brief Get an attribute packing vtable + * @brief Get a vtable * * @param glob the global context - * @param key the key, this should be the same key used in packing_key when storing attributes - * @return fclaw_packing_vtable_t* the vtable + * @param key the key + * @return void* the vtable */ -fclaw_packing_vtable_t * -fclaw_global_get_attribute_packing_vtable(fclaw_global_t * glob, const char * key); +void * +fclaw_global_get_vtable(fclaw_global_t * glob, const char * key); /** * @brief Store a glob variable in static memory diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 7a52f73fb..21646d7f6 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -427,6 +427,41 @@ TEST_CASE("fclaw2d_global_get_global assert fails when NULL") CHECK_SC_ABORTED(fclaw_global_get_static_global()); } +TEST_CASE("fclaw_global_vtable_store and fclaw_global_get_vtable test") { + fclaw_global_t* glob = fclaw_global_new(); + + // Test with an integer + int vtable1 = 10; + const char* key1 = "vtable1"; + fclaw_global_vtable_store(glob, key1, &vtable1, nullptr); + + int* retrieved_vtable1 = static_cast(fclaw_global_get_vtable(glob, key1)); + CHECK_EQ(*retrieved_vtable1, vtable1); + + // Test with a string + const char* vtable2 = "Test string"; + const char* key2 = "vtable2"; + fclaw_global_vtable_store(glob, key2, &vtable2, nullptr); + + const char** retrieved_vtable2 = static_cast(fclaw_global_get_vtable(glob, key2)); + CHECK_EQ(*retrieved_vtable2, vtable2); + + // Test with a non-existing key + const char* key3 = "non-existing key"; + void* retrieved_vtable3 = fclaw_global_get_vtable(glob, key3); + CHECK_EQ(retrieved_vtable3, nullptr); + + // Test with a destroy callback + int* vtable4 = new int(20); + const char* key4 = "vtable4"; + fclaw_global_vtable_store(glob, key4, vtable4, [](void* ptr) { delete static_cast(ptr); }); + + int* retrieved_vtable4 = static_cast(fclaw_global_get_vtable(glob, key4)); + CHECK_EQ(*retrieved_vtable4, *vtable4); + + fclaw_global_destroy(glob); +} + TEST_CASE("fclaw_global_attribute_store and fclaw_global_get_attribute test") { fclaw_global_t* glob = fclaw_global_new(); @@ -446,10 +481,6 @@ TEST_CASE("fclaw_global_attribute_store and fclaw_global_get_attribute test") { const char** retrieved_attribute2 = static_cast(fclaw_global_get_attribute(glob, key2)); CHECK_EQ(*retrieved_attribute2, attribute2); -#ifdef FCLAW_ENABLE_DEBUG - // TEST inserting twice - CHECK_SC_ABORTED(fclaw_global_attribute_store(glob, key2, &attribute2, nullptr, nullptr)); -#endif // Test with a non-existing key const char* key3 = "non-existing key"; void* retrieved_attribute3 = fclaw_global_get_attribute(glob, key3); From 086636b988530b711f5cf0f95b7d452c7cba3f01 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 14:22:37 -0600 Subject: [PATCH 10/76] don't fail tests if memory leaks are known to occur --- test/test.cpp | 12 +++++++++++- test/test.hpp | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/test.cpp b/test/test.cpp index 53da703e6..45c664681 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -39,6 +39,12 @@ void fclaw_test_clear_expect_abort() expect_abort=false; } +static bool dirty_memory=false; +void fclaw_test_set_dirty_memory() +{ + dirty_memory = true; +} + std::jmp_buf& fclaw_test_get_jump_buffer() { return jump_buffer; @@ -95,7 +101,11 @@ int main(int argc, char *argv[]) result = context.run(); // global clean-up... - fclaw_app_destroy (app); + // fclaw_app_destory will fail if these has been an abort + if(!dirty_memory) + { + fclaw_app_destroy (app); + } return result; } diff --git a/test/test.hpp b/test/test.hpp index 08160f70b..20f6ad870 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -8,6 +8,8 @@ bool test_output_vtk(); void fclaw_test_expect_abort(); void fclaw_test_clear_expect_abort(); +void fclaw_test_set_dirty_memory(); + std::jmp_buf& fclaw_test_get_jump_buffer(); #define CHECK_SC_ABORTED(expr) \ @@ -17,6 +19,7 @@ std::jmp_buf& fclaw_test_get_jump_buffer(); if(!setjmp(fclaw_test_get_jump_buffer())){ \ expr; \ }else{ \ + fclaw_test_set_dirty_memory(); \ aborted=true; \ } \ CHECK_UNARY(aborted); \ From 4ce0bf7e1b7c467d3cdbff2709b5d6783019fe5f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 14:48:24 -0600 Subject: [PATCH 11/76] add attribute packing tests --- src/fclaw_global.h.TEST.cpp | 116 ++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 21646d7f6..0687a850b 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -107,12 +107,12 @@ TEST_CASE("fclaw2d_global_pack with no options") namespace { -struct dummy_options +struct dummy_attribute { size_t size; char value; - dummy_options(size_t size_in, char value_in) + dummy_attribute(size_t size_in, char value_in) :size(size_in),value(value_in) { //nothing to do @@ -121,7 +121,7 @@ struct dummy_options size_t pack_dummy_options(void* user, char* buffer) { - dummy_options* options = (dummy_options*) user; + dummy_attribute* options = (dummy_attribute*) user; char* buffer_start = buffer; buffer += fclaw_pack_size_t(options->size, buffer); @@ -145,32 +145,31 @@ size_t unpack_dummy_options(char* buffer, void** user) } buffer += size; - *user = new dummy_options(size,value); + *user = new dummy_attribute(size,value); return buffer-buffer_start; }; -size_t packsize_dummy_options(void* user) +size_t packsize_dummy_attribute(void* user) { - dummy_options* options = (dummy_options*) user; + dummy_attribute* options = (dummy_attribute*) user; return sizeof(size_t) + options->size; }; -void destroy_dummy_options(void* user){ - delete (dummy_options*) user; +void destroy_dummy_attribute(void* user){ + delete (dummy_attribute*) user; } fclaw_packing_vtable_t dummy_opts_vt = { pack_dummy_options, unpack_dummy_options, - packsize_dummy_options, - destroy_dummy_options + packsize_dummy_attribute, + destroy_dummy_attribute }; } -TEST_CASE("fclaw_global_pack with no options structure") +TEST_CASE("fclaw_global_pack with no attribute") { - for(double curr_time : {1.0, 1.2}) for(double curr_dt : {1.0, 1.2}) { @@ -196,32 +195,30 @@ TEST_CASE("fclaw_global_pack with no options structure") CHECK_EQ(glob1->curr_time, glob2->curr_time); CHECK_EQ(glob1->curr_dt, glob2->curr_dt); - REQUIRE_EQ(fclaw_pointer_map_size(glob2->options), 0); + REQUIRE_EQ(fclaw_pointer_map_size(glob2->attributes), 0); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); } } -#if 0 -TEST_CASE("fclaw_global_pack with a single options structure") +TEST_CASE("fclaw_global_pack with a single attribute") { + for(bool already_stored_attribute : {true, false}) for(double curr_time : {1.0, 1.2}) for(double curr_dt : {1.0, 1.2}) { char dummy[] = "dummy1"; std::vector args = {dummy}; - char ** argv = args.data(); - int argc = 1; //fclaw_app_t* app = fclaw_app_new_on_comm(sc_MPI_COMM_WORLD,&argc,&argv,NULL); fclaw_global_t* glob1; glob1 = fclaw_global_new(); glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; - dummy_options* options1 = new dummy_options(20, 'a'); - fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy1", options1, destroy_dummy_options); + dummy_attribute* attribute1 = new dummy_attribute(20, 'a'); + fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); + fclaw_global_attribute_store(glob1, "dummy1", attribute1, "dummy1", destroy_dummy_attribute); size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -233,8 +230,11 @@ TEST_CASE("fclaw_global_pack with a single options structure") REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2 = fclaw_global_new(); - dummy_options* options2 = new dummy_options(99, 'z'); - fclaw_pointer_map_insert(glob2->options, "dummy1", options2, destroy_dummy_options); + dummy_attribute* attribute2 = new dummy_attribute(99, 'z'); + if(already_stored_attribute) + { + fclaw_global_attribute_store(glob2, "dummy1", attribute2, "dummy1", destroy_dummy_attribute); + } size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -242,18 +242,20 @@ TEST_CASE("fclaw_global_pack with a single options structure") CHECK_EQ(glob1->curr_time, glob2->curr_time); CHECK_EQ(glob1->curr_dt, glob2->curr_dt); - REQUIRE_EQ(fclaw_pointer_map_size(glob2->options), 1); + REQUIRE_EQ(fclaw_pointer_map_size(glob2->attributes), 1); - CHECK_EQ(options2->size, options1->size); - CHECK_EQ(options2->value, options1->value); + CHECK_EQ(attribute2->size, attribute1->size); + CHECK_EQ(attribute2->value, attribute1->value); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); } } -TEST_CASE("fclaw_global_pack with two options structure") +TEST_CASE("fclaw_global_pack with two attribute structures") { + for(bool already_stored_attribute_1 : {true, false}) + for(bool already_stored_attribute_2 : {true, false}) for(double curr_time : {1.0, 1.2}) for(double curr_dt : {1.0, 1.2}) { @@ -262,12 +264,13 @@ TEST_CASE("fclaw_global_pack with two options structure") glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; - dummy_options* options1_1 = new dummy_options(20, 'a'); - dummy_options* options1_2 = new dummy_options(40, 'b'); - fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy1", options1_1, destroy_dummy_options); - fclaw_app_register_options_packing_vtable("dummy2", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy2", options1_2, destroy_dummy_options); + dummy_attribute* attribute1_1 = new dummy_attribute(20, 'a'); + dummy_attribute* attribute1_2 = new dummy_attribute(40, 'b'); + + fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); + fclaw_global_attribute_store(glob1, "dummy1", attribute1_1, "dummy1", destroy_dummy_attribute); + fclaw_global_vtable_store(glob1, "dummy2", &dummy_opts_vt, NULL); + fclaw_global_attribute_store(glob1, "dummy2", attribute1_2, "dummy2", destroy_dummy_attribute); size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -279,10 +282,20 @@ TEST_CASE("fclaw_global_pack with two options structure") REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2 = fclaw_global_new(); - dummy_options* options2_1 = new dummy_options(99, 'z'); - dummy_options* options2_2 = new dummy_options(99, 'z'); - fclaw_pointer_map_insert(glob2->options, "dummy1", options2_1, destroy_dummy_options); - fclaw_pointer_map_insert(glob2->options, "dummy2", options2_2, destroy_dummy_options); + dummy_attribute* attribute2_1 = new dummy_attribute(99, 'z'); + dummy_attribute* attribute2_2 = new dummy_attribute(99, 'z'); + + fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); + if(already_stored_attribute_1) + { + fclaw_global_attribute_store(glob2, "dummy1", attribute2_1, "dummy1", destroy_dummy_attribute); + } + fclaw_global_vtable_store(glob1, "dummy2", &dummy_opts_vt, NULL); + if(already_stored_attribute_2) + { + fclaw_global_attribute_store(glob2, "dummy2", attribute2_2, "dummy2", destroy_dummy_attribute); + } + size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -290,13 +303,13 @@ TEST_CASE("fclaw_global_pack with two options structure") CHECK_EQ(glob1->curr_time, glob2->curr_time); CHECK_EQ(glob1->curr_dt, glob2->curr_dt); - REQUIRE_EQ(fclaw_pointer_map_size(glob2->options), 2); + REQUIRE_EQ(fclaw_pointer_map_size(glob2->attributes), 2); - CHECK_EQ(options2_1->size, options1_1->size); - CHECK_EQ(options2_1->value, options1_1->value); + CHECK_EQ(attribute2_1->size, attribute1_1->size); + CHECK_EQ(attribute2_1->value, attribute1_1->value); - CHECK_EQ(options2_2->size, options1_2->size); - CHECK_EQ(options2_2->value, options1_2->value); + CHECK_EQ(attribute2_2->size, attribute1_2->size); + CHECK_EQ(attribute2_2->value, attribute1_2->value); fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); @@ -309,8 +322,8 @@ TEST_CASE("fclaw_global_pack aborts with unregistered vtable") glob1->curr_time = 100; glob1->curr_dt = 200; - dummy_options* options = new dummy_options(20, 'a'); - fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); + dummy_attribute* attribute = new dummy_attribute(20, 'a'); + fclaw_global_attribute_store(glob1, "dummy1", attribute, "pack_dummy1", destroy_dummy_attribute); char buffer[100]; CHECK_SC_ABORTED(fclaw_global_pack(glob1, buffer)); @@ -322,8 +335,8 @@ TEST_CASE("fclaw2d_global_packsize aborts with unregistered vtable") glob1->curr_time = 100; glob1->curr_dt = 200; - dummy_options* options = new dummy_options(20, 'a'); - fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); + dummy_attribute* attribute = new dummy_attribute(20, 'a'); + fclaw_global_attribute_store(glob1, "dummy1", attribute, "pack_dummy1", destroy_dummy_attribute); CHECK_SC_ABORTED(fclaw_global_packsize(glob1)); } @@ -334,9 +347,9 @@ TEST_CASE("fclaw_global_unppack aborts with unregistered vtable") glob1->curr_time = 1; glob1->curr_dt = 1; - dummy_options* options = new dummy_options(20, 'a'); - fclaw_app_register_options_packing_vtable("dummy1", &dummy_opts_vt); - fclaw_pointer_map_insert(glob1->options, "dummy1", options, destroy_dummy_options); + dummy_attribute* attribute = new dummy_attribute(20, 'a'); + fclaw_global_vtable_store(glob1, "pack_dummy1", &dummy_opts_vt, NULL); + fclaw_global_attribute_store(glob1, "dummy1", attribute, "pack_dummy1", destroy_dummy_attribute); size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -348,10 +361,10 @@ TEST_CASE("fclaw_global_unppack aborts with unregistered vtable") REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2=fclaw_global_new(); - fclaw_app_register_options_packing_vtable("dummy1", nullptr); + //no vtables in glob2 CHECK_SC_ABORTED(fclaw_global_unpack(buffer, glob2)); } -#endif + TEST_CASE("fclaw_global_options_store and fclaw_global_get_options test") { fclaw_global_t* glob = fclaw_global_new(); @@ -427,6 +440,8 @@ TEST_CASE("fclaw2d_global_get_global assert fails when NULL") CHECK_SC_ABORTED(fclaw_global_get_static_global()); } +#endif + TEST_CASE("fclaw_global_vtable_store and fclaw_global_get_vtable test") { fclaw_global_t* glob = fclaw_global_new(); @@ -497,4 +512,3 @@ TEST_CASE("fclaw_global_attribute_store and fclaw_global_get_attribute test") { fclaw_global_destroy(glob); } -#endif From 34555eb43bfc835131a3d04861b929d6ec666ec7 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 15:04:34 -0600 Subject: [PATCH 12/76] update packing vtable, remove options packing code --- .../advection/2d/swirl/swirl_options.c | 41 ---- src/fclaw_global.h.TEST.cpp | 11 +- src/fclaw_options.c | 113 ---------- src/fclaw_options.h | 7 - src/fclaw_options.h.TEST.cpp | 211 ------------------ src/fclaw_packing.h | 10 +- .../clawpatch/fclaw_clawpatch_options.c | 55 ----- .../clawpatch/fclaw_clawpatch_options.h | 8 - .../fclaw_clawpatch_options.h.TEST.cpp | 93 +------- .../fc2d_clawpack46_options.c | 100 --------- .../fc2d_clawpack46_options.h | 7 - .../fc2d_clawpack46_options.h.TEST.cpp | 76 ------- .../fc2d_clawpack5/fc2d_clawpack5_options.c | 101 --------- .../fc2d_clawpack5/fc2d_clawpack5_options.h | 7 - .../fc2d_clawpack5_options.h.TEST.cpp | 76 ------- 15 files changed, 17 insertions(+), 899 deletions(-) diff --git a/applications/clawpack/advection/2d/swirl/swirl_options.c b/applications/clawpack/advection/2d/swirl/swirl_options.c index cecb029c8..f5037052c 100644 --- a/applications/clawpack/advection/2d/swirl/swirl_options.c +++ b/applications/clawpack/advection/2d/swirl/swirl_options.c @@ -65,45 +65,6 @@ swirl_destroy(user_options_t *user) FCLAW_FREE (user); } -static void -swirl_destroy_void(void *user) -{ - swirl_destroy((user_options_t*) user); -} - -static size_t -options_packsize(void* user) -{ - return sizeof(user_options_t); -} - -static size_t -options_pack(void* user, char* buffer) -{ - user_options_t* opts = (user_options_t*) user; - - //pack entire struct - return FCLAW_PACK(*opts, buffer); -} - -static size_t -options_unpack(char* buffer, void** user) -{ - user_options_t** opts_ptr = (user_options_t**) user; - - *opts_ptr = FCLAW_ALLOC(user_options_t,1); - - return FCLAW_UNPACK(buffer, *opts_ptr); -} - -static fclaw_packing_vtable_t packing_vt = -{ - options_pack, - options_unpack, - options_packsize, - swirl_destroy_void -}; - /* ------- Generic option handling routines that call above routines ----- */ static void* options_register (fclaw_app_t * app, void *package, sc_options_t * opt) @@ -189,8 +150,6 @@ user_options_t* swirl_options_register (fclaw_app_t * app, fclaw_app_set_attribute(app,"user",user); - fclaw_app_register_options_packing_vtable("user", &packing_vt); - return user; } diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 0687a850b..41ab8f578 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -132,8 +132,9 @@ size_t pack_dummy_options(void* user, char* buffer) return buffer-buffer_start; }; -size_t unpack_dummy_options(char* buffer, void** user) +size_t unpack_dummy_options(char* buffer, void* user) { + dummy_attribute* attribute = (dummy_attribute*) user; char* buffer_start = buffer; @@ -145,7 +146,8 @@ size_t unpack_dummy_options(char* buffer, void** user) } buffer += size; - *user = new dummy_attribute(size,value); + attribute->size = size; + attribute->value = value; return buffer-buffer_start; }; @@ -154,7 +156,9 @@ size_t packsize_dummy_attribute(void* user) dummy_attribute* options = (dummy_attribute*) user; return sizeof(size_t) + options->size; }; - +void * new_dummy_attribute(){ + return new dummy_attribute(0,0); +} void destroy_dummy_attribute(void* user){ delete (dummy_attribute*) user; } @@ -164,6 +168,7 @@ fclaw_packing_vtable_t dummy_opts_vt = pack_dummy_options, unpack_dummy_options, packsize_dummy_attribute, + new_dummy_attribute, destroy_dummy_attribute }; diff --git a/src/fclaw_options.c b/src/fclaw_options.c index d628fb83f..da3b976f8 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -454,116 +454,6 @@ fclaw_options_destroy(fclaw_options_t* fclaw_opt) FCLAW_FREE(fclaw_opt); } -static void -fclaw_options_destroy_void(void* user) -{ - fclaw_options_t* fclaw_opt = (fclaw_options_t*) user; - fclaw_options_destroy(fclaw_opt); -} - -/* ------------------------------------------------------------------------ - Options packing - ------------------------------------------------------------------------ */ - -static size_t options_packsize(void* user){ - fclaw_options_t* opts = (fclaw_options_t*) user; - - size_t size = sizeof(fclaw_options_t); - size += fclaw_packsize_string(opts->run_directory); - size += fclaw_packsize_string(opts->scale_string); - size += fclaw_packsize_string(opts->shift_string); - size += 3*sizeof(double); //scale - size += 3*sizeof(double); //shift - size += fclaw_packsize_string(opts->tikz_figsize_string); - size += 2*sizeof(double); //tickz_figsize - size += fclaw_packsize_string(opts->tikz_plot_prefix); - size += fclaw_packsize_string(opts->tikz_plot_suffix); - size += fclaw_packsize_string(opts->prefix); - size += fclaw_packsize_string(opts->logging_prefix); - - return size; -} - -static size_t options_pack(void* user, char* buffer){ - char* buffer_start = buffer; - - fclaw_options_t* opts = (fclaw_options_t*) user; - - //pack entire struct - buffer += FCLAW_PACK(*opts, buffer); - - //append arrays to buffer - buffer += fclaw_pack_string(opts->run_directory, buffer); - buffer += fclaw_pack_string(opts->scale_string, buffer); - buffer += fclaw_pack_string(opts->shift_string, buffer); - for(size_t i = 0; i < 3; i++){ - buffer += fclaw_pack_double(opts->scale[i], buffer); - buffer += fclaw_pack_double(opts->shift[i], buffer); - } - buffer += fclaw_pack_string(opts->tikz_figsize_string, buffer); - buffer += fclaw_pack_double(opts->tikz_figsize[0], buffer); - buffer += fclaw_pack_double(opts->tikz_figsize[1], buffer); - buffer += fclaw_pack_string(opts->tikz_plot_prefix, buffer); - buffer += fclaw_pack_string(opts->tikz_plot_suffix, buffer); - buffer += fclaw_pack_string(opts->prefix, buffer); - buffer += fclaw_pack_string(opts->logging_prefix, buffer); - - return buffer-buffer_start; -} - -static size_t options_unpack(char* buffer, void** user){ - char* buffer_start = buffer; - - fclaw_options_t** opts_ptr = (fclaw_options_t**) user; - *opts_ptr = FCLAW_ALLOC(fclaw_options_t,1); - fclaw_options_t* opts = *opts_ptr; - - buffer += FCLAW_UNPACK(buffer, opts); - - buffer += fclaw_unpack_string(buffer, (char **) &opts->run_directory); - buffer += fclaw_unpack_string(buffer, (char **) &opts->scale_string); - buffer += fclaw_unpack_string(buffer, (char **) &opts->shift_string); - opts->scale = FCLAW_ALLOC(double,3); - opts->shift = FCLAW_ALLOC(double,3); - for(size_t i = 0; i < 3; i++){ - buffer += fclaw_unpack_double(buffer, &opts->scale[i]); - buffer += fclaw_unpack_double(buffer, &opts->shift[i]); - } - buffer += fclaw_unpack_string(buffer, (char **) &opts->tikz_figsize_string); - opts->tikz_figsize = FCLAW_ALLOC(double,2); - buffer += fclaw_unpack_double(buffer, &opts->tikz_figsize[0]); - buffer += fclaw_unpack_double(buffer, &opts->tikz_figsize[1]); - buffer += fclaw_unpack_string(buffer, (char **) &opts->tikz_plot_prefix); - buffer += fclaw_unpack_string(buffer, (char **) &opts->tikz_plot_suffix); - buffer += fclaw_unpack_string(buffer, (char **) &opts->prefix); - buffer += fclaw_unpack_string(buffer, (char **) &opts->logging_prefix); - - sc_keyvalue_t *kv = opts->kv_timing_verbosity = sc_keyvalue_new (); - sc_keyvalue_set_int (kv, "wall", FCLAW_TIMER_PRIORITY_WALL); - sc_keyvalue_set_int (kv, "summary", FCLAW_TIMER_PRIORITY_SUMMARY); - sc_keyvalue_set_int (kv, "exclusive", FCLAW_TIMER_PRIORITY_EXCLUSIVE); - sc_keyvalue_set_int (kv, "counters", FCLAW_TIMER_PRIORITY_COUNTERS); - sc_keyvalue_set_int (kv, "details", FCLAW_TIMER_PRIORITY_DETAILS); - sc_keyvalue_set_int (kv, "extra", FCLAW_TIMER_PRIORITY_EXTRA); - sc_keyvalue_set_int (kv, "all", FCLAW_TIMER_PRIORITY_EXTRA); - - opts->is_unpacked = 1; - - return buffer-buffer_start; -} - -static fclaw_packing_vtable_t packing_vt = -{ - options_pack, - options_unpack, - options_packsize, - fclaw_options_destroy_void -}; - -const fclaw_packing_vtable_t* fclaw_options_get_packing_vtable(){ - return &packing_vt; -} - /* ------------------------------------------------------------------------ Generic functions - these call the functions above ------------------------------------------------------------------------ */ @@ -661,9 +551,6 @@ fclaw_options_t* fclaw_options_register (fclaw_app_t * a, &options_vtable, fclaw_opt); - /* register packing vtable */ - fclaw_app_register_options_packing_vtable("fclaw2d", &packing_vt); - return fclaw_opt; } diff --git a/src/fclaw_options.h b/src/fclaw_options.h index 2c7b907f6..35c004476 100644 --- a/src/fclaw_options.h +++ b/src/fclaw_options.h @@ -54,13 +54,6 @@ fclaw_options_t* fclaw_options_register (fclaw_app_t * a, const char *section, const char *configfile); -/** - * @brief Get the packing vtable for the options - * - * @return const fclaw_packing_vtable_t* the vtable - */ -const fclaw_packing_vtable_t* fclaw_options_get_packing_vtable(); - /* These can be called from external routines (in torthem, for example?) */ fclaw_exit_type_t fclaw_options_postprocess (fclaw_options_t * fclaw_opt); diff --git a/src/fclaw_options.h.TEST.cpp b/src/fclaw_options.h.TEST.cpp index f0b67fbf4..d33dfe701 100644 --- a/src/fclaw_options.h.TEST.cpp +++ b/src/fclaw_options.h.TEST.cpp @@ -82,216 +82,5 @@ TEST_CASE("fclaw_options_store fails if called twice on a glob") fclaw_global_destroy(glob1); fclaw_global_destroy(glob2); } -TEST_CASE("fclaw_options packing/unpacking") -{ - fclaw_options_t* opts = FCLAW_ALLOC_ZERO(fclaw_options_t,1); - opts->dim = 3; - opts->run_directory = "test"; - opts->initial_dt = 0.1; - opts->tfinal = 1.0; - opts->outstyle = 1; - opts->nout = 10; - opts->nstep = 100; - opts->subcycle = 0; - opts->use_fixed_dt = 1; - opts->max_cfl = .2; - opts->desired_cfl = .3; - opts->reduce_cfl = 0; -// double tout[] = {0.5,0.6,0.7,0.8,0.9}; -// opts->tout = tout; - opts->refratio = 2; - opts->minlevel = 4; - opts->maxlevel = 3; - opts->regrid_interval = 5; - opts->smooth_refine = 2; - opts->refine_threshold = 3.0; - opts->time_sync = 0; - opts->output_gauges = 1; - opts->gauge_buffer_length = 300; - opts->output_rays = 2; - opts->manifold = 2; - opts->mi = 3; - opts->mj = 4; - opts->periodic_x = 0; - opts->periodic_y = 1; - opts->flux_correction = 1; - opts->fluctuation_correction = 2; - opts->coarsen_delay = 3; - opts->init_ghostcell = 0; - opts->advance_one_step = 1; - opts->outstyle_uses_maxlevel = 2; - opts->timeinterp2fillghost = 3; - opts->scale_string = "blah"; - double scale[3] = {1.0,2.0,3.0}; - opts->scale = scale; - opts->shift_string = "jbkal"; - double shift[3] = {4.0,5.0,6.0}; - opts->shift = shift; - opts->phi = 3.5; - opts->ax = 3.98; - opts->bx = 32.38; - opts->ay = 32.90; - opts->by = 32.90; - opts->az = 104.9; - opts->bz = 3290.9023; - opts->run_user_diagnostics = 1; - opts->compute_error = 2; - opts->conservation_check = 3; - opts->trapfpe = 3; - opts->report_timing = 3; - opts->report_timing_verbosity = 3; - opts->mpi_debug = 2; - opts->ghost_patch_pack_area = 3; - opts->ghost_patch_pack_extra = 4; - opts->ghost_patch_pack_numextrafields=3298; - opts->verbosity = 3; - opts->output = 3; - opts->tikz_out = 3; - opts->tikz_figsize_string ="jdfajfda"; - double figsize[2] = {3.0,4.0}; - opts->tikz_figsize = figsize; - opts->tikz_plot_fig = 3; - opts->tikz_plot_prefix = "plot2jk"; - opts->tikz_plot_suffix = "plot3jk"; - opts->tikz_mesh_only= 0; - opts->prefix = "jdsjkl"; - opts->vtkspace = 0.328; - opts->weighted_partition = 0; - opts->is_registered = 1; - opts->logging_prefix = "werqreqw"; - opts->is_unpacked = false; - - const fclaw_packing_vtable_t* vt = fclaw_options_get_packing_vtable(); - - size_t size = vt->size(opts); - char buffer[size]; - size_t bytes_written = vt->pack(opts,buffer); - REQUIRE_EQ(bytes_written,size); - - fclaw_options_t* output_opts = nullptr; - size_t bytes_read = vt->unpack(buffer,(void**)&output_opts); - - REQUIRE_EQ(bytes_read,size); - REQUIRE_NE(output_opts,nullptr); - - CHECK_EQ(opts->dim , output_opts->dim); - - CHECK_NE(opts->run_directory , output_opts->run_directory); - CHECK_UNARY(!strcmp(opts->run_directory, output_opts->run_directory)); - - CHECK_EQ(opts->initial_dt , output_opts->initial_dt); - CHECK_EQ(opts->tfinal , output_opts->tfinal); - CHECK_EQ(opts->outstyle , output_opts->outstyle); - CHECK_EQ(opts->nout , output_opts->nout); - CHECK_EQ(opts->nstep , output_opts->nstep); - CHECK_EQ(opts->subcycle , output_opts->subcycle); - CHECK_EQ(opts->use_fixed_dt , output_opts->use_fixed_dt); - CHECK_EQ(opts->max_cfl , output_opts->max_cfl); - CHECK_EQ(opts->desired_cfl , output_opts->desired_cfl ); - CHECK_EQ(opts->reduce_cfl , output_opts->reduce_cfl); - -// CHECK_NE(opts->tout , output_opts->tout); -// for(int i = 0; i < 5; i++) -// { -// CHECK_EQ(opts->tout[i],output_opts->tout[i]); -// } - - CHECK_EQ(opts->refratio , output_opts->refratio); - CHECK_EQ(opts->minlevel , output_opts->minlevel); - CHECK_EQ(opts->maxlevel , output_opts->maxlevel); - CHECK_EQ(opts->regrid_interval , output_opts->regrid_interval); - CHECK_EQ(opts->smooth_refine , output_opts->smooth_refine); - CHECK_EQ(opts->refine_threshold , output_opts->refine_threshold); - CHECK_EQ(opts->time_sync , output_opts->time_sync); - CHECK_EQ(opts->output_gauges , output_opts->output_gauges); - CHECK_EQ(opts->gauge_buffer_length , output_opts->gauge_buffer_length); - CHECK_EQ(opts->output_rays , output_opts->output_rays); - CHECK_EQ(opts->manifold , output_opts->manifold); - CHECK_EQ(opts->mi , output_opts->mi); - CHECK_EQ(opts->mj , output_opts->mj); - CHECK_EQ(opts->periodic_x , output_opts->periodic_x); - CHECK_EQ(opts->periodic_y , output_opts->periodic_y); - CHECK_EQ(opts->flux_correction , output_opts->flux_correction); - CHECK_EQ(opts->fluctuation_correction , output_opts->fluctuation_correction); - CHECK_EQ(opts->coarsen_delay , output_opts->coarsen_delay); - CHECK_EQ(opts->init_ghostcell , output_opts->init_ghostcell); - CHECK_EQ(opts->advance_one_step , output_opts->advance_one_step); - CHECK_EQ(opts->outstyle_uses_maxlevel , output_opts->outstyle_uses_maxlevel); - CHECK_EQ(opts->timeinterp2fillghost , output_opts->timeinterp2fillghost); - - CHECK_NE(opts->scale_string , output_opts->scale_string); - CHECK_UNARY(!strcmp(opts->scale_string, output_opts->scale_string)); - - CHECK_NE(opts->scale , output_opts->scale); - for(int i = 0; i < 3; i++) - { - CHECK_EQ(opts->scale[i],output_opts->scale[i]); - } - - CHECK_NE(opts->shift_string , output_opts->shift_string); - CHECK_UNARY(!strcmp(opts->shift_string, output_opts->shift_string)); - - CHECK_NE(opts->shift , output_opts->shift); - for(int i = 0; i < 3; i++) - { - CHECK_EQ(opts->shift[i],output_opts->shift[i]); - } - - CHECK_EQ(opts->phi , output_opts->phi); - CHECK_EQ(opts->ax , output_opts->ax); - CHECK_EQ(opts->bx , output_opts->bx); - CHECK_EQ(opts->ay , output_opts->ay); - CHECK_EQ(opts->by , output_opts->by); - CHECK_EQ(opts->az , output_opts->az); - CHECK_EQ(opts->bz , output_opts->bz); - CHECK_EQ(opts->run_user_diagnostics , output_opts->run_user_diagnostics); - CHECK_EQ(opts->compute_error , output_opts->compute_error); - CHECK_EQ(opts->conservation_check , output_opts->conservation_check); - CHECK_EQ(opts->trapfpe , output_opts->trapfpe); - CHECK_EQ(opts->report_timing , output_opts->report_timing); - CHECK_EQ(opts->report_timing_verbosity , output_opts->report_timing_verbosity); - CHECK_EQ(opts->mpi_debug , output_opts->mpi_debug); - CHECK_EQ(opts->ghost_patch_pack_area , output_opts->ghost_patch_pack_area); - CHECK_EQ(opts->ghost_patch_pack_extra , output_opts->ghost_patch_pack_extra); - CHECK_EQ(opts->ghost_patch_pack_numextrafields , output_opts->ghost_patch_pack_numextrafields); - CHECK_EQ(opts->verbosity , output_opts->verbosity); - CHECK_EQ(opts->output , output_opts->output); - CHECK_EQ(opts->tikz_out , output_opts->tikz_out); - - CHECK_NE(opts->tikz_figsize_string , output_opts->tikz_figsize_string); - CHECK_UNARY(!strcmp(opts->tikz_figsize_string, output_opts->tikz_figsize_string)); - - CHECK_NE(opts->tikz_figsize , output_opts->tikz_figsize); - for(int i = 0; i < 2; i++) - { - CHECK_EQ(opts->tikz_figsize[i],output_opts->tikz_figsize[i]); - } - - CHECK_EQ(opts->tikz_plot_fig , output_opts->tikz_plot_fig); - - CHECK_NE(opts->tikz_plot_prefix , output_opts->tikz_plot_prefix); - CHECK_UNARY(!strcmp(opts->tikz_plot_prefix, output_opts->tikz_plot_prefix)); - - CHECK_NE(opts->tikz_plot_suffix , output_opts->tikz_plot_suffix); - CHECK_UNARY(!strcmp(opts->tikz_plot_suffix, output_opts->tikz_plot_suffix)); - - CHECK_EQ(opts->tikz_mesh_only , output_opts->tikz_mesh_only); - - CHECK_NE(opts->prefix , output_opts->prefix); - CHECK_UNARY(!strcmp(opts->prefix, output_opts->prefix)); - - CHECK_EQ(opts->vtkspace , output_opts->vtkspace); - CHECK_EQ(opts->weighted_partition , output_opts->weighted_partition); - CHECK_EQ(opts->is_registered , output_opts->is_registered); - - CHECK_NE(opts->logging_prefix , output_opts->logging_prefix); - CHECK_UNARY(!strcmp(opts->logging_prefix, output_opts->logging_prefix)); - - CHECK_UNARY(output_opts->is_unpacked); - - vt->destroy(output_opts); - - FCLAW_FREE(opts); -} #endif \ No newline at end of file diff --git a/src/fclaw_packing.h b/src/fclaw_packing.h index 31f56372f..18c61f2a2 100644 --- a/src/fclaw_packing.h +++ b/src/fclaw_packing.h @@ -58,15 +58,20 @@ typedef size_t (*fclaw_packing_pack_t)(void* userdata, /** * @brief Unpack userdata from buffer * @param buffer buffer to unpack from - * @return newly create userdata + * @return user data to write to */ -typedef size_t (*fclaw_packing_unpack_t)(char* buffer,void**); +typedef size_t (*fclaw_packing_unpack_t)(char* buffer,void*); /** * @brief Get the size needed to pack userdata * @return the size */ typedef size_t (*fclaw_packing_packsize_t)(void* userdata); +/** + * @brief create new userdata + */ +typedef void * (*fclaw_packing_new_t)(); + /** * @brief destroy userdata */ @@ -80,6 +85,7 @@ typedef struct fclaw_packing_vtable fclaw_packing_pack_t pack; /**< function for packing */ fclaw_packing_unpack_t unpack; /**< function for unpacking*/ fclaw_packing_packsize_t size; /**< function for packing size */ + fclaw_packing_new_t new_data; /**< function for creating new data */ fclaw_packing_destroy_t destroy; /**< function for destroying */ } fclaw_useradata_vtable_t; diff --git a/src/patches/clawpatch/fclaw_clawpatch_options.c b/src/patches/clawpatch/fclaw_clawpatch_options.c index 1c027c67d..2953e5e6d 100644 --- a/src/patches/clawpatch/fclaw_clawpatch_options.c +++ b/src/patches/clawpatch/fclaw_clawpatch_options.c @@ -184,59 +184,6 @@ fclaw_clawpatch_options_destroy (fclaw_clawpatch_options_t *clawpatch_opt) FCLAW_FREE(clawpatch_opt); } -static void -clawpatch_destroy_void(void *clawpatch_opt) -{ - fclaw_clawpatch_options_destroy ((fclaw_clawpatch_options_t *) clawpatch_opt); -} - -static size_t -options_packsize(void* user) -{ - return sizeof(fclaw_clawpatch_options_t); -} - -static size_t -options_pack(void* user, char* buffer) -{ - char* buffer_start = buffer; - fclaw_clawpatch_options_t* opts = (fclaw_clawpatch_options_t*) user; - - //pack entire struct - buffer += FCLAW_PACK(*opts,buffer); - - return buffer - buffer_start; -} - -static size_t -options_unpack(char* buffer, void** user) -{ - char* buffer_start = buffer; - fclaw_clawpatch_options_t** opts_ptr = (fclaw_clawpatch_options_t**) user; - - *opts_ptr = FCLAW_ALLOC(fclaw_clawpatch_options_t,1); - - buffer += FCLAW_UNPACK(buffer,*opts_ptr); - - (*opts_ptr)->kv_refinement_criteria = kv_refinement_criterea_new(); - - return buffer - buffer_start; -} - -static fclaw_packing_vtable_t packing_vt = -{ - options_pack, - options_unpack, - options_packsize, - clawpatch_destroy_void -}; - -const fclaw_packing_vtable_t* -fclaw_clawpatch_options_get_packing_vtable() -{ - return &packing_vt; -} - /* ------------------------------------------------------------------------ Generic functions - these call the functions above ------------------------------------------------------------------------ */ @@ -251,8 +198,6 @@ options_register(fclaw_app_t * a, void *optpkg, sc_options_t * opt) fclaw_clawpatch_options_t *clawpatch_opt = (fclaw_clawpatch_options_t *) optpkg; - fclaw_app_register_options_packing_vtable("clawpatch", &packing_vt); - return clawpatch_register(clawpatch_opt,opt); } diff --git a/src/patches/clawpatch/fclaw_clawpatch_options.h b/src/patches/clawpatch/fclaw_clawpatch_options.h index f05415e41..f27921efc 100644 --- a/src/patches/clawpatch/fclaw_clawpatch_options.h +++ b/src/patches/clawpatch/fclaw_clawpatch_options.h @@ -168,14 +168,6 @@ void fclaw_clawpatch_options_store (struct fclaw_global *glob, */ fclaw_clawpatch_options_t* fclaw_clawpatch_get_options(struct fclaw_global* glob); -/** - * @brief Get the packing vtable for fclaw_clawpatch_options_t - * - * @return const fclaw_packing_vtable_t* the vtable - */ -const fclaw_packing_vtable_t* fclaw_clawpatch_options_get_packing_vtable(); - - #ifdef __cplusplus #if 0 { /* need this because indent is dumb */ diff --git a/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp index 02d2831f2..d3018baa6 100644 --- a/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp @@ -106,95 +106,4 @@ TEST_CASE("fclaw_clawpatch_options_store fails if called twice on a glob") fclaw_global_destroy(glob2); } -#endif -TEST_CASE("2d fclaw_clawpatch_options packing/unpacking") -{ - fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(2); - opts->mx = 5; - opts->my = 6; - opts->maux = 4; - opts->mbc = 3; - opts->meqn = 32; - opts->rhs_fields = 39; - opts->refinement_criteria = 1; - opts->interp_stencil_width = 3; - opts->ghost_patch_pack_aux = 7; - opts->save_aux = 1; - opts->is_registered = 1; - - const fclaw_packing_vtable_t* vt = fclaw_clawpatch_options_get_packing_vtable(); - - size_t size = vt->size(opts); - char buffer[size]; - size_t bytes_written = vt->pack(opts,buffer); - REQUIRE_EQ(bytes_written,size); - - fclaw_clawpatch_options_t* output_opts = nullptr; - size_t bytes_read = vt->unpack(buffer,(void**)&output_opts); - - REQUIRE_EQ(bytes_read,size); - REQUIRE_NE(output_opts,nullptr); - - CHECK_EQ(output_opts->patch_dim,2); - CHECK_EQ(output_opts->mx,opts->mx); - CHECK_EQ(output_opts->my,opts->my); - CHECK_EQ(output_opts->maux,opts->maux); - CHECK_EQ(output_opts->mbc,opts->mbc); - CHECK_EQ(output_opts->meqn,opts->meqn); - CHECK_EQ(output_opts->rhs_fields,opts->rhs_fields); - CHECK_EQ(output_opts->refinement_criteria,opts->refinement_criteria); - CHECK_EQ(output_opts->interp_stencil_width,opts->interp_stencil_width); - CHECK_EQ(output_opts->ghost_patch_pack_aux,opts->ghost_patch_pack_aux); - CHECK_EQ(output_opts->save_aux,opts->save_aux); - CHECK_EQ(output_opts->is_registered,opts->is_registered); - - vt->destroy(output_opts); - fclaw_clawpatch_options_destroy(opts); -} - -TEST_CASE("3d fclaw_clawpatch_options packing/unpacking") -{ - fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); - opts->mx = 5; - opts->my = 6; - opts->mz = 3; - opts->maux = 4; - opts->mbc = 3; - opts->meqn = 32; - opts->rhs_fields = 39; - opts->refinement_criteria = 1; - opts->interp_stencil_width = 3; - opts->ghost_patch_pack_aux = 7; - opts->save_aux = 1; - opts->is_registered = 1; - - const fclaw_packing_vtable_t* vt = fclaw_clawpatch_options_get_packing_vtable(); - - size_t size = vt->size(opts); - char buffer[size]; - size_t bytes_written = vt->pack(opts,buffer); - REQUIRE_EQ(bytes_written,size); - - fclaw_clawpatch_options_t* output_opts = nullptr; - size_t bytes_read = vt->unpack(buffer,(void**)&output_opts); - - REQUIRE_EQ(bytes_read,size); - REQUIRE_NE(output_opts,nullptr); - - CHECK_EQ(output_opts->patch_dim,3); - CHECK_EQ(output_opts->mx,opts->mx); - CHECK_EQ(output_opts->my,opts->my); - CHECK_EQ(output_opts->mz,opts->mz); - CHECK_EQ(output_opts->maux,opts->maux); - CHECK_EQ(output_opts->mbc,opts->mbc); - CHECK_EQ(output_opts->meqn,opts->meqn); - CHECK_EQ(output_opts->rhs_fields,opts->rhs_fields); - CHECK_EQ(output_opts->refinement_criteria,opts->refinement_criteria); - CHECK_EQ(output_opts->interp_stencil_width,opts->interp_stencil_width); - CHECK_EQ(output_opts->ghost_patch_pack_aux,opts->ghost_patch_pack_aux); - CHECK_EQ(output_opts->save_aux,opts->save_aux); - CHECK_EQ(output_opts->is_registered,opts->is_registered); - - vt->destroy(output_opts); - fclaw_clawpatch_options_destroy(opts); -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.c b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.c index bdd37b0ba..a84abbc49 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.c +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.c @@ -120,104 +120,6 @@ void clawpack46_destroy (fc2d_clawpack46_options_t * clawopt) FCLAW_FREE (clawopt); } -static void clawpack46_destroy_void(void* user) -{ - fc2d_clawpack46_options_t* clawopt = (fc2d_clawpack46_options_t*) user; - clawpack46_destroy(clawopt); -} - -static size_t -options_packsize(void* user) -{ - fc2d_clawpack46_options_t* opts = (fc2d_clawpack46_options_t*) user; - - size_t size = sizeof(fc2d_clawpack46_options_t); - size += fclaw_packsize_string(opts->order_string); - size += 2*sizeof(int); /* order */ - size += opts->mwaves*sizeof(int); /* mthlim */ - size += fclaw_packsize_string(opts->mthlim_string); - size += 4*sizeof(int); /* mthbc */ - size += fclaw_packsize_string(opts->mthbc_string); - - return size; -} - -static size_t -options_pack(void* user, char* buffer) -{ - char* buffer_start = buffer; - - fc2d_clawpack46_options_t* opts = (fc2d_clawpack46_options_t*) user; - - //pack entire struct - buffer += FCLAW_PACK(*opts, buffer); - - //append arrays to buffer - buffer += fclaw_pack_string(opts->order_string,buffer); - buffer += fclaw_pack_int(opts->order[0],buffer); - buffer += fclaw_pack_int(opts->order[1],buffer); - for(size_t i = 0; i < opts->mwaves; i++) - { - buffer += fclaw_pack_int(opts->mthlim[i],buffer); - } - buffer += fclaw_pack_string(opts->mthlim_string,buffer); - for(size_t i = 0; i < 4; i++) - { - buffer += fclaw_pack_int(opts->mthbc[i],buffer); - } - buffer += fclaw_pack_string(opts->mthbc_string,buffer); - - return buffer-buffer_start; -} - -static size_t -options_unpack(char* buffer, void** user) -{ - char* buffer_start = buffer; - - fc2d_clawpack46_options_t** opts_ptr = (fc2d_clawpack46_options_t**) user; - *opts_ptr = FCLAW_ALLOC(fc2d_clawpack46_options_t,1); - fc2d_clawpack46_options_t* opts = *opts_ptr; - - buffer += FCLAW_UNPACK(buffer, opts); - - //unpack arrays - buffer += fclaw_unpack_string(buffer,(char**) &opts->order_string); - opts->order = FCLAW_ALLOC(int,2); - buffer += fclaw_unpack_int(buffer,&opts->order[0]); - buffer += fclaw_unpack_int(buffer,&opts->order[1]); - opts->mthlim = FCLAW_ALLOC(int,opts->mwaves); - for(size_t i = 0; i < opts->mwaves; i++) - { - buffer += fclaw_unpack_int(buffer,&opts->mthlim[i]); - } - buffer += fclaw_unpack_string(buffer,(char**) &opts->mthlim_string); - opts->mthbc = FCLAW_ALLOC(int,4); - for(size_t i = 0; i < 4; i++) - { - buffer += fclaw_unpack_int(buffer,&opts->mthbc[i]); - } - buffer += fclaw_unpack_string(buffer,(char**) &opts->mthbc_string); - - opts->is_unpacked = 1; - - return buffer-buffer_start; -} - -static fclaw_packing_vtable_t packing_vt = -{ - options_pack, - options_unpack, - options_packsize, - clawpack46_destroy_void -}; - -const fclaw_packing_vtable_t* -fc2d_clawpack46_options_get_packing_vtable() -{ - return &packing_vt; -} - /* ------------------------------------------------------ Generic calls to options handling; each calls clawpack-specific options call back @@ -297,8 +199,6 @@ fc2d_clawpack46_options_t* fc2d_clawpack46_options_register (fclaw_app_t * app, const char *section, const char *configfile) { - fclaw_app_register_options_packing_vtable("fc2d_clawpack46", &packing_vt); - fc2d_clawpack46_options_t *clawopt; FCLAW_ASSERT (app != NULL); diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h index a5fbe1424..4d9be4bee 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h @@ -93,13 +93,6 @@ void fc2d_clawpack46_options_store (struct fclaw_global* glob, fc2d_clawpack46_o void fc2d_clawpack46_output(struct fclaw_global *glob, int iframe); -/** - * @brief Get the packing vtable for fc2d_clawpack46_options_t - * - * @return const fclaw_packing_vtable_t* the vtable - */ -const fclaw_packing_vtable_t* fc2d_clawpack46_options_get_packing_vtable(); - #ifdef __cplusplus #if 0 { diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp index 06aba5569..b78ce3198 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp @@ -83,80 +83,4 @@ TEST_CASE("fc2d_clawpack46_options_store fails if called twice on a glob") fclaw_global_destroy(glob2); } -TEST_CASE("fc2d_clawpack46_options packing/unpacking") -{ - fc2d_clawpack46_options_t* opts = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); - opts->mwaves = 5; - opts->order_string = "[2 2]"; - int order[] = {2,2}; - opts->order = order; - int mthlim[] = {5,4,3,2,1}; - opts->mthlim = mthlim; - opts->mthlim_string = "[5 4 3 2 1]"; - int mthbc[] = {0, 1, 1, 1}; - opts->mthbc = mthbc; - opts->mthbc_string = "[0 1 1 1]"; - - int method[] = {0,4,3,2,5,6,99}; - for(size_t i = 0; i < 7; ++i) - opts->method[i] = method[i]; - - opts->mcapa = 3; - opts->src_term = 2; - opts->use_fwaves = 1; - - opts->ascii_out = 2; - opts->vtk_out = 3; - - opts->is_registered = 1; - - opts->is_unpacked = 0; - - const fclaw_packing_vtable_t* vt = fc2d_clawpack46_options_get_packing_vtable(); - - size_t size = vt->size(opts); - char buffer[size]; - size_t bytes_written = vt->pack(opts,buffer); - REQUIRE_EQ(bytes_written,size); - - fc2d_clawpack46_options_t* output_opts = nullptr; - size_t bytes_read = vt->unpack(buffer,(void**)&output_opts); - - REQUIRE_EQ(bytes_read,size); - REQUIRE_NE(output_opts,nullptr); - - CHECK_EQ(output_opts->mwaves, opts->mwaves); - - CHECK_NE(output_opts->order_string, opts->order_string); - CHECK_UNARY(!strcmp(output_opts->order_string, opts->order_string)); - - CHECK_EQ(output_opts->order[0], opts->order[0]); - CHECK_EQ(output_opts->order[1], opts->order[1]); - - for(size_t i = 0; i < 5; ++i) - CHECK_EQ(output_opts->mthlim[i], opts->mthlim[i]); - - CHECK_NE(output_opts->mthlim_string, opts->mthlim_string); - CHECK_UNARY(!strcmp(output_opts->mthlim_string, opts->mthlim_string)); - - for(size_t i = 0; i < 4; ++i) - CHECK_EQ(output_opts->mthbc[i], opts->mthbc[i]); - - CHECK_NE(output_opts->mthbc_string, opts->mthbc_string); - CHECK_UNARY(!strcmp(output_opts->mthbc_string, opts->mthbc_string)); - - for(size_t i = 0; i < 7; ++i) - CHECK_EQ(output_opts->method[i], opts->method[i]); - - CHECK_EQ(output_opts->mcapa, opts->mcapa); - CHECK_EQ(output_opts->src_term, opts->src_term); - CHECK_EQ(output_opts->use_fwaves, opts->use_fwaves); - CHECK_EQ(output_opts->ascii_out, opts->ascii_out); - CHECK_EQ(output_opts->vtk_out, opts->vtk_out); - CHECK_EQ(output_opts->is_registered, opts->is_registered); - CHECK_UNARY(output_opts->is_unpacked); - - vt->destroy(output_opts); - FCLAW_FREE(opts); -} #endif \ No newline at end of file diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.c b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.c index 784ae770b..658d4ea28 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.c +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.c @@ -125,105 +125,6 @@ clawpack5_destroy (fc2d_clawpack5_options_t * clawopt) FCLAW_FREE (clawopt); } -static void clawpack5_destroy_void(void* user) -{ - fc2d_clawpack5_options_t* clawopt = (fc2d_clawpack5_options_t*) user; - clawpack5_destroy(clawopt); -} - -static size_t -options_packsize(void* user) -{ - fc2d_clawpack5_options_t* opts = (fc2d_clawpack5_options_t*) user; - - size_t size = sizeof(fc2d_clawpack5_options_t); - size += fclaw_packsize_string(opts->order_string); - size += 2*sizeof(int); /* order */ - size += opts->mwaves*sizeof(int); /* mthlim */ - size += fclaw_packsize_string(opts->mthlim_string); - size += 4*sizeof(int); /* mthbc */ - size += fclaw_packsize_string(opts->mthbc_string); - - return size; -} - -static size_t -options_pack(void* user, char* buffer) -{ - char* buffer_start = buffer; - - fc2d_clawpack5_options_t* opts = (fc2d_clawpack5_options_t*) user; - - //pack entire struct - buffer += FCLAW_PACK(*opts, buffer); - - //append arrays to buffer - buffer += fclaw_pack_string(opts->order_string,buffer); - buffer += fclaw_pack_int(opts->order[0],buffer); - buffer += fclaw_pack_int(opts->order[1],buffer); - for(size_t i = 0; i < opts->mwaves; i++) - { - buffer += fclaw_pack_int(opts->mthlim[i],buffer); - } - buffer += fclaw_pack_string(opts->mthlim_string,buffer); - for(size_t i = 0; i < 4; i++) - { - buffer += fclaw_pack_int(opts->mthbc[i],buffer); - } - buffer += fclaw_pack_string(opts->mthbc_string,buffer); - - return buffer-buffer_start; -} - -static size_t -options_unpack(char* buffer, void** user) -{ - char* buffer_start = buffer; - - fc2d_clawpack5_options_t** opts_ptr = (fc2d_clawpack5_options_t**) user; - *opts_ptr = FCLAW_ALLOC(fc2d_clawpack5_options_t,1); - fc2d_clawpack5_options_t* opts = *opts_ptr; - - buffer += FCLAW_UNPACK(buffer, opts); - - //unpack arrays - buffer += fclaw_unpack_string(buffer,(char**) &opts->order_string); - opts->order = FCLAW_ALLOC(int,2); - buffer += fclaw_unpack_int(buffer,&opts->order[0]); - buffer += fclaw_unpack_int(buffer,&opts->order[1]); - opts->mthlim = FCLAW_ALLOC(int,opts->mwaves); - for(size_t i = 0; i < opts->mwaves; i++) - { - buffer += fclaw_unpack_int(buffer,&opts->mthlim[i]); - } - buffer += fclaw_unpack_string(buffer,(char**) &opts->mthlim_string); - opts->mthbc = FCLAW_ALLOC(int,4); - for(size_t i = 0; i < 4; i++) - { - buffer += fclaw_unpack_int(buffer,&opts->mthbc[i]); - } - buffer += fclaw_unpack_string(buffer,(char**) &opts->mthbc_string); - - opts->is_unpacked = 1; - - return buffer-buffer_start; -} - -static fclaw_packing_vtable_t packing_vt = -{ - options_pack, - options_unpack, - options_packsize, - clawpack5_destroy_void -}; - -const fclaw_packing_vtable_t* -fc2d_clawpack5_options_get_packing_vtable() -{ - return &packing_vt; -} - - /* ------------------------------------------------------------------- Functions below are part of the options vtable; no need to change these They call functions above @@ -231,8 +132,6 @@ fc2d_clawpack5_options_get_packing_vtable() static void* options_register (fclaw_app_t * app, void *package, sc_options_t * opt) { - fclaw_app_register_options_packing_vtable("fc2d_clawpack5", &packing_vt); - fc2d_clawpack5_options_t *clawopt; FCLAW_ASSERT (app != NULL); diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h index d066c688e..64bf17390 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h @@ -94,13 +94,6 @@ void CLAWPACK5_SET_AMR_MODULE(const int* mwaves_in, const int* mcapa_in, const int mthlim_in[], const int method_in[], const int *use_fwaves); -/** - * @brief Get the packing vtable for fc2d_clawpack5_options_t - * - * @return const fclaw_packing_vtable_t* the vtable - */ -const fclaw_packing_vtable_t* fc2d_clawpack5_options_get_packing_vtable(); - #ifdef __cplusplus #if 0 { diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp index 4b7ae9904..9a789d0ed 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp @@ -83,80 +83,4 @@ TEST_CASE("fc2d_clawpack5_options_store fails if called twice on a glob") fclaw_global_destroy(glob2); } -TEST_CASE("fc2d_clawpack5_options packing/unpacking") -{ - fc2d_clawpack5_options_t* opts = FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1); - opts->mwaves = 5; - opts->order_string = "[2 2]"; - int order[] = {2,2}; - opts->order = order; - int mthlim[] = {5,4,3,2,1}; - opts->mthlim = mthlim; - opts->mthlim_string = "[5 4 3 2 1]"; - int mthbc[] = {0, 1, 1, 1}; - opts->mthbc = mthbc; - opts->mthbc_string = "[0 1 1 1]"; - - int method[] = {0,4,3,2,5,6,99}; - for(size_t i = 0; i < 7; ++i) - opts->method[i] = method[i]; - - opts->mcapa = 3; - opts->src_term = 2; - opts->use_fwaves = 1; - - opts->ascii_out = 2; - opts->vtk_out = 3; - - opts->is_registered = 1; - - opts->is_unpacked = 0; - - const fclaw_packing_vtable_t* vt = fc2d_clawpack5_options_get_packing_vtable(); - - size_t size = vt->size(opts); - char buffer[size]; - size_t bytes_written = vt->pack(opts,buffer); - REQUIRE_EQ(bytes_written,size); - - fc2d_clawpack5_options_t* output_opts = nullptr; - size_t bytes_read = vt->unpack(buffer,(void**)&output_opts); - - REQUIRE_EQ(bytes_read,size); - REQUIRE_NE(output_opts,nullptr); - - CHECK_EQ(output_opts->mwaves, opts->mwaves); - - CHECK_NE(output_opts->order_string, opts->order_string); - CHECK_UNARY(!strcmp(output_opts->order_string, opts->order_string)); - - CHECK_EQ(output_opts->order[0], opts->order[0]); - CHECK_EQ(output_opts->order[1], opts->order[1]); - - for(size_t i = 0; i < 5; ++i) - CHECK_EQ(output_opts->mthlim[i], opts->mthlim[i]); - - CHECK_NE(output_opts->mthlim_string, opts->mthlim_string); - CHECK_UNARY(!strcmp(output_opts->mthlim_string, opts->mthlim_string)); - - for(size_t i = 0; i < 4; ++i) - CHECK_EQ(output_opts->mthbc[i], opts->mthbc[i]); - - CHECK_NE(output_opts->mthbc_string, opts->mthbc_string); - CHECK_UNARY(!strcmp(output_opts->mthbc_string, opts->mthbc_string)); - - for(size_t i = 0; i < 7; ++i) - CHECK_EQ(output_opts->method[i], opts->method[i]); - - CHECK_EQ(output_opts->mcapa, opts->mcapa); - CHECK_EQ(output_opts->src_term, opts->src_term); - CHECK_EQ(output_opts->use_fwaves, opts->use_fwaves); - CHECK_EQ(output_opts->ascii_out, opts->ascii_out); - CHECK_EQ(output_opts->vtk_out, opts->vtk_out); - CHECK_EQ(output_opts->is_registered, opts->is_registered); - CHECK_UNARY(output_opts->is_unpacked); - - vt->destroy(output_opts); - FCLAW_FREE(opts); -} #endif \ No newline at end of file From 75cf5f9bf7d85d290d45d34a638ff89c903eae6f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 15:18:03 -0600 Subject: [PATCH 13/76] add attribute entry struct for attribute metadata --- src/fclaw_global.c | 57 ++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index babe15c0c..6e299b0dd 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -289,20 +289,55 @@ void* fclaw_global_get_options (fclaw_global_t* glob, const char* key) return options; } +/* + * @brief struct for store attributes and metadata + */ +typedef +struct attribute_entry +{ + /* the key to the packing vtable, NULL if not used */ + const char* packing_vtable_key; + /* the attribute */ + void* attribute; + /* the callback to destroy the attribute, NULL if not used*/ + fclaw_pointer_map_value_destroy_t destroy; +} attribute_entry_t; + +/* callback to destroy attribute entry */ +void attribute_entry_destroy(void* value) +{ + attribute_entry_t* entry = (attribute_entry_t*) value; + if(entry->destroy != NULL) + { + entry->destroy(entry->attribute); + } + FCLAW_FREE(entry); +} + void fclaw_global_attribute_store (fclaw_global_t * glob, const char * key, void* attribute, - const char * packing_key, + const char * packing_vtable_key, fclaw_pointer_map_value_destroy_t destroy) { - fclaw_pointer_map_insert(glob->options, key, attribute, destroy); + attribute_entry_t *entry = FCLAW_ALLOC(attribute_entry_t,1); + entry->packing_vtable_key = packing_vtable_key; + entry->attribute = attribute; + entry->destroy = destroy; + fclaw_pointer_map_insert(glob->options, key, entry, attribute_entry_destroy); } void * fclaw_global_get_attribute (fclaw_global_t* glob, const char* key) { - return fclaw_pointer_map_get(glob->options, key); + attribute_entry_t *entry = (attribute_entry_t*) fclaw_pointer_map_get(glob->options, key); + void * attribute = NULL; + if(entry != NULL) + { + attribute = entry->attribute; + } + return attribute; } void @@ -320,22 +355,6 @@ fclaw_global_get_vtable (fclaw_global_t* glob, const char* key) return fclaw_pointer_map_get(glob->vtables, key); } -void -fclaw_global_register_options_packing_vtable(fclaw_global_t * glob, - const char*name, - fclaw_packing_vtable_t* vtable, - fclaw_pointer_map_value_destroy_t destroy) -{ - // -} - -fclaw_packing_vtable_t * -fclaw_global_get_options_packing_vtable(fclaw_global_t * glob, const char*name) -{ - // - return NULL; -} - static fclaw_global_t* fclaw2d_global_glob = NULL; void fclaw_global_set_static (fclaw_global_t* glob) From 1613a7f13782351d7f9acfa2415f5ee01ec84573 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 15:20:15 -0600 Subject: [PATCH 14/76] move glob packing code --- src/fclaw_global.c | 166 ++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 84 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 6e299b0dd..5bb08ba6c 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -92,90 +92,6 @@ fclaw_global_t* fclaw_global_new_comm (sc_MPI_Comm mpicomm, return glob; } -#ifndef P4_TO_P8 -// packing unpacking functions only 2d for now - -static void check_vt(fclaw_packing_vtable_t* vt, const char* name) -{ - char msg[1024]; - sprintf(msg,"Unregistered options packing vtable for \"%s\"",name); - SC_CHECK_ABORT ((vt != NULL), msg); -} - -static void -pack_iterator_callback(const char* key, void* value, void* user) -{ - char** buffer_ptr = (char **) user; - - *buffer_ptr += fclaw_pack_string(key, *buffer_ptr); - - fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - check_vt(vt,key); - - // advance buffer pointer - *buffer_ptr += vt->pack(value,*buffer_ptr); -} - -size_t -fclaw_global_pack(const fclaw_global_t * glob, char* buffer) -{ - const char* buffer_start = buffer; - - buffer += fclaw_pack_double(glob->curr_time, buffer); - buffer += fclaw_pack_double(glob->curr_dt, buffer); - - buffer += fclaw_pack_size_t(fclaw_pointer_map_size(glob->options), buffer); - - //fclaw_pointer_map_iterate(glob->options, pack_iterator_callback, &buffer); - - return (buffer-buffer_start); -} - -static void -packsize_iterator_callback(const char* key, void* value, void* user) -{ - size_t* options_size = (size_t*) user; - fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - check_vt(vt,key); - (*options_size) += fclaw_packsize_string(key) + vt->size(value); -} - -size_t -fclaw_global_packsize(const fclaw_global_t * glob) -{ - size_t options_size = sizeof(size_t); - //fclaw_pointer_map_iterate(glob->options, packsize_iterator_callback, &options_size); - return 2*sizeof(double) + options_size; -} - -size_t -fclaw_global_unpack(char* buffer, fclaw_global_t * glob) -{ - char* buffer_start = buffer; - - buffer += fclaw_unpack_double(buffer,&glob->curr_time); - buffer += fclaw_unpack_double(buffer,&glob->curr_dt); - - size_t num_option_structs; - buffer += fclaw_unpack_size_t(buffer,&num_option_structs); - - //for(size_t i = 0; i< num_option_structs; i++) - //{ - // char * key; - // buffer += fclaw_unpack_string(buffer,&key); - // fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - // check_vt(vt,key); - // void * options; - // buffer += vt->unpack(buffer,&options); - // fclaw_pointer_map_insert(glob->options, key, options, vt->destroy); - // FCLAW_FREE(key); - //} - - return buffer-buffer_start; -} - -#endif - void fclaw_global_store_domain (fclaw_global_t* glob, fclaw_domain_t* domain) { @@ -340,6 +256,88 @@ fclaw_global_get_attribute (fclaw_global_t* glob, const char* key) return attribute; } +/* *************************************** + * Packing and unpacking functions + * ***************************************/ + +static void check_vt(fclaw_packing_vtable_t* vt, const char* name) +{ + char msg[1024]; + sprintf(msg,"Unregistered options packing vtable for \"%s\"",name); + SC_CHECK_ABORT ((vt != NULL), msg); +} + +static void +pack_iterator_callback(const char* key, void* value, void* user) +{ + char** buffer_ptr = (char **) user; + + *buffer_ptr += fclaw_pack_string(key, *buffer_ptr); + + fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); + check_vt(vt,key); + + // advance buffer pointer + *buffer_ptr += vt->pack(value,*buffer_ptr); +} + +size_t +fclaw_global_pack(const fclaw_global_t * glob, char* buffer) +{ + const char* buffer_start = buffer; + + buffer += fclaw_pack_double(glob->curr_time, buffer); + buffer += fclaw_pack_double(glob->curr_dt, buffer); + + buffer += fclaw_pack_size_t(fclaw_pointer_map_size(glob->options), buffer); + + //fclaw_pointer_map_iterate(glob->options, pack_iterator_callback, &buffer); + + return (buffer-buffer_start); +} + +static void +packsize_iterator_callback(const char* key, void* value, void* user) +{ + size_t* options_size = (size_t*) user; + fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); + check_vt(vt,key); + (*options_size) += fclaw_packsize_string(key) + vt->size(value); +} + +size_t +fclaw_global_packsize(const fclaw_global_t * glob) +{ + size_t options_size = sizeof(size_t); + //fclaw_pointer_map_iterate(glob->options, packsize_iterator_callback, &options_size); + return 2*sizeof(double) + options_size; +} + +size_t +fclaw_global_unpack(char* buffer, fclaw_global_t * glob) +{ + char* buffer_start = buffer; + + buffer += fclaw_unpack_double(buffer,&glob->curr_time); + buffer += fclaw_unpack_double(buffer,&glob->curr_dt); + + size_t num_option_structs; + buffer += fclaw_unpack_size_t(buffer,&num_option_structs); + + //for(size_t i = 0; i< num_option_structs; i++) + //{ + // char * key; + // buffer += fclaw_unpack_string(buffer,&key); + // fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); + // check_vt(vt,key); + // void * options; + // buffer += vt->unpack(buffer,&options); + // fclaw_pointer_map_insert(glob->options, key, options, vt->destroy); + // FCLAW_FREE(key); + //} + + return buffer-buffer_start; +} void fclaw_global_vtable_store (fclaw_global_t * glob, const char * key, From 6d92b051ff38617c3d6bc03ca79a3e49ad463fc8 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 16:50:39 -0600 Subject: [PATCH 15/76] attribute packing works --- src/fclaw_global.c | 175 ++++++++++++++++++++++++++---------- src/fclaw_global.h | 4 +- src/fclaw_global.h.TEST.cpp | 122 +++++++++++++------------ 3 files changed, 196 insertions(+), 105 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 5bb08ba6c..0db165bdf 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -212,7 +212,7 @@ typedef struct attribute_entry { /* the key to the packing vtable, NULL if not used */ - const char* packing_vtable_key; + char* packing_vtable_key; /* the attribute */ void* attribute; /* the callback to destroy the attribute, NULL if not used*/ @@ -220,13 +220,15 @@ struct attribute_entry } attribute_entry_t; /* callback to destroy attribute entry */ -void attribute_entry_destroy(void* value) +static void +attribute_entry_destroy(void* value) { attribute_entry_t* entry = (attribute_entry_t*) value; if(entry->destroy != NULL) { entry->destroy(entry->attribute); } + FCLAW_FREE(entry->packing_vtable_key); FCLAW_FREE(entry); } @@ -238,16 +240,25 @@ fclaw_global_attribute_store (fclaw_global_t * glob, fclaw_pointer_map_value_destroy_t destroy) { attribute_entry_t *entry = FCLAW_ALLOC(attribute_entry_t,1); - entry->packing_vtable_key = packing_vtable_key; + if(packing_vtable_key != NULL) + { + entry->packing_vtable_key = FCLAW_ALLOC(char,strlen(packing_vtable_key)+1); + strcpy(entry->packing_vtable_key,packing_vtable_key); + } + else + { + entry->packing_vtable_key = NULL; + } entry->attribute = attribute; entry->destroy = destroy; - fclaw_pointer_map_insert(glob->options, key, entry, attribute_entry_destroy); + fclaw_pointer_map_insert(glob->attributes, key, entry, attribute_entry_destroy); } void * fclaw_global_get_attribute (fclaw_global_t* glob, const char* key) { - attribute_entry_t *entry = (attribute_entry_t*) fclaw_pointer_map_get(glob->options, key); + attribute_entry_t *entry = + (attribute_entry_t*) fclaw_pointer_map_get(glob->attributes, key); void * attribute = NULL; if(entry != NULL) { @@ -260,81 +271,153 @@ fclaw_global_get_attribute (fclaw_global_t* glob, const char* key) * Packing and unpacking functions * ***************************************/ -static void check_vt(fclaw_packing_vtable_t* vt, const char* name) +static void +check_vt(fclaw_packing_vtable_t* vt, + const char* name, + const char* vtable_name) { - char msg[1024]; - sprintf(msg,"Unregistered options packing vtable for \"%s\"",name); - SC_CHECK_ABORT ((vt != NULL), msg); + if(vt == NULL) + { + char msg[BUFSIZ]; + snprintf(msg, BUFSIZ, "Unregistered attribute packing vtable \"%s\" for attribute \"%s\"",vtable_name,name); + SC_CHECK_ABORT ((vt != NULL), msg); + } } static void -pack_iterator_callback(const char* key, void* value, void* user) +num_to_pack_cb(const char* key, void* value, void* user) { - char** buffer_ptr = (char **) user; - - *buffer_ptr += fclaw_pack_string(key, *buffer_ptr); - - fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - check_vt(vt,key); + size_t *num_to_pack = (size_t*) user; + attribute_entry_t* entry = (attribute_entry_t*) value; + if(entry->packing_vtable_key != NULL) + { + (*num_to_pack)++; + } +} +typedef +struct pack_iter +{ + fclaw_global_t* glob; + char** buffer_ptr; + size_t num_packed; +} pack_iter_t; - // advance buffer pointer - *buffer_ptr += vt->pack(value,*buffer_ptr); +static void +pack_attribute_cb(const char* key, void* value, void* user) +{ + pack_iter_t *iter = (pack_iter_t*) user; + attribute_entry_t* entry = (attribute_entry_t*) value; + if(entry->packing_vtable_key != NULL) + { + fclaw_packing_vtable_t* vt + = (fclaw_packing_vtable_t*) fclaw_global_get_vtable(iter->glob, entry->packing_vtable_key); + check_vt(vt, key, entry->packing_vtable_key); + // advance buffer pointer + *iter->buffer_ptr += fclaw_pack_string(entry->packing_vtable_key, *iter->buffer_ptr); + *iter->buffer_ptr += fclaw_pack_string(key, *iter->buffer_ptr); + *iter->buffer_ptr += vt->pack(entry->attribute, *iter->buffer_ptr); + } } size_t -fclaw_global_pack(const fclaw_global_t * glob, char* buffer) +fclaw_global_pack(fclaw_global_t * glob, char* buffer) { const char* buffer_start = buffer; buffer += fclaw_pack_double(glob->curr_time, buffer); buffer += fclaw_pack_double(glob->curr_dt, buffer); - buffer += fclaw_pack_size_t(fclaw_pointer_map_size(glob->options), buffer); + size_t num_to_pack = 0; + fclaw_pointer_map_iterate(glob->attributes, num_to_pack_cb, &num_to_pack); + buffer += fclaw_pack_size_t(num_to_pack, buffer); - //fclaw_pointer_map_iterate(glob->options, pack_iterator_callback, &buffer); + pack_iter_t iter; + iter.glob = glob; + iter.buffer_ptr = &buffer; + fclaw_pointer_map_iterate(glob->attributes, pack_attribute_cb, &iter); return (buffer-buffer_start); } +typedef +struct packsize_iter +{ + fclaw_global_t* glob; + size_t size; +} packsize_iter_t; + static void -packsize_iterator_callback(const char* key, void* value, void* user) +attribute_packsize_cb(const char* key, void* value, void* user) { - size_t* options_size = (size_t*) user; - fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - check_vt(vt,key); - (*options_size) += fclaw_packsize_string(key) + vt->size(value); + packsize_iter_t* iter = (packsize_iter_t*) user; + attribute_entry_t* entry = (attribute_entry_t*) value; + if(entry->packing_vtable_key != NULL) + { + fclaw_packing_vtable_t* vt = + (fclaw_packing_vtable_t*) fclaw_global_get_vtable(iter->glob, entry->packing_vtable_key); + check_vt(vt, key, entry->packing_vtable_key); + iter->size += + fclaw_packsize_string(entry->packing_vtable_key) + + fclaw_packsize_string(key) + + vt->size(entry->attribute); + } } size_t -fclaw_global_packsize(const fclaw_global_t * glob) +fclaw_global_packsize(fclaw_global_t * glob) { - size_t options_size = sizeof(size_t); - //fclaw_pointer_map_iterate(glob->options, packsize_iterator_callback, &options_size); - return 2*sizeof(double) + options_size; + packsize_iter_t iter; + iter.glob = glob; + iter.size = sizeof(size_t); + fclaw_pointer_map_iterate(glob->attributes, attribute_packsize_cb, &iter); + return 2*sizeof(double) + iter.size; } size_t -fclaw_global_unpack(char* buffer, fclaw_global_t * glob) +fclaw_global_unpack(char * buffer, fclaw_global_t * glob) { - char* buffer_start = buffer; + char *buffer_start = buffer; buffer += fclaw_unpack_double(buffer,&glob->curr_time); buffer += fclaw_unpack_double(buffer,&glob->curr_dt); - size_t num_option_structs; - buffer += fclaw_unpack_size_t(buffer,&num_option_structs); - - //for(size_t i = 0; i< num_option_structs; i++) - //{ - // char * key; - // buffer += fclaw_unpack_string(buffer,&key); - // fclaw_packing_vtable_t* vt = fclaw_app_get_options_packing_vtable(key); - // check_vt(vt,key); - // void * options; - // buffer += vt->unpack(buffer,&options); - // fclaw_pointer_map_insert(glob->options, key, options, vt->destroy); - // FCLAW_FREE(key); - //} + size_t num_attributes; + buffer += fclaw_unpack_size_t(buffer,&num_attributes); + + for(size_t i = 0; i< num_attributes; i++) + { + char *packing_vtable_key; + buffer += fclaw_unpack_string(buffer,&packing_vtable_key); + + char *attribute_key; + buffer += fclaw_unpack_string(buffer,&attribute_key); + + fclaw_packing_vtable_t *vt = + (fclaw_packing_vtable_t *) fclaw_global_get_vtable(glob, packing_vtable_key); + + check_vt(vt, attribute_key, packing_vtable_key); + + attribute_entry_t *entry + = (attribute_entry_t *) fclaw_pointer_map_get(glob->attributes, attribute_key); + + if(entry == NULL) + { + entry = FCLAW_ALLOC(attribute_entry_t,1); + entry->packing_vtable_key = packing_vtable_key; + entry->attribute = vt->new_data(); + entry->destroy = vt->destroy; + fclaw_pointer_map_insert(glob->attributes, attribute_key, entry, attribute_entry_destroy); + } + else + { + FCLAW_ASSERT(strcmp(entry->packing_vtable_key,packing_vtable_key) == 0); + FCLAW_FREE(packing_vtable_key); + } + + buffer += vt->unpack(buffer,entry->attribute); + + FCLAW_FREE(attribute_key); + } return buffer-buffer_start; } diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 8f1f964d3..6a903add5 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -152,7 +152,7 @@ struct fclaw_map_context* fclaw_map_get(fclaw_global_t* glob); * @param buffer the buffer to write to * @return size_t number of bytes written */ -size_t fclaw_global_pack(const fclaw_global_t * glob, char* buffer); +size_t fclaw_global_pack(fclaw_global_t * glob, char* buffer); /** * @brief Get the number of bytes needed to pack the global structure @@ -160,7 +160,7 @@ size_t fclaw_global_pack(const fclaw_global_t * glob, char* buffer); * @param glob the structure * @return size_t the number of bytes needed to store structure */ -size_t fclaw_global_packsize(const fclaw_global_t * glob); +size_t fclaw_global_packsize(fclaw_global_t * glob); /** * @brief Unpack global structure from buffer diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 41ab8f578..0acf4b126 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -67,43 +67,6 @@ TEST_CASE("fclaw_global_new default options") fclaw_global_destroy(glob); } -TEST_CASE("fclaw2d_global_pack with no options") -{ - - for(double curr_time : {1.0, 1.2}) - for(double curr_dt : {1.0, 1.2}) - { - fclaw_global_t* glob1; - glob1 = fclaw_global_new(); - glob1->curr_time = curr_time; - glob1->curr_dt = curr_dt; - - size_t packsize = fclaw_global_packsize(glob1); - - REQUIRE_GT(packsize, 0); - - char buffer[packsize]; - - size_t bytes_written = fclaw_global_pack(glob1, buffer); - - REQUIRE_EQ(bytes_written, packsize); - - fclaw_global_t* glob2 = fclaw_global_new(); - size_t bytes_read = fclaw_global_unpack(buffer, glob2); - - REQUIRE_EQ(bytes_read, packsize); - - CHECK_EQ(glob1->curr_time, glob2->curr_time); - CHECK_EQ(glob1->curr_dt, glob2->curr_dt); - - CHECK_EQ(fclaw_pointer_map_size(glob2->options), 0); - - - fclaw_global_destroy(glob1); - fclaw_global_destroy(glob2); - } -} - namespace { @@ -173,8 +136,9 @@ fclaw_packing_vtable_t dummy_opts_vt = }; } -TEST_CASE("fclaw_global_pack with no attribute") +TEST_CASE("fclaw_global_pack with no packed attributes") { + for(bool extra_non_packed_attribute : {true, false}) for(double curr_time : {1.0, 1.2}) for(double curr_dt : {1.0, 1.2}) { @@ -183,6 +147,12 @@ TEST_CASE("fclaw_global_pack with no attribute") glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; + if(extra_non_packed_attribute) + { + dummy_attribute* attribute = new dummy_attribute(40, 'b'); + fclaw_global_attribute_store(glob1, "dummy_not_packed", attribute, NULL, destroy_dummy_attribute); + } + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -206,9 +176,10 @@ TEST_CASE("fclaw_global_pack with no attribute") fclaw_global_destroy(glob2); } } -TEST_CASE("fclaw_global_pack with a single attribute") +TEST_CASE("fclaw_global_pack with a single packed attribute") { + for(bool extra_non_packed_attribute : {true, false}) for(bool already_stored_attribute : {true, false}) for(double curr_time : {1.0, 1.2}) for(double curr_dt : {1.0, 1.2}) @@ -218,12 +189,19 @@ TEST_CASE("fclaw_global_pack with a single attribute") //fclaw_app_t* app = fclaw_app_new_on_comm(sc_MPI_COMM_WORLD,&argc,&argv,NULL); fclaw_global_t* glob1; glob1 = fclaw_global_new(); + fclaw_global_vtable_store(glob1, "dummy1_vtable", &dummy_opts_vt, NULL); + glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; dummy_attribute* attribute1 = new dummy_attribute(20, 'a'); - fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); - fclaw_global_attribute_store(glob1, "dummy1", attribute1, "dummy1", destroy_dummy_attribute); + fclaw_global_attribute_store(glob1, "dummy1", attribute1, "dummy1_vtable", destroy_dummy_attribute); + + if(extra_non_packed_attribute) + { + dummy_attribute* attribute = new dummy_attribute(40, 'b'); + fclaw_global_attribute_store(glob1, "dummy_not_packed", attribute, NULL, destroy_dummy_attribute); + } size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -235,13 +213,23 @@ TEST_CASE("fclaw_global_pack with a single attribute") REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2 = fclaw_global_new(); - dummy_attribute* attribute2 = new dummy_attribute(99, 'z'); + fclaw_global_vtable_store(glob2, "dummy1_vtable", &dummy_opts_vt, NULL); + + dummy_attribute* attribute2 = NULL; if(already_stored_attribute) { - fclaw_global_attribute_store(glob2, "dummy1", attribute2, "dummy1", destroy_dummy_attribute); + attribute2 = new dummy_attribute(99, 'z'); + fclaw_global_attribute_store(glob2, "dummy1", attribute2, "dummy1_vtable", destroy_dummy_attribute); } + size_t bytes_read = fclaw_global_unpack(buffer, glob2); + if(!already_stored_attribute) + { + attribute2 = (dummy_attribute*)(fclaw_global_get_attribute(glob2, "dummy1")); + REQUIRE_NE(attribute2, nullptr); + } + REQUIRE_EQ(bytes_read, packsize); CHECK_EQ(glob1->curr_time, glob2->curr_time); @@ -256,9 +244,10 @@ TEST_CASE("fclaw_global_pack with a single attribute") fclaw_global_destroy(glob2); } } -TEST_CASE("fclaw_global_pack with two attribute structures") +TEST_CASE("fclaw_global_pack with two packed attributes") { + for(bool extra_non_packed_attribute : {true, false}) for(bool already_stored_attribute_1 : {true, false}) for(bool already_stored_attribute_2 : {true, false}) for(double curr_time : {1.0, 1.2}) @@ -266,17 +255,23 @@ TEST_CASE("fclaw_global_pack with two attribute structures") { fclaw_global_t* glob1; glob1 = fclaw_global_new(); + fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); + fclaw_global_vtable_store(glob1, "dummy2", &dummy_opts_vt, NULL); glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; dummy_attribute* attribute1_1 = new dummy_attribute(20, 'a'); dummy_attribute* attribute1_2 = new dummy_attribute(40, 'b'); - fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); fclaw_global_attribute_store(glob1, "dummy1", attribute1_1, "dummy1", destroy_dummy_attribute); - fclaw_global_vtable_store(glob1, "dummy2", &dummy_opts_vt, NULL); fclaw_global_attribute_store(glob1, "dummy2", attribute1_2, "dummy2", destroy_dummy_attribute); + if(extra_non_packed_attribute) + { + dummy_attribute* attribute = new dummy_attribute(40, 'b'); + fclaw_global_attribute_store(glob1, "dummy_not_packed", attribute, NULL, destroy_dummy_attribute); + } + size_t packsize = fclaw_global_packsize(glob1); REQUIRE_GT(packsize, 0); @@ -287,22 +282,35 @@ TEST_CASE("fclaw_global_pack with two attribute structures") REQUIRE_EQ(bytes_written, packsize); fclaw_global_t* glob2 = fclaw_global_new(); - dummy_attribute* attribute2_1 = new dummy_attribute(99, 'z'); - dummy_attribute* attribute2_2 = new dummy_attribute(99, 'z'); + fclaw_global_vtable_store(glob2, "dummy1", &dummy_opts_vt, NULL); + fclaw_global_vtable_store(glob2, "dummy2", &dummy_opts_vt, NULL); - fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); + dummy_attribute* attribute2_1 = NULL; + dummy_attribute* attribute2_2 = NULL; if(already_stored_attribute_1) { + attribute2_1 = new dummy_attribute(99, 'z'); fclaw_global_attribute_store(glob2, "dummy1", attribute2_1, "dummy1", destroy_dummy_attribute); } - fclaw_global_vtable_store(glob1, "dummy2", &dummy_opts_vt, NULL); if(already_stored_attribute_2) { + attribute2_2 = new dummy_attribute(99, 'z'); fclaw_global_attribute_store(glob2, "dummy2", attribute2_2, "dummy2", destroy_dummy_attribute); } size_t bytes_read = fclaw_global_unpack(buffer, glob2); + if(!already_stored_attribute_1) + { + attribute2_1 = (dummy_attribute*)(fclaw_global_get_attribute(glob2, "dummy1")); + REQUIRE_NE(attribute2_1, nullptr); + } + if(!already_stored_attribute_2) + { + attribute2_2 = (dummy_attribute*)(fclaw_global_get_attribute(glob2, "dummy2")); + REQUIRE_NE(attribute2_2, nullptr); + } + REQUIRE_EQ(bytes_read, packsize); CHECK_EQ(glob1->curr_time, glob2->curr_time); @@ -330,10 +338,10 @@ TEST_CASE("fclaw_global_pack aborts with unregistered vtable") dummy_attribute* attribute = new dummy_attribute(20, 'a'); fclaw_global_attribute_store(glob1, "dummy1", attribute, "pack_dummy1", destroy_dummy_attribute); - char buffer[100]; + char buffer[BUFSIZ]; CHECK_SC_ABORTED(fclaw_global_pack(glob1, buffer)); } -TEST_CASE("fclaw2d_global_packsize aborts with unregistered vtable") +TEST_CASE("fclaw_global_packsize aborts with unregistered vtable") { fclaw_global_t* glob1; glob1 = fclaw_global_new(); @@ -345,7 +353,7 @@ TEST_CASE("fclaw2d_global_packsize aborts with unregistered vtable") CHECK_SC_ABORTED(fclaw_global_packsize(glob1)); } -TEST_CASE("fclaw_global_unppack aborts with unregistered vtable") +TEST_CASE("fclaw_global_unpack aborts with unregistered vtable") { fclaw_global_t* glob1; glob1 = fclaw_global_new(); @@ -405,7 +413,7 @@ TEST_CASE("fclaw_global_options_store and fclaw_global_get_options test") { fclaw_global_destroy(glob); } -TEST_CASE("fclaw2d_global_set_global") +TEST_CASE("fclaw_global_set_global") { fclaw_global_t* glob = (fclaw_global_t*)123; fclaw_global_set_static(glob); @@ -427,7 +435,7 @@ TEST_CASE("fclaw_global_clear_static") #ifdef FCLAW_ENABLE_DEBUG -TEST_CASE("fclaw2d_global_set_global twice fails") +TEST_CASE("fclaw_global_set_global twice fails") { fclaw_global_t* glob = (fclaw_global_t*)123; fclaw_global_set_static(glob); @@ -435,12 +443,12 @@ TEST_CASE("fclaw2d_global_set_global twice fails") fclaw_global_clear_static(); } -TEST_CASE("fclaw2d_global_unset_global assert fails when NULL") +TEST_CASE("fclaw_global_unset_global assert fails when NULL") { CHECK_SC_ABORTED(fclaw_global_clear_static()); } -TEST_CASE("fclaw2d_global_get_global assert fails when NULL") +TEST_CASE("fclaw_global_get_global assert fails when NULL") { CHECK_SC_ABORTED(fclaw_global_get_static_global()); } From 42b660a49fa1c640912eb619e2fba32c84e2b97f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 18:01:58 -0600 Subject: [PATCH 16/76] outstyle_1 context gets written to restart file --- src/fclaw_forestclaw.c | 1 + src/fclaw_forestclaw.h | 1 + src/fclaw_run.c | 164 +++++++++++++++++++++++++++++++++-------- 3 files changed, 137 insertions(+), 29 deletions(-) diff --git a/src/fclaw_forestclaw.c b/src/fclaw_forestclaw.c index 93fc51864..3dab94a04 100644 --- a/src/fclaw_forestclaw.c +++ b/src/fclaw_forestclaw.c @@ -42,6 +42,7 @@ void fclaw_vtables_initialize(fclaw_global_t *glob) fclaw_elliptic_vtable_initialize(glob); fclaw_gauges_vtable_initialize(glob); fclaw_ray_vtable_initialize(glob); + fclaw_run_vtables_initialize(glob); } void fclaw_problem_setup(fclaw_global_t *glob) diff --git a/src/fclaw_forestclaw.h b/src/fclaw_forestclaw.h index ac4b143c0..5056e62b1 100644 --- a/src/fclaw_forestclaw.h +++ b/src/fclaw_forestclaw.h @@ -38,6 +38,7 @@ struct fclaw_global; void fclaw_problem_setup(struct fclaw_global *glob); void fclaw_vtables_initialize(struct fclaw_global *glob); +void fclaw_run_vtables_initialize(struct fclaw_global *glob); void fclaw_initialize (struct fclaw_global *glob); void fclaw_run (struct fclaw_global *glob); diff --git a/src/fclaw_run.c b/src/fclaw_run.c index 914d4f2b0..e8a8ebab7 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "fclaw_math.h" @@ -111,6 +112,77 @@ static void outstyle_0(fclaw_global_t *glob) } +typedef +struct outstyle1_ctx +{ + int initalized; + int iframe; + int n; + double dt_minlevel; +} outstyle1_ctx_t; + +static +size_t packsize_outstyle1_ctx(void *user) +{ + outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; + size_t size = 0; + size += sizeof(ctx->initalized); + size += sizeof(ctx->iframe); + size += sizeof(ctx->n); + size += sizeof(ctx->dt_minlevel); + return size; +} + +static +size_t pack_outstyle1_ctx(void *user, char *buffer) +{ + outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; + char* buffer_start = buffer; + buffer += fclaw_pack_int(ctx->initalized,buffer); + buffer += fclaw_pack_int(ctx->iframe,buffer); + buffer += fclaw_pack_int(ctx->n,buffer); + buffer += fclaw_pack_double(ctx->dt_minlevel,buffer); + return buffer - buffer_start; +} + +static +size_t unpack_outstyle1_ctx(char* buffer , void *user) +{ + outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; + char* buffer_start = buffer; + buffer += fclaw_unpack_int(buffer,&ctx->initalized); + buffer += fclaw_unpack_int(buffer,&ctx->iframe); + buffer += fclaw_unpack_int(buffer,&ctx->n); + buffer += fclaw_unpack_double(buffer,&ctx->dt_minlevel); + return buffer - buffer_start; +} + +static +void *outstyle1_ctx_new() +{ + outstyle1_ctx_t *ctx = FCLAW_ALLOC_ZERO(outstyle1_ctx_t,1); + return (void*) ctx; +} + +static +void outstyle1_ctx_destroy(void *user) +{ + FCLAW_FREE(user); +} + +#define OUTSTYLE1_CTX_ATTRIBUTE_KEY "fclaw_run_outstyle1_ctx" +#define OUTSTYLE1_CTX_VTABLE_KEY "fclaw_run_outstyle1_ctx_vtable" + +static +fclaw_packing_vtable_t outstyle1_ctx_vt = +{ + pack_outstyle1_ctx, + unpack_outstyle1_ctx, + packsize_outstyle1_ctx, + outstyle1_ctx_new, + outstyle1_ctx_destroy +}; + /* ------------------------------------------------------------------------------- Output style 1 @@ -119,6 +191,16 @@ static void outstyle_0(fclaw_global_t *glob) static void outstyle_1(fclaw_global_t *glob) { + outstyle1_ctx_t* ctx = (outstyle1_ctx_t*) fclaw_global_get_attribute(glob, OUTSTYLE1_CTX_ATTRIBUTE_KEY); + if(ctx == NULL) + { + ctx = (outstyle1_ctx_t*) outstyle1_ctx_new(); + fclaw_global_attribute_store(glob, + OUTSTYLE1_CTX_ATTRIBUTE_KEY, + ctx, + OUTSTYLE1_CTX_VTABLE_KEY, + outstyle1_ctx_destroy); + } fclaw_domain_t** domain = &glob->domain; /* Set error to 0 */ @@ -126,8 +208,11 @@ void outstyle_1(fclaw_global_t *glob) fclaw_diagnostics_gather(glob,init_flag); init_flag = 0; - int iframe = 0; - fclaw_output_frame(glob,iframe); + if(!ctx->initalized) + { + ctx->iframe = 0; + fclaw_output_frame(glob,ctx->iframe); + } const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); @@ -135,16 +220,23 @@ void outstyle_1(fclaw_global_t *glob) int nout = fclaw_opt->nout; double initial_dt = fclaw_opt->initial_dt; int level_factor = pow_int(2,fclaw_opt->maxlevel - fclaw_opt->minlevel); - double dt_minlevel = initial_dt; + if(!ctx->initalized) + { + ctx->dt_minlevel = initial_dt; + } double t0 = 0; double dt_outer = (final_time-t0)/((double) nout); - double t_curr = t0; + double t_curr = glob->curr_time; int n_inner = 0; - int n; - for(n = 0; n < nout; n++) + if(!ctx->initalized) + { + ctx->n = 0; + } + ctx->initalized = 1; + for(/* init above */; ctx->n < nout; ctx->n++) { double tstart = t_curr; @@ -165,7 +257,7 @@ void outstyle_1(fclaw_global_t *glob) the next step. Of course if 'tend - t_curr > dt_minlevel', then dt_minlevel doesn't change. */ - double dt_step = dt_minlevel; + double dt_step = ctx->dt_minlevel; if (fclaw_opt->advance_one_step) { dt_step /= level_factor; @@ -227,7 +319,7 @@ void outstyle_1(fclaw_global_t *glob) restore_time_step(glob); /* Modify dt_level0 from step used. */ - dt_minlevel = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + ctx->dt_minlevel = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; /* Got back to start of loop, without incrementing step counter or time level */ @@ -260,10 +352,10 @@ void outstyle_1(fclaw_global_t *glob) /* New time step, which should give a cfl close to the desired cfl. */ - double dt_new = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + double dt_new = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; if (!took_small_step) { - dt_minlevel = dt_new; + ctx->dt_minlevel = dt_new; } else { @@ -282,7 +374,7 @@ void outstyle_1(fclaw_global_t *glob) { if (n_inner % fclaw_opt->regrid_interval == 0) { - fclaw_global_infof("regridding at step %d\n",n); + fclaw_global_infof("regridding at step %d\n",ctx->n); fclaw_regrid(glob); } } @@ -291,8 +383,8 @@ void outstyle_1(fclaw_global_t *glob) /* Output file at every outer loop iteration */ fclaw_diagnostics_gather(glob, init_flag); glob->curr_time = t_curr; - iframe++; - fclaw_output_frame(glob,iframe); + ctx->iframe++; + fclaw_output_frame(glob,ctx->iframe); } } @@ -304,17 +396,25 @@ static void outstyle_2(fclaw2d_global_t *glob) } #endif +typedef struct outstyle3_ctx +{ + int iframe; + int n; + double dt_minlevel; +} outstyle3_ctx_t; + static void outstyle_3(fclaw_global_t *glob) { + outstyle3_ctx_t* ctx = FCLAW_ALLOC(outstyle3_ctx_t,1); fclaw_domain_t** domain = &glob->domain; int init_flag = 1; fclaw_diagnostics_gather(glob,init_flag); init_flag = 0; - int iframe = 0; - fclaw_output_frame(glob,iframe); + ctx->iframe = 0; + fclaw_output_frame(glob,ctx->iframe); const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); @@ -324,7 +424,7 @@ void outstyle_3(fclaw_global_t *glob) //fclaw2d_time_sync_reset(glob,fclaw_opt->minlevel,fclaw_opt->maxlevel,1); double t0 = 0; - double dt_minlevel = initial_dt; + ctx->dt_minlevel = initial_dt; glob->curr_time = t0; int nstep_outer = fclaw_opt->nout; int nstep_inner = fclaw_opt->nstep; @@ -347,11 +447,11 @@ void outstyle_3(fclaw_global_t *glob) } } - int n = 0; - double t_curr = t0; - while (n < nstep_outer) + ctx->n = 0; + double t_curr = glob->curr_time; + while (ctx->n < nstep_outer) { - double dt_step = dt_minlevel; + double dt_step = ctx->dt_minlevel; if (!fclaw_opt->subcycle && fclaw_opt->advance_one_step) { /* if domain->global_maxlevel < fclaw_opt->maxlevel, this choice @@ -389,7 +489,7 @@ void outstyle_3(fclaw_global_t *glob) level2print, (*domain)->global_minlevel, (*domain)->global_maxlevel, - n+1,dt_step,maxcfl_step, tc); + ctx->n+1,dt_step,maxcfl_step, tc); if (fclaw_opt->reduce_cfl & (maxcfl_step > fclaw_opt->max_cfl)) { @@ -398,7 +498,7 @@ void outstyle_3(fclaw_global_t *glob) fclaw_global_productionf(" WARNING : Maximum CFL exceeded; retaking time step\n"); restore_time_step(glob); - dt_minlevel = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + ctx->dt_minlevel = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; /* Go back to start of loop without incrementing step counter or current time. */ @@ -417,16 +517,16 @@ void outstyle_3(fclaw_global_t *glob) /* New time step, which should give a cfl close to the desired cfl. */ if (!fclaw_opt->use_fixed_dt) { - dt_minlevel = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + ctx->dt_minlevel = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; } - n++; /* Increment outer counter */ + ctx->n++; /* Increment outer counter */ if (fclaw_opt->regrid_interval > 0) { - if (n % nregrid_interval == 0) + if (ctx->n % nregrid_interval == 0) { - fclaw_global_infof("regridding at step %d\n",n); + fclaw_global_infof("regridding at step %d\n",ctx->n); fclaw_regrid(glob); } } @@ -436,13 +536,14 @@ void outstyle_3(fclaw_global_t *glob) //fclaw2d_diagnostics_gather(glob,init_flag); } - if (n % nstep_inner == 0) + if (ctx->n % nstep_inner == 0) { - iframe++; + ctx->iframe++; fclaw_diagnostics_gather(glob,init_flag); - fclaw_output_frame(glob,iframe); + fclaw_output_frame(glob,ctx->iframe); } } + FCLAW_FREE(ctx); } @@ -540,3 +641,8 @@ void fclaw_run(fclaw_global_t *glob) exit(0); } } + +void fclaw_run_vtables_initialize(fclaw_global_t *glob) +{ + fclaw_global_vtable_store(glob, OUTSTYLE1_CTX_VTABLE_KEY, &outstyle1_ctx_vt, NULL); +} From f00de4752d2f8d3974549828f8ae2b7f99a3417f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 18:02:10 -0600 Subject: [PATCH 17/76] add some restart functions --- src/fclaw_restart.c | 18 ++++++++---------- src/fclaw_restart.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 9dcac5d9a..2b98b19ff 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include typedef struct pack_iter @@ -68,11 +69,6 @@ set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat user_data->curr_index++; } -//TODO move this to header -void -fclaw_restart_from_file (fclaw_global_t * glob, - const char* restart_filename, - const char* partition_filename); /* ----------------------------------------------------------------------- Public interface @@ -133,16 +129,16 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) "Test partition write", glob->domain->d3, &errcode); - fclaw_restart_from_file(glob, filename, parition_filename); + //fclaw_restart_test_from_file(glob, filename, parition_filename); fclaw_global_productionf("RESTATRTT!!\n"); } void -fclaw_restart_from_file (fclaw_global_t * glob, - const char* restart_filename, - const char* partition_filename) +fclaw_restart_test_from_file (fclaw_global_t * glob, + const char* restart_filename, + const char* partition_filename) { fclaw_domain_reset(glob); @@ -190,7 +186,9 @@ fclaw_restart_from_file (fclaw_global_t * glob, sc_array_destroy(patches); fclaw3d_file_close(fc, &errcode); - fclaw_exchange_setup(glob,FCLAW_TIMER_OUTPUT); + + fclaw_exchange_setup(glob,FCLAW_TIMER_INIT); + fclaw_regrid_set_neighbor_types(glob); } diff --git a/src/fclaw_restart.h b/src/fclaw_restart.h index fd802f799..669671c2b 100644 --- a/src/fclaw_restart.h +++ b/src/fclaw_restart.h @@ -38,6 +38,37 @@ struct fclaw_global; /* This is a hack !! */ void fclaw_restart_output_frame(struct fclaw_global * glob, int iframe); +/** + * @brief Restarts the forestclaw simulation from a restart file. + * + * This function is responsible for restarting the simulation from a previously saved state. + * This is meant to be called fclaw_initalize() + * + * @param glob The global context + * @param restart_filename The filename of the restart file. + * @param partition_filename The filename of the partition file. + */ +void +fclaw_restart_from_file (struct fclaw_global * glob, + const char* restart_filename, + const char* partition_filename); + +/** + * @brief Tests the restart functionality by reading data from a restart file. + * + * This function is used to do an "in memory" restart test. + * It deletes the current domain and creates a new domain from the restart file, + * and overwrites the values in glob with the values from the restart file. + * + * @param glob The pointer to the global context + * @param restart_filename The filename of the restart file to read from. + * @param partition_filename The filename of the partition file to read from. + */ +void +fclaw_restart_test_from_file (struct fclaw_global * glob, + const char* restart_filename, + const char* partition_filename); + #ifdef __cplusplus #if 0 { From 6a6a4cc7932ef890081b9492aacfd5ddebb26ea2 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 18:05:54 -0600 Subject: [PATCH 18/76] add some restart options --- src/fclaw_options.c | 11 +++++++++++ src/fclaw_options.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/fclaw_options.c b/src/fclaw_options.c index da3b976f8..20e1c7c31 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -360,6 +360,17 @@ fclaw_register (fclaw_options_t* fclaw_opt, sc_options_t * opt) sc_options_add_double(opt, 0, "max-refinement-ratio", &fclaw_opt->max_refinement_ratio, 1.0, "Ratio of patches to refine before paritioning and continuing refinement. [1.0]"); + + sc_options_add_string(opt, 0, "restart-file", + &fclaw_opt->restart_file, + "","Filename of restart file. " + " If defined, a restart will be performed frome the specified file. [""]"); + + sc_options_add_string(opt, 0, "partition-file", + &fclaw_opt->partition_file, + "","Partition file associated with restart file. " + " This should be specified if a restart file is specified. [""]"); + fclaw_opt->is_registered = 1; fclaw_opt->is_unpacked = 0; diff --git a/src/fclaw_options.h b/src/fclaw_options.h index 35c004476..c7a36e63a 100644 --- a/src/fclaw_options.h +++ b/src/fclaw_options.h @@ -246,6 +246,9 @@ struct fclaw_options const char * regression_check; /**< filename of regression check values */ double max_refinement_ratio; /**< Maximum refinment ratio before partitioning and continuing refinement. */ + + const char * restart_file; /**< filename of restart file */ + const char * partition_file; /**< filename of partition file */ }; struct fclaw_global; From 3f241b6e364781135487a151df9b71e8423e651e Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 18:24:48 -0600 Subject: [PATCH 19/76] restart outstyle_2 with 3d/swirl appears to work --- src/fclaw_initialize.c | 108 +++++++++++++++++++++++-------------- src/fclaw_restart.c | 117 ++++++++++++++++++++++------------------- src/fclaw_run.c | 16 ++++-- 3 files changed, 142 insertions(+), 99 deletions(-) diff --git a/src/fclaw_initialize.c b/src/fclaw_initialize.c index 4fca9c294..2aba547f3 100644 --- a/src/fclaw_initialize.c +++ b/src/fclaw_initialize.c @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #if defined(_OPENMP) #include @@ -69,54 +70,17 @@ void cb_initialize (fclaw_domain_t *domain, } - -/* ----------------------------------------------------------------- - Public interface - ----------------------------------------------------------------- */ -void fclaw_initialize(fclaw_global_t *glob) +static +void build_initial_domain(fclaw_global_t *glob) { fclaw_domain_t** domain = &glob->domain; - int time_interp = 0; const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); - /* set partitioning */ - fclaw_domain_set_partitioning(*domain, fclaw_opt->partition_for_coarsening); - - /* This mapping context is needed by fortran mapping functions */ - fclaw_map_context_t *cont = glob->cont; - FCLAW_MAP_SET_CONTEXT(&cont); - - int maxthreads = 0; - -#if defined(_OPENMP) - maxthreads = omp_get_max_threads(); -#endif - - fclaw_global_essentialf("Max threads set to %d\n",maxthreads); - int minlevel = fclaw_opt->minlevel; int maxlevel = fclaw_opt->maxlevel; - /* Initialize all timers */ - int i; - for (i = 0; i < FCLAW_TIMER_COUNT; ++i) { - fclaw_timer_init (&glob->timers[i]); - } - - /* start timing */ - fclaw_domain_barrier (*domain); - fclaw_timer_start (&glob->timers[FCLAW_TIMER_WALLTIME]); - fclaw_timer_start (&glob->timers[FCLAW_TIMER_INIT]); - - /* User defined problem setup */ - fclaw_problem_setup(glob); - - /* set specific refinement strategy */ - fclaw_domain_set_refinement - (*domain, fclaw_opt->smooth_refine, fclaw_opt->smooth_level, - fclaw_opt->coarsen_delay); - + int time_interp = 0; /* ------------------------------------------------ Set up initial domain. @@ -241,6 +205,70 @@ void fclaw_initialize(fclaw_global_t *glob) (*domain)->global_maxlevel,0.0, time_interp,FCLAW_TIMER_INIT); } +} + +/* ----------------------------------------------------------------- + Public interface + ----------------------------------------------------------------- */ +void fclaw_initialize(fclaw_global_t *glob) +{ + fclaw_domain_t** domain = &glob->domain; + + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); + + /* set partitioning */ + fclaw_domain_set_partitioning(*domain, fclaw_opt->partition_for_coarsening); + + /* This mapping context is needed by fortran mapping functions */ + fclaw_map_context_t *cont = glob->cont; + FCLAW_MAP_SET_CONTEXT(&cont); + + int maxthreads = 0; + +#if defined(_OPENMP) + maxthreads = omp_get_max_threads(); +#endif + + fclaw_global_essentialf("Max threads set to %d\n",maxthreads); + + + /* Initialize all timers */ + int i; + for (i = 0; i < FCLAW_TIMER_COUNT; ++i) { + fclaw_timer_init (&glob->timers[i]); + } + + /* start timing */ + fclaw_domain_barrier (*domain); + fclaw_timer_start (&glob->timers[FCLAW_TIMER_WALLTIME]); + fclaw_timer_start (&glob->timers[FCLAW_TIMER_INIT]); + + /* User defined problem setup */ + fclaw_problem_setup(glob); + + /* set specific refinement strategy */ + fclaw_domain_set_refinement + (*domain, fclaw_opt->smooth_refine, fclaw_opt->smooth_level, + fclaw_opt->coarsen_delay); + + if(strcmp(fclaw_opt->restart_file,"") == 0) + { + // no restart file + build_initial_domain(glob); + } + else + { + const char* partition_filename = NULL; + if(strcmp(fclaw_opt->partition_file,"") != 0) + { + partition_filename = fclaw_opt->partition_file; + } + + fclaw_restart_from_file(glob, fclaw_opt->restart_file, + partition_filename); + } + + fclaw_diagnostics_initialize(glob); fclaw_locate_gauges(glob); diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 2b98b19ff..99bab101e 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -70,6 +70,65 @@ set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat user_data->curr_index++; } +static +void restart (fclaw_global_t * glob, + const char* restart_filename, + const char* partition_filename, + int timer) +{ + fclaw_domain_reset(glob); + + int errcode; + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + sc_array_t* partition = sc_array_new(sizeof(p4est_gloidx_t)); + char user_string[FCLAW3D_FILE_USER_STRING_BYTES]; + if(partition_filename != NULL) + { + fclaw3d_file_read_partition(partition_filename, user_string, glob->mpicomm, partition, &errcode); + + } + fclaw3d_domain_t * domain_3d; + fclaw3d_file_context_t *fc + = fclaw3d_file_open_read (restart_filename, user_string, glob->mpicomm, partition, &domain_3d, &errcode); + glob->domain = fclaw_domain_wrap_3d(domain_3d); + fclaw_domain_setup(glob, glob->domain); + sc_array_destroy(partition); + + sc_array_t globsize; + sc_array_init_size(&globsize, sizeof(size_t), 1); + fclaw3d_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); + size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); + sc_array_reset(&globsize); + + sc_array_t glob_buffer; + sc_array_init_size(&glob_buffer, glob_packsize, 1); + fclaw3d_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); + + fclaw_global_unpack((char *) sc_array_index(&glob_buffer, 0), glob); + + sc_array_reset(&glob_buffer); + + + size_t packsize = patch_vt->partition_packsize(glob); + sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); + + fclaw3d_file_read_array(fc, user_string, packsize, patches, &errcode); + + pack_iter_t user; + user.glob = glob; + user.curr_index = 0; + user.patches = patches; + user.packsize = packsize; + user.patch_vt = patch_vt; + fclaw_domain_iterate_patches(glob->domain, set_patches, &user); + + sc_array_destroy(patches); + + fclaw3d_file_close(fc, &errcode); + + fclaw_exchange_setup(glob,timer); + fclaw_regrid_set_neighbor_types(glob); +} /* ----------------------------------------------------------------------- Public interface -------------------------------------------------------------------- */ @@ -136,59 +195,9 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) void -fclaw_restart_test_from_file (fclaw_global_t * glob, - const char* restart_filename, - const char* partition_filename) +fclaw_restart_from_file (fclaw_global_t * glob, + const char* restart_filename, + const char* partition_filename) { - fclaw_domain_reset(glob); - - int errcode; - fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); - sc_array_t* partition = sc_array_new(sizeof(p4est_gloidx_t)); - char user_string[FCLAW3D_FILE_USER_STRING_BYTES]; - if(partition_filename != NULL) - { - fclaw3d_file_read_partition(partition_filename, user_string, glob->mpicomm, partition, &errcode); - - } - fclaw3d_domain_t * domain_3d; - fclaw3d_file_context_t *fc - = fclaw3d_file_open_read (restart_filename, user_string, glob->mpicomm, partition, &domain_3d, &errcode); - glob->domain = fclaw_domain_wrap_3d(domain_3d); - fclaw_domain_setup(glob, glob->domain); - sc_array_destroy(partition); - - sc_array_t globsize; - sc_array_init_size(&globsize, sizeof(size_t), 1); - fclaw3d_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); - size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); - sc_array_reset(&globsize); - - sc_array_t glob_buffer; - sc_array_init_size(&glob_buffer, glob_packsize, 1); - fclaw3d_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); - sc_array_reset(&glob_buffer); - - - size_t packsize = patch_vt->partition_packsize(glob); - sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); - - fclaw3d_file_read_array(fc, user_string, packsize, patches, &errcode); - - pack_iter_t user; - user.glob = glob; - user.curr_index = 0; - user.patches = patches; - user.packsize = packsize; - user.patch_vt = patch_vt; - fclaw_domain_iterate_patches(glob->domain, set_patches, &user); - - sc_array_destroy(patches); - - fclaw3d_file_close(fc, &errcode); - - fclaw_exchange_setup(glob,FCLAW_TIMER_INIT); - fclaw_regrid_set_neighbor_types(glob); + restart(glob, restart_filename, partition_filename, FCLAW_TIMER_INIT); } - - diff --git a/src/fclaw_run.c b/src/fclaw_run.c index e8a8ebab7..46fe4bfa7 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -118,6 +118,7 @@ struct outstyle1_ctx int initalized; int iframe; int n; + int n_inner; double dt_minlevel; } outstyle1_ctx_t; @@ -129,6 +130,7 @@ size_t packsize_outstyle1_ctx(void *user) size += sizeof(ctx->initalized); size += sizeof(ctx->iframe); size += sizeof(ctx->n); + size += sizeof(ctx->n_inner); size += sizeof(ctx->dt_minlevel); return size; } @@ -141,6 +143,7 @@ size_t pack_outstyle1_ctx(void *user, char *buffer) buffer += fclaw_pack_int(ctx->initalized,buffer); buffer += fclaw_pack_int(ctx->iframe,buffer); buffer += fclaw_pack_int(ctx->n,buffer); + buffer += fclaw_pack_int(ctx->n_inner,buffer); buffer += fclaw_pack_double(ctx->dt_minlevel,buffer); return buffer - buffer_start; } @@ -153,6 +156,7 @@ size_t unpack_outstyle1_ctx(char* buffer , void *user) buffer += fclaw_unpack_int(buffer,&ctx->initalized); buffer += fclaw_unpack_int(buffer,&ctx->iframe); buffer += fclaw_unpack_int(buffer,&ctx->n); + buffer += fclaw_unpack_int(buffer,&ctx->n_inner); buffer += fclaw_unpack_double(buffer,&ctx->dt_minlevel); return buffer - buffer_start; } @@ -191,9 +195,12 @@ fclaw_packing_vtable_t outstyle1_ctx_vt = static void outstyle_1(fclaw_global_t *glob) { + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); outstyle1_ctx_t* ctx = (outstyle1_ctx_t*) fclaw_global_get_attribute(glob, OUTSTYLE1_CTX_ATTRIBUTE_KEY); if(ctx == NULL) { + FCLAW_ASSERT(strcmp(fclaw_opt->restart_file,"") == 0); + ctx = (outstyle1_ctx_t*) outstyle1_ctx_new(); fclaw_global_attribute_store(glob, OUTSTYLE1_CTX_ATTRIBUTE_KEY, @@ -214,7 +221,6 @@ void outstyle_1(fclaw_global_t *glob) fclaw_output_frame(glob,ctx->iframe); } - const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); double final_time = fclaw_opt->tfinal; int nout = fclaw_opt->nout; @@ -229,10 +235,10 @@ void outstyle_1(fclaw_global_t *glob) double dt_outer = (final_time-t0)/((double) nout); double t_curr = glob->curr_time; - int n_inner = 0; if(!ctx->initalized) { + ctx->n_inner = 0; ctx->n = 0; } ctx->initalized = 1; @@ -306,7 +312,7 @@ void outstyle_1(fclaw_global_t *glob) fclaw_opt->minlevel, (*domain)->global_minlevel, (*domain)->global_maxlevel, - n_inner+1,dt_step, + ctx->n_inner+1,dt_step, maxcfl_step, tc); if ((maxcfl_step > fclaw_opt->max_cfl) & fclaw_opt->reduce_cfl) @@ -328,7 +334,7 @@ void outstyle_1(fclaw_global_t *glob) } /* We are happy with this step */ - n_inner++; + ctx->n_inner++; t_curr += dt_step; @@ -372,7 +378,7 @@ void outstyle_1(fclaw_global_t *glob) if (fclaw_opt->regrid_interval > 0) { - if (n_inner % fclaw_opt->regrid_interval == 0) + if (ctx->n_inner % fclaw_opt->regrid_interval == 0) { fclaw_global_infof("regridding at step %d\n",ctx->n); fclaw_regrid(glob); From af52eb1990bb0c04491ee82be91fca8993904863 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 19:05:34 -0600 Subject: [PATCH 20/76] add dim_ind fclaw_file wrapper --- src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/fclaw_file.c | 308 ++++++++++++++++++++++++++ src/fclaw_file.h | 514 ++++++++++++++++++++++++++++++++++++++++++++ src/fclaw_restart.c | 2 +- 5 files changed, 827 insertions(+), 1 deletion(-) create mode 100644 src/fclaw_file.c create mode 100644 src/fclaw_file.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bfe45c71b..ed94410f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,6 +44,7 @@ add_library(forestclaw_c OBJECT fclaw_edge_neighbors.c fclaw_face_neighbors.c fclaw_farraybox.cpp + fclaw_file.c fclaw2d_convenience.c fclaw2d_output_tikz.c fclaw2d_file.c @@ -131,6 +132,7 @@ install(FILES fclaw_map_query.h fclaw_map_query_defs.h fclaw_diagnostics.h + fclaw_file.h forestclaw2d.h fp_exception_glibc_extension.h fclaw2d_convenience.h diff --git a/src/Makefile.am b/src/Makefile.am index d2958918c..467852f3e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ libforestclaw_installed_headers = \ src/fclaw_map_query.h \ src/fclaw_map_query_defs.h \ src/fclaw_diagnostics.h \ + src/fclaw_file.h \ src/forestclaw2d.h \ src/fclaw2d_convenience.h \ src/fp_exception_glibc_extension.h \ @@ -109,6 +110,7 @@ libforestclaw_compiled_sources = \ src/fclaw_edge_neighbors.c \ src/fclaw_face_neighbors.c \ src/fclaw_farraybox.cpp \ + src/fclaw_file.c \ src/fclaw2d_convenience.c \ src/fclaw2d_output_tikz.c \ src/fclaw2d_file.c \ diff --git a/src/fclaw_file.c b/src/fclaw_file.c new file mode 100644 index 000000000..c4a1114aa --- /dev/null +++ b/src/fclaw_file.c @@ -0,0 +1,308 @@ +/* +Copyright (c) 2012 Carsten Burstedde, Donna Calhoun +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include + +struct fclaw_file_context +{ + int refine_dim; + fclaw2d_file_context_t *d2; + fclaw3d_file_context_t *d3; +}; + +static fclaw_file_context_t *wrap_file_2d(fclaw2d_file_context_t *d2) +{ + fclaw_file_context_t *fc = FCLAW_ALLOC (fclaw_file_context_t, 1); + fc->refine_dim = 0; + fc->d2 = d2; + fc->d3 = NULL; + return fc; +} + +static fclaw_file_context_t *wrap_file_3d(fclaw3d_file_context_t *d3) +{ + fclaw_file_context_t *fc = FCLAW_ALLOC (fclaw_file_context_t, 1); + fc->refine_dim = 1; + fc->d2 = NULL; + fc->d3 = d3; + return fc; +} + +fclaw_file_context_t *fclaw_file_open_write (const char *filename, + const char *user_string, + fclaw_domain_t * domain, + int *errcode) +{ + if(domain->refine_dim == 2) + { + fclaw2d_file_context_t *d2 = fclaw2d_file_open_write (filename, user_string, + domain->d2, errcode); + return wrap_file_2d(d2); + } + else if(domain->refine_dim == 3) + { + fclaw3d_file_context_t *d3 = fclaw3d_file_open_write (filename, user_string, + domain->d3, errcode); + return wrap_file_3d(d3); + } + else + { + SC_ABORT_NOT_REACHED (); + } +} + +int fclaw_file_write_partition (const char *filename, + const char *user_string, + fclaw_domain_t * domain, int *errcode) +{ + if(domain->refine_dim == 2) + { + return fclaw2d_file_write_partition (filename, user_string, domain->d2, errcode); + } + else if(domain->refine_dim == 3) + { + return fclaw3d_file_write_partition (filename, user_string, domain->d3, errcode); + } + else + { + SC_ABORT_NOT_REACHED (); + } +} + +fclaw_file_context_t *fclaw_file_write_block (fclaw_file_context_t * + fc, const char *user_string, + size_t block_size, + sc_array_t * block_data, + int *errcode) +{ + if(fc->refine_dim == 0) + { + return wrap_file_2d(fclaw2d_file_write_block (fc->d2, user_string, + block_size, block_data, errcode)); + } + else if(fc->refine_dim == 1) + { + return wrap_file_3d(fclaw3d_file_write_block (fc->d3, user_string, + block_size, block_data, errcode)); + } + else + { + SC_ABORT_NOT_REACHED (); + } +} + +fclaw_file_context_t *fclaw_file_write_array (fclaw_file_context_t * + fc, const char *user_string, + size_t patch_size, + sc_array_t * patch_data, + int *errcode) +{ + if(fc->refine_dim == 0) + { + return wrap_file_2d(fclaw2d_file_write_array (fc->d2, user_string, + patch_size, patch_data, errcode)); + } + else if(fc->refine_dim == 1) + { + return wrap_file_3d(fclaw3d_file_write_array (fc->d3, user_string, + patch_size, patch_data, errcode)); + } + else + { + SC_ABORT_NOT_REACHED (); + } +} + +int fclaw_file_read_partition (int refine_dim, + const char *filename, char *user_string, + sc_MPI_Comm mpicomm, sc_array_t * partition, + int *errcode) +{ + if(refine_dim == 2) + { + return fclaw2d_file_read_partition (filename, user_string, mpicomm, partition, errcode); + } + else if(refine_dim == 3) + { + return fclaw3d_file_read_partition (filename, user_string, mpicomm, partition, errcode); + } + else + { + fclaw_abortf("Invalid refine_dim %d\n", refine_dim); + } +} + +fclaw_file_context_t *fclaw_file_open_read (int refine_dim, + const char *filename, + char *user_string, + sc_MPI_Comm mpicomm, + sc_array_t * partition, + fclaw_domain_t ** domain, + int *errcode) +{ + if(refine_dim == 2) + { + fclaw2d_domain_t *new_domain; + fclaw2d_file_context_t *d2 = fclaw2d_file_open_read (filename, user_string, + mpicomm, partition, &new_domain, errcode); + + *domain = fclaw_domain_wrap_2d(new_domain); + return wrap_file_2d(d2); + } + else if(refine_dim == 3) + { + fclaw3d_domain_t *new_domain; + fclaw3d_file_context_t *d3 = fclaw3d_file_open_read (filename, user_string, + mpicomm, partition, &new_domain, errcode); + *domain = fclaw_domain_wrap_3d(new_domain); + return wrap_file_3d(d3); + } + else + { + fclaw_abortf("Invalid refine_dim %d\n", refine_dim); + } +} + +fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * + fc, char *user_string, + size_t block_size, + sc_array_t * block_data, + int *errcode) +{ + if(fc->refine_dim == 0) + { + fclaw2d_file_context_t* retval; + retval = fclaw2d_file_read_block (fc->d2, user_string, + block_size, block_data, errcode); + if(retval == NULL) + { + return NULL; + } + else + { + FCLAW_ASSERT(fc->d2 == retval); + return fc; + } + } + else if(fc->refine_dim == 1) + { + fclaw3d_file_context_t* retval; + retval = fclaw3d_file_read_block (fc->d3, user_string, + block_size, block_data, errcode); + if(retval == NULL) + { + return NULL; + } + else + { + FCLAW_ASSERT(fc->d3 == retval); + return fc; + } + } + else + { + SC_ABORT_NOT_REACHED (); + } + +} + +fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * + fc, char *user_string, + size_t patch_size, + sc_array_t * patch_data, + int *errcode) +{ + if(fc->refine_dim == 0) + { + fclaw2d_file_context_t* retval; + retval = fclaw2d_file_read_array (fc->d2, user_string, + patch_size, patch_data, errcode); + if(retval == NULL) + { + return NULL; + } + else + { + FCLAW_ASSERT(fc->d2 == retval); + return fc; + } + } + else if(fc->refine_dim == 1) + { + fclaw3d_file_context_t* retval; + retval = fclaw3d_file_read_array (fc->d3, user_string, + patch_size, patch_data, errcode); + if(retval == NULL) + { + return NULL; + } + else + { + FCLAW_ASSERT(fc->d3 == retval); + return fc; + } + } + else + { + SC_ABORT_NOT_REACHED (); + } +} + +int fclaw_file_close (fclaw_file_context_t * fc, int *errcode) +{ + int retval; + if(fc->refine_dim == 0) + { + retval = fclaw2d_file_close (fc->d2, errcode); + } + else if(fc->refine_dim == 1) + { + retval = fclaw3d_file_close (fc->d3, errcode); + } + else + { + SC_ABORT_NOT_REACHED (); + } + FCLAW_FREE(fc); + return retval; +} + +int fclaw_file_error_string (int refine_dim, int errcode, char *string, int *resultlen) +{ + if(refine_dim == 2) + { + return fclaw2d_file_error_string (errcode, string, resultlen); + } + else if(refine_dim == 3) + { + return fclaw3d_file_error_string (errcode, string, resultlen); + } + else + { + fclaw_abortf("Invalid refine_dim %d\n", refine_dim); + } +} diff --git a/src/fclaw_file.h b/src/fclaw_file.h new file mode 100644 index 000000000..5bbdf4390 --- /dev/null +++ b/src/fclaw_file.h @@ -0,0 +1,514 @@ +/* +Copyright (c) 2012 Carsten Burstedde, Donna Calhoun +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** \file fclaw_file.h + * Routines for parallel IO for \ref fclaw_domain_t and generic data. + * + * Principle: All files are associated with a single domain, i.e. one can + * write only one domain to one file. + */ + +#ifndef FCLAW_FILE_H +#define FCLAW_FILE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} /* need this because indent is dumb */ +#endif +#endif + +#define FCLAW_FILE_USER_STRING_BYTES 48 /**< number of user string bytes */ +#define FCLAW_FILE_MAX_BLOCK_SIZE ((1000L * 1000L * 1000L * 1000L * 10L) - 1L) /**< maximal data size of a block */ +#define FCLAW_FILE_MAX_FIELD_ENTRY_SIZE ((1000L * 1000L * 1000L * 1000L * 10L) - 1L) /**< maximal data size per field entry*/ + +/** Error values for fclaw_file functions. + * In the future we may add further error codes. Therefore, the error codes + * should only be used by the enum but not by the explicit numeric values since + * these explicit numeric values may change. + */ +typedef enum fclaw_file_error +{ + FCLAW_FILE_ERR_SUCCESS = 0, /**< file function completed with success */ + FCLAW_FILE_ERR_FILE = sc_MPI_ERR_LASTCODE, /**< invalid file handle */ + FCLAW_FILE_ERR_NOT_SAME, /**< collective arg not identical */ + FCLAW_FILE_ERR_AMODE, /**< access mode error */ + FCLAW_FILE_ERR_NO_SUCH_FILE, /**< file does not exist */ + FCLAW_FILE_ERR_FILE_EXIST, /**< file exists already */ + FCLAW_FILE_ERR_BAD_FILE, /**< invalid file name */ + FCLAW_FILE_ERR_ACCESS, /**< permission denied */ + FCLAW_FILE_ERR_NO_SPACE, /**< not enough space */ + FCLAW_FILE_ERR_QUOTA, /**< quota exceeded */ + FCLAW_FILE_ERR_READ_ONLY, /**< read only file (system) */ + FCLAW_FILE_ERR_IN_USE, /**< file currently open by other process */ + FCLAW_FILE_ERR_IO, /**< other I/O error */ + FCLAW_FILE_ERR_FORMAT, /**< read file has a wrong format */ + FCLAW_FILE_ERR_SECTION_TYPE, /**< a valid non-matching section type */ + FCLAW_FILE_ERR_CONN, /**< invalid serialized connectivity data */ + FCLAW_FILE_ERR_P4EST, /**< invalid p4est data */ + FCLAW_FILE_ERR_IN_DATA, /**< input data of file function is invalid */ + FCLAW_FILE_ERR_COUNT, /**< read or write count error that was not + classified as a format error */ + FCLAW_FILE_ERR_DIM, /**< file has wrong dimension */ + FCLAW_FILE_ERR_UNKNOWN, /**< unknown error */ + FCLAW_FILE_ERR_PART, /**< invalid partition data */ + FCLAW_FILE_ERR_NOT_IMPLEMENTED, /**< functionality is not implemented */ + FCLAW_FILE_ERR_LASTCODE /**< to define own error codes for + a higher level application + that is using fclaw_file + functions */ +} +fclaw_file_error_t; + +/** Opaque context used for writing a fclaw2d data file. */ +typedef struct fclaw_file_context fclaw_file_context_t; + +/** Create and open a file that is associated with the given domain structure. + * + * This is a collective function call that overwrites the file if it exists + * already. This function writes a header with metadata of the underlying + * p4est of the passed \b domain to the file. In addition, the passed \b domain + * is written to the file. + * + * The opened file can be used to write to the file using the functions + * \ref fclaw_file_write_block, \ref fclaw_file_write_array and + * potentially other functions operating on \ref fclaw_file_context_t that + * may be implemented on the top of the current fclaw_file routines. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in] filename Path to parallel file that is to be created. + * \param [in] user_string A NUL-terminated user string that is written to the + * file header having FCLAW_FILE_USER_STRING_BYTES + * bytes including the NUL-termination. Shorter + * user strings are padded by spaces in the file header. + * Too long user strings result in an error with the + * error code \ref FCLAW_FILE_ERR_IN_DATA. + * \param [in] domain The underlying p4est is used for the metadata of the + * the created file and the \b domain is written to the + * file. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return Newly allocated context to continue writing and + * eventually closing the file. NULL in case of error. + */ +fclaw_file_context_t *fclaw_file_open_write (const char *filename, + const char *user_string, + fclaw_domain_t * domain, + int *errcode); + +/** Write the partition of a domain to a partition file. + * + * This function writes the partition of the passed \b domain to a partition + * file. The user can read the partition to an array using \ref + * fclaw_file_read_partition and then pass the read array to \ref + * fclaw_file_open_read to use the read partition. + * + * The function and all its parameters are collective. + * + * This function does not abort on MPI I/O errors but returns -1. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in] filename Path to partition file that is to be created. + * \param [in] user_string A NUL-terminated user string that is written to + * the partition file header having \ref + * FCLAW_FILE_USER_STRING_BYTES bytes including + * the NUL-termination. Shorter user strings are + * padded by spaces in the file header. + * Too long user strings result in an error with the + * error code \ref FCLAW_FILE_ERR_IN_DATA. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return 0 for a successful write of the partition file. + * -1 in case of an error. + */ +int fclaw_file_write_partition (const char *filename, + const char *user_string, + fclaw_domain_t * domain, int *errcode); + +/** Write a serial data block to an opened parallel file. + * + * This is a collective function. + * This function writes a serial data block to the opened file. + * + * The number of block bytes must be less or equal \ref + * FCLAW_FILE_MAX_BLOCK_SIZE. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in, out] fc Context previously created by \ref + * fclaw_file_open_write. It keeps track + * of the data sets written one after another. + * \param [in] user_string A NUL-terminated user string that is written to + * the section header having + * FCLAW_FILE_USER_STRING_BYTES bytes including + * the NUL-termination. Shorter user strings are + * padded by spaces in the section header. Too long + * user strings result in an error with the error + * code \ref FCLAW_FILE_ERR_IN_DATA. + * \param [in] block_size The size of the block in bytes. May be equal to + * 0. In this case the section header and the padding + * is still written. This function returns the passed + * \b fc parameter and sets errcode to \ref + * FCLAW_FILE_ERR_SUCCESS if it is called for + * \b block_size == 0. + * \param [in] block_data A sc_array with one element and element size + * equal to \b block_size. + * The array points to the block data. The user is + * responsible for the validality of the block + * data. block_data can be NULL if \b block_size == 0. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return Return a pointer to input context or NULL in case + * of errors that does not abort the program. + * In case of error the file is tried to close + * and \b fc is freed. + */ +fclaw_file_context_t *fclaw_file_write_block (fclaw_file_context_t * + fc, const char *user_string, + size_t block_size, + sc_array_t * block_data, + int *errcode); + +/** Write per-patch data to a parallel output file. + * + * This is a collective function. + * This function writes the per-patch data with respect the domain that was passed + * to the \ref fclaw_file_open_write for opening the file. + * + * The per-patch data is written in parallel according to the partition of the + * domain and the underlying p4est, respectively. + * The data size per patch must be fixed. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in, out] fc Context previously created by \ref + * fclaw_file_open_write. It keeps track + * of the data sets written one after another. + * \param [in] user_string A NUL-terminated user string that is written to + * the section header having + * FCLAW_FILE_USER_STRING_BYTES bytes including + * the NUL-termination. Shorter user strings are + * padded by spaces in the section header. Too long + * user strings result in an error with the error + * code \ref FCLAW_FILE_ERR_IN_DATA. + * \param [in] patch_size The number of bytes per patch. This number + * must coincide with \b patch_data->elem_size. + * \param [in] patch_data An array of the length number of local patches + * with the element size equal to sizeof (sc_array_t). + * This means each element of \b patch_data must be + * a sc_array. These sc_arrays must have an element + * size of \b patch_size and store the actual + * patch data. This memory layout enables the user + * to write by indirect addressing, i.e. to write + * non-contigous patch data. The patch data is + * expected to be stored according to the Morton + * order of the patches. For \b patch_size == 0 + * the function writes an empty array. The section + * header and the padding is still written. + * In this case the function passes successfully and + * \b errcode is set to \ref FCLAW_FILE_ERR_SUCCESS. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return Return a pointer to input context or NULL in case + * of errors that does not abort the program. + * In case of error the file is tried to close + * and \b fc is freed. + */ +fclaw_file_context_t *fclaw_file_write_array (fclaw_file_context_t * + fc, const char *user_string, + size_t patch_size, + sc_array_t * patch_data, + int *errcode); + +/** Read a partition array from file. + * + * This function reads the partition array, i.e. the global first patch + * array from a partition file that was written using + * \ref fclaw_file_write_partition. The read partition can be passed to + * \ref fclaw_file_open_read. + * + * This function guarantees that on successful output the read partition + * is valid in the sense that the partition array has 0 as first entry and is + * non-decreasing. + * + * The function and all its parameters are collective. + * + * This function does not abort on MPI I/O errors but returns -1. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in] refine_dim The refine dimension. + * \param [in] filename The path to the partition file. + * \param [out] user_string At least \ref FCLAW_FILE_USER_STRING_BYTES + * bytes. The user string is written + * to the passed array including padding spaces + * and a trailing NUL-termination. + * \param [in] mpicomm The MPI communicator is required to synchronize + * the \b errcode and the output array \b partition. + * It is important to notice that \b partition is + * only available on MPI ranks that are part of the + * passed \b mpicomm. Therefore, \b mpicomm should + * coincide with the mpicomm parameter of \ref + * fclaw_file_open_read to ensure that the + * partition parameter of \ref + * fclaw_file_open_read is collectivly available. + * \param [out] partition A sc_array with element size equals to + * sizeof (p4est_gloidx_t). On successful output + * the array is filled with the read partition. + * In case of an error, the function does not + * guarantee that \b partition stays untouched + * but it is guaranteed that the user is not + * required to call \ref sc_array_reset on + * \b partition. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return 0 for a successful read of the partition file. + * -1 in case of an error. + */ +int fclaw_file_read_partition (int refine_dim, + const char *filename, char *user_string, + sc_MPI_Comm mpicomm, sc_array_t * partition, + int *errcode); + +/** Open a file for reading and read the stored domain. + * The user string is broadcasted to all ranks after reading. + * The file must exist and be at least of the size of the file header. + * + * This is a collective function. + * If the file has wrong metadata the function reports the error using + * \ref fclaw_errorf, collectively closes the file and deallocates + * the file context. In this case the function returns NULL on all ranks. + * The wrong file format or a wrong file header causes \ref FCLAW_FILE_ERR_FORMAT + * as errcode. + * + * After calling this function the user can continue reading the opened file + * by calling \ref fclaw_file_read_block, \ref fclaw_file_read_array and + * potentially other functions operating on \ref fclaw_file_context_t that + * may be implemented on the top of the current fclaw_file routines. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in] refine_dim The refinement dimension. + * \param [in] filename The path to the file that is opened. + * \param [out] user_string At least \ref FCLAW_FILE_USER_STRING_BYTES + * bytes. The user string is written + * to the passed array including padding spaces + * and a trailing NUL-termination. + * \param [in] mpicomm MPI communicator that is used to read the file and + * is used for potential other reading operations of + * MPI communicator dependent objects. + * \param [in] partition A sc_array of the size of number of MPI ranks + 1 + * with sizeof (p4est_gloidx_t) as element size + * or NULL. + * The sc_array must contain a valid partition, i.e. + * the first element is 0, the array is + * non-decreasing and the last array entry equals + * the number of global patches of the domain in + * the file pointed to by \b filename. + * If any of these conditions is violated, the + * function returns NULL and set \b errcode to + * \ref FCLAW_FILE_ERR_PART. + * The user can pass NULL for using the uniform + * partition with respect to the quadrant count. + * In both cases the respective partition, either + * read or computed, is used for the parallel I/O + * operations and stored in the returned \b domain. + * The user can use \ref fclaw_file_read_partition + * to read a partition array from file. + * \param [out] domain Newly allocated domain that is read from the file. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return Newly allocated context to continue reading + * and eventually closing the file. NULL in + * case of error. + */ +fclaw_file_context_t *fclaw_file_open_read (int refine_dim, + const char *filename, + char *user_string, + sc_MPI_Comm mpicomm, + sc_array_t * partition, + fclaw_domain_t ** domain, + int *errcode); + +/** Read a serial data block from an opened file. + * + * This is a collective function. + * + * This function requires an opened file context. + * + * The passed \b block_size is compared to the block size stored in the file. + * If the values do not equal each other, the function reports details, closes + * and deallocates the file context. The return value in this case is NULL. + * If the data block section header information is not matching the passed + * parameters the function sets \ref FCLAW_FILE_ERR_FORMAT for errcode. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in] fc Context previously created by \ref + * fclaw_file_open_read. It keeps track + * of the data sets read one after another. + * \param [out] user_string At least \ref FCLAW_FILE_USER_STRING_BYTES + * bytes. The user string is written + * to the passed array including padding spaces + * and a trailing NUL-termination. + * \param [in] block_size The size of the header that is read. + * \param [in, out] block_data \b block_size allocated bytes in an sc_array + * with one element and \b block_size as element + * size. This data will be filled with the block + * data from the file. If this is NULL it means that + * the current header block is skipped and the + * internal file pointer of the file context is + * set to the next data section. If the current data + * section is not a data block, the file is closed + * and the file context is deallocated. Furthermore, + * in this case the function returns NULL and sets + * errcode to \ref FCLAW_FILE_ERR_FORMAT. In case + * of skipping the data block section \b block_size + * needs also to coincide with the data block size + * given in the file. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return Return a pointer to input context or NULL in case + * of errors that does not abort the program. + * In case of error the file is tried to close + * and \b fc is freed. + */ +fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * + fc, char *user_string, + size_t block_size, + sc_array_t * block_data, + int *errcode); + +/** Read per-patch data from a parallel output file. + * + * This is a collective function. + * The function closes and deallocates the file context and returns NULL + * if the bytes the user wants to read exceed the given file and/or + * the element size of the array given by \b patch_data->elem_size does not + * coincide with the element size according to the array metadata given in + * the file. + * + * The data is read in parallel using the partition of the domain (and the + * underlying p4est) that is associated with the passed file context in the + * sense that the file context was created using the respective domain. + * The data size per patch must be fixed. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in] fc Context previously created by \ref + * fclaw_file_open_read. It keeps track + * of the data sets read one after another. + * \param [out] user_string At least \ref FCLAW_FILE_USER_STRING_BYTES + * bytes. The user string is written + * to the passed array including padding spaces + * and a trailing NUL-termination. + * \param [in] patch_size The number of bytes per patch. This number + * must coincide with \b patch_data->elem_size. + * \param [in,out] patch_data An array of the length number of local patches + * with the element size equal to sizeof (sc_array_t). + * This means each element of \b patch_data must be + * a sc_array. These sc_arrays must have an element + * size of \b patch_size. This memory layout enables + * the user to read by indirect addressing, i.e. to + * read into non-contigous patch data. The patch data + * is read according to the Morton order of the patches. + * \b patch_size must coincide with the section data + * size in the file. \b patch_data == NULL means that + * the data is skipped and the internal file pointer + * is incremented. In the case of skipping + * \b patch_size is still checked using the + * corresponding value read from the file. The data + * is read using the partition of patches given by the + * domain that is associated to \b fc. + * \param [out] errcode An errcode that can be interpreted by + * \ref fclaw_file_error_string. + * \return Return a pointer to input context or NULL in case + * of errors that does not abort the program. + * In case of error the file is tried to close + * and \b fc is freed. + */ +fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * + fc, char *user_string, + size_t patch_size, + sc_array_t * patch_data, + int *errcode); + +/** Close a file opened for parallel write/read and free the context. + * + * This is a collective function. + * + * This function does not abort on MPI I/O errors but returns NULL. + * Without MPI I/O the function may abort on file system dependent + * errors. + * + * \param [in,out] fc Context previously created by \ref + * fclaw_file_open_write or \ref + * fclaw_file_open_read. Is freed. + * \param [out] errcode An errcode that can be interpreted by \ref + * fclaw_file_error_string. + * \return 0 for a successful call and -1 in case of + * an error. See also errcode argument. + */ +int fclaw_file_close (fclaw_file_context_t * fc, int *errcode); + +/** Turn fclaw_file errcode into a string. + * + * \param [in] refine_dim The refinement dimension. + * \param [in] errcode An errcode that is output by a + * fclaw_file function. + * \param [in,out] string At least sc_MPI_MAX_ERROR_STRING bytes. + * \param [out] resultlen Length of string on return. + * \return 0 on success or + * something else on invalid arguments. + */ +int fclaw_file_error_string (int refine_dim, int errcode, char *string, int *resultlen); + +#ifdef __cplusplus +#if 0 +{ /* need this because indent is dumb */ +#endif +} +#endif + +#endif /* !FCLAW_FILE_H */ diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 99bab101e..194bc18d1 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include +#include #include #include #include From 20193879e0b5a0965547f5347813bb8b0e785781 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 19:09:11 -0600 Subject: [PATCH 21/76] move fclaw_restart to fclaw_file interface --- src/fclaw_restart.c | 52 ++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 194bc18d1..39f0930d4 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -76,6 +76,7 @@ void restart (fclaw_global_t * glob, const char* partition_filename, int timer) { + int refine_dim = glob->domain->refine_dim; fclaw_domain_reset(glob); int errcode; @@ -84,25 +85,36 @@ void restart (fclaw_global_t * glob, char user_string[FCLAW3D_FILE_USER_STRING_BYTES]; if(partition_filename != NULL) { - fclaw3d_file_read_partition(partition_filename, user_string, glob->mpicomm, partition, &errcode); - + fclaw_file_read_partition(refine_dim, + partition_filename, + user_string, + glob->mpicomm, + partition, + &errcode); } - fclaw3d_domain_t * domain_3d; - fclaw3d_file_context_t *fc - = fclaw3d_file_open_read (restart_filename, user_string, glob->mpicomm, partition, &domain_3d, &errcode); - glob->domain = fclaw_domain_wrap_3d(domain_3d); + + fclaw_file_context_t *fc + = fclaw_file_open_read (refine_dim, + restart_filename, + user_string, + glob->mpicomm, + partition, + &glob->domain, + &errcode); + fclaw_domain_setup(glob, glob->domain); + sc_array_destroy(partition); sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); - fclaw3d_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); + fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); sc_array_reset(&globsize); sc_array_t glob_buffer; sc_array_init_size(&glob_buffer, glob_packsize, 1); - fclaw3d_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); + fclaw_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); fclaw_global_unpack((char *) sc_array_index(&glob_buffer, 0), glob); @@ -112,7 +124,7 @@ void restart (fclaw_global_t * glob, size_t packsize = patch_vt->partition_packsize(glob); sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); - fclaw3d_file_read_array(fc, user_string, packsize, patches, &errcode); + fclaw_file_read_array(fc, user_string, packsize, patches, &errcode); pack_iter_t user; user.glob = glob; @@ -124,7 +136,7 @@ void restart (fclaw_global_t * glob, sc_array_destroy(patches); - fclaw3d_file_close(fc, &errcode); + fclaw_file_close(fc, &errcode); fclaw_exchange_setup(glob,timer); fclaw_regrid_set_neighbor_types(glob); @@ -144,22 +156,22 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) snprintf(parition_filename, BUFSIZ, "fort_frame_%04d.partition", iframe); int errcode; - fclaw3d_file_context_t *fc - = fclaw3d_file_open_write (filename, "ForestClaw data file", - glob->domain->d3, &errcode); + fclaw_file_context_t *fc + = fclaw_file_open_write (filename, "ForestClaw data file", + glob->domain, &errcode); size_t glob_packsize = fclaw_global_packsize(glob); sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); *((size_t*) sc_array_index(&globsize, 0)) = glob_packsize; - fclaw3d_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); + fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); sc_array_reset(&globsize); sc_array_t glob_buffer; sc_array_init_size(&glob_buffer, glob_packsize, 1); fclaw_global_pack(glob,(char *) sc_array_index(&glob_buffer, 0)); - fclaw3d_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); + fclaw_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); sc_array_reset(&glob_buffer); size_t packsize = patch_vt->partition_packsize(glob); @@ -173,7 +185,7 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) fclaw_domain_iterate_patches(glob->domain, get_patches, &user); - fclaw3d_file_write_array(fc, "meqn", packsize, patches, &errcode); + fclaw_file_write_array(fc, "meqn", packsize, patches, &errcode); for(int i = 0; i < glob->domain->local_num_patches; i++) { @@ -183,10 +195,10 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) sc_array_destroy(patches); - fclaw3d_file_close(fc, &errcode); - fclaw3d_file_write_partition (parition_filename, - "Test partition write", - glob->domain->d3, &errcode); + fclaw_file_close(fc, &errcode); + fclaw_file_write_partition (parition_filename, + "Test partition write", + glob->domain, &errcode); //fclaw_restart_test_from_file(glob, filename, parition_filename); From 87f8df03b3ca480f4cb22ba86d1265ab24deb366 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 20:46:07 -0600 Subject: [PATCH 22/76] change check_error to macro --- src/fclaw_restart.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 39f0930d4..a8ae55203 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -36,6 +36,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#define CHECK_ERROR_CODE(refine_dim, errcode, str) \ +do { \ + int reslen, retval; \ + char err_str[sc_MPI_MAX_ERROR_STRING]; \ + if (errcode != FCLAW_FILE_ERR_SUCCESS) \ + { \ + retval = fclaw_file_error_string (refine_dim, errcode, err_str, &reslen); \ + SC_CHECK_ABORTF (!retval, "%s: error string function not successful", str); \ + SC_ABORTF ("%s: %*.*s", str, reslen, reslen, err_str); \ + } \ +} while(0) + typedef struct pack_iter { fclaw_global_t * glob; @@ -91,6 +103,7 @@ void restart (fclaw_global_t * glob, glob->mpicomm, partition, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart read_partition"); } fclaw_file_context_t *fc @@ -101,6 +114,7 @@ void restart (fclaw_global_t * glob, partition, &glob->domain, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart open_file"); fclaw_domain_setup(glob, glob->domain); @@ -108,13 +122,18 @@ void restart (fclaw_global_t * glob, sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); - fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); + + fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart read globsize"); + size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); sc_array_reset(&globsize); sc_array_t glob_buffer; sc_array_init_size(&glob_buffer, glob_packsize, 1); - fclaw_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); + + fc = fclaw_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart read glob buffer"); fclaw_global_unpack((char *) sc_array_index(&glob_buffer, 0), glob); @@ -124,7 +143,8 @@ void restart (fclaw_global_t * glob, size_t packsize = patch_vt->partition_packsize(glob); sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); - fclaw_file_read_array(fc, user_string, packsize, patches, &errcode); + fc = fclaw_file_read_array(fc, user_string, packsize, patches, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart read patches"); pack_iter_t user; user.glob = glob; @@ -137,6 +157,7 @@ void restart (fclaw_global_t * glob, sc_array_destroy(patches); fclaw_file_close(fc, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart close file"); fclaw_exchange_setup(glob,timer); fclaw_regrid_set_neighbor_types(glob); @@ -148,6 +169,7 @@ void restart (fclaw_global_t * glob, void fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) { + int refine_dim = glob->domain->refine_dim; fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); char filename[BUFSIZ]; @@ -159,19 +181,26 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_context_t *fc = fclaw_file_open_write (filename, "ForestClaw data file", glob->domain, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "restart open file"); size_t glob_packsize = fclaw_global_packsize(glob); sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); *((size_t*) sc_array_index(&globsize, 0)) = glob_packsize; - fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); + + fc = fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "write globsize"); + sc_array_reset(&globsize); sc_array_t glob_buffer; sc_array_init_size(&glob_buffer, glob_packsize, 1); fclaw_global_pack(glob,(char *) sc_array_index(&glob_buffer, 0)); - fclaw_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); + + fc = fclaw_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "write glob buffer"); + sc_array_reset(&glob_buffer); size_t packsize = patch_vt->partition_packsize(glob); @@ -185,7 +214,8 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) fclaw_domain_iterate_patches(glob->domain, get_patches, &user); - fclaw_file_write_array(fc, "meqn", packsize, patches, &errcode); + fc = fclaw_file_write_array(fc, "meqn", packsize, patches, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "write glob buffer"); for(int i = 0; i < glob->domain->local_num_patches; i++) { @@ -199,10 +229,9 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_write_partition (parition_filename, "Test partition write", glob->domain, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "close file"); //fclaw_restart_test_from_file(glob, filename, parition_filename); - - fclaw_global_productionf("RESTATRTT!!\n"); } From 17b01ec95b967135efed994042e18da032918094 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 15 Mar 2024 20:46:18 -0600 Subject: [PATCH 23/76] fix dimensions --- src/fclaw_file.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/fclaw_file.c b/src/fclaw_file.c index c4a1114aa..1ad60ee95 100644 --- a/src/fclaw_file.c +++ b/src/fclaw_file.c @@ -37,7 +37,7 @@ struct fclaw_file_context static fclaw_file_context_t *wrap_file_2d(fclaw2d_file_context_t *d2) { fclaw_file_context_t *fc = FCLAW_ALLOC (fclaw_file_context_t, 1); - fc->refine_dim = 0; + fc->refine_dim = 2; fc->d2 = d2; fc->d3 = NULL; return fc; @@ -46,7 +46,7 @@ static fclaw_file_context_t *wrap_file_2d(fclaw2d_file_context_t *d2) static fclaw_file_context_t *wrap_file_3d(fclaw3d_file_context_t *d3) { fclaw_file_context_t *fc = FCLAW_ALLOC (fclaw_file_context_t, 1); - fc->refine_dim = 1; + fc->refine_dim = 3; fc->d2 = NULL; fc->d3 = d3; return fc; @@ -99,12 +99,12 @@ fclaw_file_context_t *fclaw_file_write_block (fclaw_file_context_t * sc_array_t * block_data, int *errcode) { - if(fc->refine_dim == 0) + if(fc->refine_dim == 2) { return wrap_file_2d(fclaw2d_file_write_block (fc->d2, user_string, block_size, block_data, errcode)); } - else if(fc->refine_dim == 1) + else if(fc->refine_dim == 3) { return wrap_file_3d(fclaw3d_file_write_block (fc->d3, user_string, block_size, block_data, errcode)); @@ -121,12 +121,12 @@ fclaw_file_context_t *fclaw_file_write_array (fclaw_file_context_t * sc_array_t * patch_data, int *errcode) { - if(fc->refine_dim == 0) + if(fc->refine_dim == 2) { return wrap_file_2d(fclaw2d_file_write_array (fc->d2, user_string, patch_size, patch_data, errcode)); } - else if(fc->refine_dim == 1) + else if(fc->refine_dim == 3) { return wrap_file_3d(fclaw3d_file_write_array (fc->d3, user_string, patch_size, patch_data, errcode)); @@ -193,7 +193,7 @@ fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * sc_array_t * block_data, int *errcode) { - if(fc->refine_dim == 0) + if(fc->refine_dim == 2) { fclaw2d_file_context_t* retval; retval = fclaw2d_file_read_block (fc->d2, user_string, @@ -208,7 +208,7 @@ fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * return fc; } } - else if(fc->refine_dim == 1) + else if(fc->refine_dim == 3) { fclaw3d_file_context_t* retval; retval = fclaw3d_file_read_block (fc->d3, user_string, @@ -236,7 +236,7 @@ fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * sc_array_t * patch_data, int *errcode) { - if(fc->refine_dim == 0) + if(fc->refine_dim == 2) { fclaw2d_file_context_t* retval; retval = fclaw2d_file_read_array (fc->d2, user_string, @@ -251,7 +251,7 @@ fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * return fc; } } - else if(fc->refine_dim == 1) + else if(fc->refine_dim == 3) { fclaw3d_file_context_t* retval; retval = fclaw3d_file_read_array (fc->d3, user_string, @@ -275,11 +275,11 @@ fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * int fclaw_file_close (fclaw_file_context_t * fc, int *errcode) { int retval; - if(fc->refine_dim == 0) + if(fc->refine_dim == 2) { retval = fclaw2d_file_close (fc->d2, errcode); } - else if(fc->refine_dim == 1) + else if(fc->refine_dim == 3) { retval = fclaw3d_file_close (fc->d3, errcode); } From 05638c559dc0e35fd3d0d36a8f20b2a996905c4e Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Sat, 16 Mar 2024 18:35:48 -0600 Subject: [PATCH 24/76] add glob arguments to fclaw_packing_vtable_t --- src/fclaw_global.c | 8 ++++---- src/fclaw_global.h | 3 ++- src/fclaw_global.h.TEST.cpp | 8 ++++---- src/fclaw_packing.h | 30 ++++++++++++++++++++++-------- src/fclaw_run.c | 15 ++++++++++----- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 0db165bdf..5f239612e 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -315,7 +315,7 @@ pack_attribute_cb(const char* key, void* value, void* user) // advance buffer pointer *iter->buffer_ptr += fclaw_pack_string(entry->packing_vtable_key, *iter->buffer_ptr); *iter->buffer_ptr += fclaw_pack_string(key, *iter->buffer_ptr); - *iter->buffer_ptr += vt->pack(entry->attribute, *iter->buffer_ptr); + *iter->buffer_ptr += vt->pack(iter->glob, entry->attribute, *iter->buffer_ptr); } } @@ -359,7 +359,7 @@ attribute_packsize_cb(const char* key, void* value, void* user) iter->size += fclaw_packsize_string(entry->packing_vtable_key) + fclaw_packsize_string(key) - + vt->size(entry->attribute); + + vt->size(iter->glob, entry->attribute); } } @@ -404,7 +404,7 @@ fclaw_global_unpack(char * buffer, fclaw_global_t * glob) { entry = FCLAW_ALLOC(attribute_entry_t,1); entry->packing_vtable_key = packing_vtable_key; - entry->attribute = vt->new_data(); + entry->attribute = vt->new_data(glob); entry->destroy = vt->destroy; fclaw_pointer_map_insert(glob->attributes, attribute_key, entry, attribute_entry_destroy); } @@ -414,7 +414,7 @@ fclaw_global_unpack(char * buffer, fclaw_global_t * glob) FCLAW_FREE(packing_vtable_key); } - buffer += vt->unpack(buffer,entry->attribute); + buffer += vt->unpack(glob, buffer, entry->attribute); FCLAW_FREE(attribute_key); } diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 6a903add5..5831414fa 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -216,7 +216,8 @@ void* fclaw_global_get_options (fclaw_global_t* glob, const char* key); * @param glob the global context * @param key the key to store the attribute under * @param attribute the attribute structure - * @param packing_vtable_key the key to the packing vtable, NULL if not needed + * @param packing_vtable_key The key to the packing vtable, NULL if not needed + * The packing vtable is expected to be of type fclaw_packing_vtable_t * @param destroy the callback to destroy the attribute, NULL if not needed */ void diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 0acf4b126..eed11444b 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -82,7 +82,7 @@ struct dummy_attribute } }; -size_t pack_dummy_options(void* user, char* buffer) +size_t pack_dummy_options(fclaw_global_t *glob, void *user, char *buffer) { dummy_attribute* options = (dummy_attribute*) user; @@ -95,7 +95,7 @@ size_t pack_dummy_options(void* user, char* buffer) return buffer-buffer_start; }; -size_t unpack_dummy_options(char* buffer, void* user) +size_t unpack_dummy_options(fclaw_global_t *glob, char* buffer, void* user) { dummy_attribute* attribute = (dummy_attribute*) user; @@ -114,12 +114,12 @@ size_t unpack_dummy_options(char* buffer, void* user) return buffer-buffer_start; }; -size_t packsize_dummy_attribute(void* user) +size_t packsize_dummy_attribute(fclaw_global_t *glob, void* user) { dummy_attribute* options = (dummy_attribute*) user; return sizeof(size_t) + options->size; }; -void * new_dummy_attribute(){ +void * new_dummy_attribute(fclaw_global_t *glob){ return new dummy_attribute(0,0); } void destroy_dummy_attribute(void* user){ diff --git a/src/fclaw_packing.h b/src/fclaw_packing.h index 18c61f2a2..1f3276ad0 100644 --- a/src/fclaw_packing.h +++ b/src/fclaw_packing.h @@ -27,6 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define FCLAW_PACKING_H #include +#include #ifdef __cplusplus extern "C" @@ -50,32 +51,45 @@ extern "C" /** * @brief Pack userdata into a buffer + * @param glob global context * @param userdata pointer to userdata * @param buffer buffer to pack into + * @return size_t number of bytes written */ -typedef size_t (*fclaw_packing_pack_t)(void* userdata, - char* buffer); +typedef size_t (*fclaw_packing_pack_t)(fclaw_global_t *glob, + void *userdata, + char *buffer); /** * @brief Unpack userdata from buffer + * @param glob global context * @param buffer buffer to unpack from - * @return user data to write to + * @param userdata user data to read from + * @return size_t number of bytes read */ -typedef size_t (*fclaw_packing_unpack_t)(char* buffer,void*); +typedef size_t (*fclaw_packing_unpack_t)(fclaw_global_t *glob, + char *buffer, + void *userdata); /** * @brief Get the size needed to pack userdata - * @return the size + * @param glob global context + * @param userdata pointer to userdata + * @return size_t number of bytes needed to pack userdata */ -typedef size_t (*fclaw_packing_packsize_t)(void* userdata); +typedef size_t (*fclaw_packing_packsize_t)(fclaw_global_t *glob, + void *userdata); /** * @brief create new userdata + * @param glob global context + * @return void * pointer to new userdata */ -typedef void * (*fclaw_packing_new_t)(); +typedef void * (*fclaw_packing_new_t)(fclaw_global_t *glob); /** * @brief destroy userdata + * @param value pointer to userdata to destroy */ -typedef void (*fclaw_packing_destroy_t)(void* value); +typedef void (*fclaw_packing_destroy_t)(void *value); /** * @brief vtable for packing functions diff --git a/src/fclaw_run.c b/src/fclaw_run.c index 46fe4bfa7..da24282cf 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -123,7 +123,8 @@ struct outstyle1_ctx } outstyle1_ctx_t; static -size_t packsize_outstyle1_ctx(void *user) +size_t packsize_outstyle1_ctx(fclaw_global_t *glob, + void *user) { outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; size_t size = 0; @@ -136,7 +137,9 @@ size_t packsize_outstyle1_ctx(void *user) } static -size_t pack_outstyle1_ctx(void *user, char *buffer) +size_t pack_outstyle1_ctx(fclaw_global_t *glob, + void *user, + char *buffer) { outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; char* buffer_start = buffer; @@ -149,7 +152,9 @@ size_t pack_outstyle1_ctx(void *user, char *buffer) } static -size_t unpack_outstyle1_ctx(char* buffer , void *user) +size_t unpack_outstyle1_ctx(fclaw_global_t *glob, + char *buffer, + void *user) { outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; char* buffer_start = buffer; @@ -162,7 +167,7 @@ size_t unpack_outstyle1_ctx(char* buffer , void *user) } static -void *outstyle1_ctx_new() +void *outstyle1_ctx_new(fclaw_global_t *glob) { outstyle1_ctx_t *ctx = FCLAW_ALLOC_ZERO(outstyle1_ctx_t,1); return (void*) ctx; @@ -201,7 +206,7 @@ void outstyle_1(fclaw_global_t *glob) { FCLAW_ASSERT(strcmp(fclaw_opt->restart_file,"") == 0); - ctx = (outstyle1_ctx_t*) outstyle1_ctx_new(); + ctx = (outstyle1_ctx_t*) outstyle1_ctx_new(glob); fclaw_global_attribute_store(glob, OUTSTYLE1_CTX_ATTRIBUTE_KEY, ctx, From deaca00e82997c698776ab039a0a5593eb74f67f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Sat, 16 Mar 2024 18:47:55 -0600 Subject: [PATCH 25/76] change gauge info to be an attribute --- src/fclaw_gauges.c | 35 +++++++++++++++++++++-------------- src/fclaw_global.h | 5 ----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/fclaw_gauges.c b/src/fclaw_gauges.c index 48cf234ce..bf0c738ce 100644 --- a/src/fclaw_gauges.c +++ b/src/fclaw_gauges.c @@ -59,7 +59,6 @@ typedef struct fclaw_gauge_info sc_array_t *coordinates; } fclaw_gauge_info_t; - static void gauge_initialize(fclaw_global_t* glob, void** acc) { @@ -92,7 +91,12 @@ void gauge_initialize(fclaw_global_t* glob, void** acc) gauge_acc->num_gauges = num_gauges; - glob->gauge_info = FCLAW_ALLOC_ZERO(fclaw_gauge_info_t,1); + fclaw_gauge_info_t *gauge_info = FCLAW_ALLOC_ZERO(fclaw_gauge_info_t,1); + fclaw_global_attribute_store(glob, + "gauge_info", + gauge_info, + NULL, + NULL); if (num_gauges > 0) { @@ -131,9 +135,9 @@ void gauge_initialize(fclaw_global_t* glob, void** acc) int num_blocks = glob->domain->num_blocks; - glob->gauge_info->block_offsets = sc_array_new_count(sizeof(int), + gauge_info->block_offsets = sc_array_new_count(sizeof(int), num_blocks+1); - glob->gauge_info->coordinates = sc_array_new_count(2*sizeof(double), num_gauges); + gauge_info->coordinates = sc_array_new_count(2*sizeof(double), num_gauges); /* We don't know how the blocks are arranged in the brick domain so we reverse engineer this information */ @@ -149,7 +153,7 @@ void gauge_initialize(fclaw_global_t* glob, void** acc) fclaw_block_t *blocks = glob->domain->blocks; int number_of_gauges_set = 0; - int *bo = (int*) sc_array_index_int(glob->gauge_info->block_offsets,0); + int *bo = (int*) sc_array_index_int(gauge_info->block_offsets,0); bo[0] = 0; double xll,yll, xur, yur; @@ -200,7 +204,7 @@ void gauge_initialize(fclaw_global_t* glob, void** acc) domain in [0,mi]x[0,mj]. This may not work for the cubed sphere case */ - double *c = (double*) sc_array_index_int(glob->gauge_info->coordinates, ng); + double *c = (double*) sc_array_index_int(gauge_info->coordinates, ng); c[0] = mi*(x - xll); c[1] = mj*(y - yll); @@ -209,7 +213,7 @@ void gauge_initialize(fclaw_global_t* glob, void** acc) number_of_gauges_set++; } } - bo = (int*) sc_array_index_int(glob->gauge_info->block_offsets, nb+1); + bo = (int*) sc_array_index_int(gauge_info->block_offsets, nb+1); bo[0] = number_of_gauges_set; } } @@ -293,9 +297,11 @@ void fclaw_locate_gauges(fclaw_global_t *glob) sc_array_t *results = sc_array_new_size(sizeof(int), num); + fclaw_gauge_info_t* gauge_info = + (fclaw_gauge_info_t *) fclaw_global_get_attribute(glob,"gauge_info"); fclaw_domain_search_points(glob->domain, - glob->gauge_info->block_offsets, - glob->gauge_info->coordinates, results); + gauge_info->block_offsets, + gauge_info->coordinates, results); for (i = 0; i < gauge_acc->num_gauges; ++i) { @@ -328,7 +334,8 @@ void gauge_finalize(fclaw_global_t *glob, void** acc) /* Clean up gauges and print anything left over in buffers */ fclaw_gauge_acc_t* gauge_acc = *((fclaw_gauge_acc_t**) acc); fclaw_gauge_t *gauges = gauge_acc->gauges; - fclaw_gauge_info_t* gauge_info = glob->gauge_info; + fclaw_gauge_info_t* gauge_info = + (fclaw_gauge_info_t *) fclaw_global_get_attribute(glob,"gauge_info"); for(int i = 0; i < gauge_acc->num_gauges; i++) { @@ -349,14 +356,14 @@ void gauge_finalize(fclaw_global_t *glob, void** acc) FCLAW_FREE(gauge_acc->gauges); } - if (glob->gauge_info->block_offsets != NULL) + if (gauge_info->block_offsets != NULL) { - sc_array_destroy(glob->gauge_info->block_offsets); + sc_array_destroy(gauge_info->block_offsets); } - if (glob->gauge_info->coordinates != NULL) + if (gauge_info->coordinates != NULL) { - sc_array_destroy(glob->gauge_info->coordinates); + sc_array_destroy(gauge_info->coordinates); } FCLAW_FREE(gauge_acc); diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 5831414fa..c5f37134c 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -93,11 +93,6 @@ struct fclaw_global object that does not need to be known to this file? */ struct fclaw_diagnostics_accumulator *acc; - /* CB: this is application specific. - Would it not be cleaner to add the gauges in a way to global - that this file does not need to know about gauges at all? */ - struct fclaw_gauge_info* gauge_info; - void *user; }; From 8781058daa73e31d0563be01ca7bf0d14ec42ae3 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Sat, 16 Mar 2024 18:58:53 -0600 Subject: [PATCH 26/76] move diagnostics accumulator into glob --- src/fclaw_diagnostics.c | 27 +++++- src/fclaw_diagnostics.h | 168 ++++++++++++++++++++++++++++++++++++ src/fclaw_gauges.c | 4 +- src/fclaw_global.c | 8 -- src/fclaw_global.h | 5 -- src/fclaw_global.h.TEST.cpp | 2 - 6 files changed, 193 insertions(+), 21 deletions(-) diff --git a/src/fclaw_diagnostics.c b/src/fclaw_diagnostics.c index 9b9c3dd21..6fd0e8905 100644 --- a/src/fclaw_diagnostics.c +++ b/src/fclaw_diagnostics.c @@ -44,6 +44,11 @@ void diagnostics_vt_destroy(void* vt) FCLAW_FREE (vt); } +static +void diagnostics_accumulator_destroy(void* acc) +{ + FCLAW_FREE (acc); +} /* --------------------------------------------------- Public interface ------------------------------------------------ */ @@ -57,6 +62,14 @@ fclaw_diagnostics_vtable_t* fclaw_diagnostics_vt(fclaw_global_t* glob) return diagnostics_vt; } +fclaw_diagnostics_accumulator_t* fclaw_diagnostics_get_acc(fclaw_global_t* glob) +{ + fclaw_diagnostics_accumulator_t* acc = (fclaw_diagnostics_accumulator_t*) + fclaw_global_get_attribute(glob, "fclaw_diagnostics_accumulator"); + FCLAW_ASSERT(acc != NULL); + return acc; +} + /* global_maximum is in forestclaw2d.c */ double fclaw_domain_global_minimum (fclaw_domain_t* domain, double d) { @@ -93,7 +106,13 @@ void fclaw_diagnostics_initialize(fclaw_global_t *glob) { fclaw_diagnostics_vtable_t *diag_vt = fclaw_diagnostics_vt(glob); - fclaw_diagnostics_accumulator_t *acc = glob->acc; + fclaw_diagnostics_accumulator_t *acc = FCLAW_ALLOC(fclaw_diagnostics_accumulator_t, 1); + fclaw_global_attribute_store(glob, + "fclaw_diagnostics_accumulator", + acc, + NULL, + diagnostics_accumulator_destroy); + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); /* Return an error accumulator */ @@ -122,7 +141,7 @@ void fclaw_diagnostics_initialize(fclaw_global_t *glob) void fclaw_diagnostics_gather(fclaw_global_t *glob, int init_flag) { - fclaw_diagnostics_accumulator_t *acc = glob->acc; + fclaw_diagnostics_accumulator_t *acc = fclaw_diagnostics_get_acc(glob); const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); fclaw_diagnostics_vtable_t *diag_vt = fclaw_diagnostics_vt(glob); @@ -182,7 +201,7 @@ void fclaw_diagnostics_gather(fclaw_global_t *glob, void fclaw_diagnostics_reset(fclaw_global_t *glob) { - fclaw_diagnostics_accumulator_t *acc = glob->acc; + fclaw_diagnostics_accumulator_t *acc = fclaw_diagnostics_get_acc(glob); const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); fclaw_diagnostics_vtable_t *diag_vt = fclaw_diagnostics_vt(glob); @@ -208,7 +227,7 @@ void fclaw_diagnostics_reset(fclaw_global_t *glob) void fclaw_diagnostics_finalize(fclaw_global_t *glob) { - fclaw_diagnostics_accumulator_t *acc = glob->acc; + fclaw_diagnostics_accumulator_t *acc = fclaw_diagnostics_get_acc(glob); const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); fclaw_diagnostics_vtable_t *diag_vt = fclaw_diagnostics_vt(glob); diff --git a/src/fclaw_diagnostics.h b/src/fclaw_diagnostics.h index b49fa9468..1fadd2407 100644 --- a/src/fclaw_diagnostics.h +++ b/src/fclaw_diagnostics.h @@ -28,6 +28,165 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef __cplusplus extern "C" +/** + * @file fclaw_diagnostics.h + * @brief Header file containing declarations for diagnostic functions and structures. + */ + +#ifndef FCLAW_DIAGNOSTICS_H +#define FCLAW_DIAGNOSTICS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @struct fclaw_diagnostics_accumulator + * @brief Structure representing the accumulator for diagnostic information. + */ +struct fclaw_diagnostics_accumulator +{ + void* patch_accumulator; /**< Pointer to the patch accumulator */ + void* solver_accumulator; /**< Pointer to the solver accumulator */ + void* user_accumulator; /**< Pointer to the user accumulator */ + void* gauge_accumulator; /**< Pointer to the gauge accumulator */ + void* ray_accumulator; /**< Pointer to the ray accumulator */ +}; + +/** + * @typedef fclaw_diagnostics_initialize_t + * @brief Function pointer type for the initialization of diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @param acc Pointer to the accumulator. + */ +typedef void (*fclaw_diagnostics_initialize_t)(struct fclaw_global *glob, void** acc); + +/** + * @typedef fclaw_diagnostics_compute_t + * @brief Function pointer type for the computation of diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @param acc Pointer to the accumulator. + */ +typedef void (*fclaw_diagnostics_compute_t)(struct fclaw_global *glob, void* acc); + +/** + * @typedef fclaw_diagnostics_gather_t + * @brief Function pointer type for the gathering of diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @param acc Pointer to the accumulator. + * @param init_flag Flag indicating whether the gathering is for initialization. + */ +typedef void (*fclaw_diagnostics_gather_t)(struct fclaw_global *glob, void* acc, int init_flag); + +/** + * @typedef fclaw_diagnostics_reset_t + * @brief Function pointer type for the resetting of diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @param acc Pointer to the accumulator. + */ +typedef void (*fclaw_diagnostics_reset_t)(struct fclaw_global *glob, void* acc); + +/** + * @typedef fclaw_diagnostics_finalize_t + * @brief Function pointer type for the finalization of diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @param acc Pointer to the accumulator. + */ +typedef void (*fclaw_diagnostics_finalize_t)(struct fclaw_global *glob, void** acc); + +/** + * @struct fclaw_diagnostics_vtable + * @brief Structure representing the virtual table for diagnostic functions. + */ +struct fclaw_diagnostics_vtable +{ + fclaw_diagnostics_initialize_t patch_init_diagnostics; /**< Function pointer for patch diagnostic initialization */ + fclaw_diagnostics_compute_t patch_compute_diagnostics; /**< Function pointer for patch diagnostic computation */ + fclaw_diagnostics_gather_t patch_gather_diagnostics; /**< Function pointer for patch diagnostic gathering */ + fclaw_diagnostics_reset_t patch_reset_diagnostics; /**< Function pointer for patch diagnostic resetting */ + fclaw_diagnostics_finalize_t patch_finalize_diagnostics; /**< Function pointer for patch diagnostic finalization */ + fclaw_diagnostics_initialize_t solver_init_diagnostics; /**< Function pointer for solver diagnostic initialization */ + fclaw_diagnostics_compute_t solver_compute_diagnostics; /**< Function pointer for solver diagnostic computation */ + fclaw_diagnostics_gather_t solver_gather_diagnostics; /**< Function pointer for solver diagnostic gathering */ + fclaw_diagnostics_reset_t solver_reset_diagnostics; /**< Function pointer for solver diagnostic resetting */ + fclaw_diagnostics_finalize_t solver_finalize_diagnostics; /**< Function pointer for solver diagnostic finalization */ + fclaw_diagnostics_initialize_t gauges_init_diagnostics; /**< Function pointer for gauge diagnostic initialization */ + fclaw_diagnostics_compute_t gauges_compute_diagnostics; /**< Function pointer for gauge diagnostic computation */ + fclaw_diagnostics_gather_t gauges_gather_diagnostics; /**< Function pointer for gauge diagnostic gathering */ + fclaw_diagnostics_reset_t gauges_reset_diagnostics; /**< Function pointer for gauge diagnostic resetting */ + fclaw_diagnostics_finalize_t gauges_finalize_diagnostics; /**< Function pointer for gauge diagnostic finalization */ + fclaw_diagnostics_initialize_t ray_init_diagnostics; /**< Function pointer for ray diagnostic initialization */ + fclaw_diagnostics_compute_t ray_compute_diagnostics; /**< Function pointer for ray diagnostic computation */ + fclaw_diagnostics_gather_t ray_gather_diagnostics; /**< Function pointer for ray diagnostic gathering */ + fclaw_diagnostics_reset_t ray_reset_diagnostics; /**< Function pointer for ray diagnostic resetting */ + fclaw_diagnostics_finalize_t ray_finalize_diagnostics; /**< Function pointer for ray diagnostic finalization */ + fclaw_diagnostics_initialize_t user_init_diagnostics; /**< Function pointer for user-defined diagnostic initialization */ + fclaw_diagnostics_compute_t user_compute_diagnostics; /**< Function pointer for user-defined diagnostic computation */ + fclaw_diagnostics_gather_t user_gather_diagnostics; /**< Function pointer for user-defined diagnostic gathering */ + fclaw_diagnostics_reset_t user_reset_diagnostics; /**< Function pointer for user-defined diagnostic resetting */ + fclaw_diagnostics_finalize_t user_finalize_diagnostics; /**< Function pointer for user-defined diagnostic finalization */ + int is_set; /**< Flag indicating whether the virtual table is set */ +}; + +/** + * @brief Retrieves the virtual table for diagnostic functions. + * @param glob Pointer to the fclaw_global structure. + * @return Pointer to the fclaw_diagnostics_vtable structure. + */ +fclaw_diagnostics_vtable_t* fclaw_diagnostics_vt(struct fclaw_global* glob); + +/** + * @brief Retrieves the accumulator for diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @return Pointer to the fclaw_diagnostics_accumulator structure. + */ +fclaw_diagnostics_accumulator_t* fclaw_diagnostics_get_acc(struct fclaw_global* glob); + +/** + * @brief Initializes the virtual table for diagnostic functions. + * @param glob Pointer to the fclaw_global structure. + */ +void fclaw_diagnostics_vtable_initialize(struct fclaw_global* glob); + +/** + * @brief Computes the global minimum value within a domain. + * @param domain Pointer to the fclaw_domain structure. + * @param d The value to compute the minimum for. + * @return The global minimum value. + */ +double fclaw_domain_global_minimum(struct fclaw_domain* domain, double d); + +/** + * @brief Initializes the diagnostic information. + * @param glob Pointer to the fclaw_global structure. + */ +void fclaw_diagnostics_initialize(struct fclaw_global* glob); + +/** + * @brief Gathers the diagnostic information. + * @param glob Pointer to the fclaw_global structure. + * @param init_flag Flag indicating whether the gathering is for initialization. + */ +void fclaw_diagnostics_gather(struct fclaw_global* glob, int init_flag); + +/** + * @brief Resets the diagnostic information. + * @param glob Pointer to the fclaw_global structure. + */ +void fclaw_diagnostics_reset(struct fclaw_global* glob); + +/** + * @brief Finalizes the diagnostic information. + * @param glob Pointer to the fclaw_global structure. + */ +void fclaw_diagnostics_finalize(struct fclaw_global* glob); + +#ifdef __cplusplus +} +#endif + +#endif /* FCLAW_DIAGNOSTICS_H */ { #endif @@ -106,6 +265,15 @@ struct fclaw_diagnostics_vtable fclaw_diagnostics_vtable_t* fclaw_diagnostics_vt(struct fclaw_global* glob); + +/** + * @brief get the accumulator for diagnostic information + * + * @param glob global context + * @return fclaw_diagnostics_accumulator_t accumulator + */ +fclaw_diagnostics_accumulator_t* fclaw_diagnostics_get_acc(struct fclaw_global* glob); + void fclaw_diagnostics_vtable_initialize(struct fclaw_global* glob); double fclaw_domain_global_minimum (struct fclaw_domain* domain, double d); diff --git a/src/fclaw_gauges.c b/src/fclaw_gauges.c index bf0c738ce..9223f6e9f 100644 --- a/src/fclaw_gauges.c +++ b/src/fclaw_gauges.c @@ -283,8 +283,8 @@ void fclaw_locate_gauges(fclaw_global_t *glob) int i,index,num; fclaw_gauge_t *g; - fclaw_gauge_acc_t* gauge_acc = - (fclaw_gauge_acc_t*) glob->acc->gauge_accumulator; + fclaw_diagnostics_accumulator_t *acc = fclaw_diagnostics_get_acc(glob); + fclaw_gauge_acc_t* gauge_acc = (fclaw_gauge_acc_t*) acc->gauge_accumulator; //fclaw_gauge_info_t* gauge_info = glob->gauge_info; /* Locate each gauge in the new mesh */ diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 5f239612e..6f201238f 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -67,11 +67,6 @@ fclaw_global_t* fclaw_global_new (void) glob->curr_time = 0; glob->cont = NULL; -#ifndef P4_TO_P8 - /* think about how this can work independent of dimension */ - glob->acc = FCLAW_ALLOC (fclaw_diagnostics_accumulator_t, 1); -#endif /* P4_TO_P8 */ - return glob; } @@ -128,9 +123,6 @@ fclaw_global_destroy (fclaw_global_t * glob) if(glob->options != NULL) fclaw_pointer_map_destroy (glob->options); if(glob->attributes != NULL) fclaw_pointer_map_destroy (glob->attributes); -#ifndef P4_TO_P8 - FCLAW_FREE (glob->acc); -#endif FCLAW_FREE (glob); } diff --git a/src/fclaw_global.h b/src/fclaw_global.h index c5f37134c..68ae0eabd 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -88,11 +88,6 @@ struct fclaw_global struct fclaw_map_context* cont; struct fclaw_domain *domain; - /* CB: is this a good place for the accumulator? - Would it be possible to add and retrieve it as an anonymous - object that does not need to be known to this file? */ - struct fclaw_diagnostics_accumulator *acc; - void *user; }; diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index eed11444b..492b39859 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -59,8 +59,6 @@ TEST_CASE("fclaw_global_new default options") CHECK_EQ(fclaw_pointer_map_size(glob->attributes), 0); CHECK(glob->cont == nullptr); CHECK(glob->domain == nullptr); - CHECK(glob->acc != nullptr); - CHECK(glob->gauge_info == nullptr); CHECK(glob->user == nullptr); From ca8c43f2f9e88a13b4059a67cc02fbb7e2d045e2 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Sat, 16 Mar 2024 20:14:31 -0600 Subject: [PATCH 27/76] fix handling of return values in fclaw_file.c --- src/fclaw_file.c | 74 +++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/src/fclaw_file.c b/src/fclaw_file.c index 1ad60ee95..e5f675a5f 100644 --- a/src/fclaw_file.c +++ b/src/fclaw_file.c @@ -36,6 +36,10 @@ struct fclaw_file_context static fclaw_file_context_t *wrap_file_2d(fclaw2d_file_context_t *d2) { + if(d2 == NULL) + { + return NULL; + } fclaw_file_context_t *fc = FCLAW_ALLOC (fclaw_file_context_t, 1); fc->refine_dim = 2; fc->d2 = d2; @@ -45,6 +49,10 @@ static fclaw_file_context_t *wrap_file_2d(fclaw2d_file_context_t *d2) static fclaw_file_context_t *wrap_file_3d(fclaw3d_file_context_t *d3) { + if(d3 == NULL) + { + return NULL; + } fclaw_file_context_t *fc = FCLAW_ALLOC (fclaw_file_context_t, 1); fc->refine_dim = 3; fc->d2 = NULL; @@ -187,6 +195,21 @@ fclaw_file_context_t *fclaw_file_open_read (int refine_dim, } } +/* handle the return when the returned file context is NULL */ +static +fclaw_file_context_t* handle_return_value(fclaw_file_context_t * fc) +{ + if(fc->d2 == NULL && fc->d3 == NULL) + { + FCLAW_FREE(fc); + return NULL; + } + else + { + return fc; + } +} + fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * fc, char *user_string, size_t block_size, @@ -195,39 +218,19 @@ fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * { if(fc->refine_dim == 2) { - fclaw2d_file_context_t* retval; - retval = fclaw2d_file_read_block (fc->d2, user_string, + fc->d2 = fclaw2d_file_read_block (fc->d2, user_string, block_size, block_data, errcode); - if(retval == NULL) - { - return NULL; - } - else - { - FCLAW_ASSERT(fc->d2 == retval); - return fc; - } } else if(fc->refine_dim == 3) { - fclaw3d_file_context_t* retval; - retval = fclaw3d_file_read_block (fc->d3, user_string, + fc->d3 = fclaw3d_file_read_block (fc->d3, user_string, block_size, block_data, errcode); - if(retval == NULL) - { - return NULL; - } - else - { - FCLAW_ASSERT(fc->d3 == retval); - return fc; - } } else { SC_ABORT_NOT_REACHED (); } - + return handle_return_value(fc); } fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * @@ -238,38 +241,19 @@ fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * { if(fc->refine_dim == 2) { - fclaw2d_file_context_t* retval; - retval = fclaw2d_file_read_array (fc->d2, user_string, + fc->d2 = fclaw2d_file_read_array (fc->d2, user_string, patch_size, patch_data, errcode); - if(retval == NULL) - { - return NULL; - } - else - { - FCLAW_ASSERT(fc->d2 == retval); - return fc; - } } else if(fc->refine_dim == 3) { - fclaw3d_file_context_t* retval; - retval = fclaw3d_file_read_array (fc->d3, user_string, + fc->d3 = fclaw3d_file_read_array (fc->d3, user_string, patch_size, patch_data, errcode); - if(retval == NULL) - { - return NULL; - } - else - { - FCLAW_ASSERT(fc->d3 == retval); - return fc; - } } else { SC_ABORT_NOT_REACHED (); } + return handle_return_value(fc); } int fclaw_file_close (fclaw_file_context_t * fc, int *errcode) From 576780637e82a52df0c242fc51668aac34e46575 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 19 Mar 2024 15:33:18 -0600 Subject: [PATCH 28/76] read/write directly from patch pointers --- src/fclaw_forestclaw.h | 6 + src/fclaw_initialize.c | 22 ++-- src/fclaw_patch.c | 35 ++++++ src/fclaw_patch.h | 50 ++++++++ src/fclaw_restart.c | 135 +++++++++++++--------- src/patches/clawpatch/fclaw_clawpatch.cpp | 57 +++++++++ 6 files changed, 241 insertions(+), 64 deletions(-) diff --git a/src/fclaw_forestclaw.h b/src/fclaw_forestclaw.h index 5056e62b1..495abacf4 100644 --- a/src/fclaw_forestclaw.h +++ b/src/fclaw_forestclaw.h @@ -38,6 +38,12 @@ struct fclaw_global; void fclaw_problem_setup(struct fclaw_global *glob); void fclaw_vtables_initialize(struct fclaw_global *glob); +/** + * @brief Intialize flags in the domain + * + * @param glob the global context + */ +void fclaw_initialize_domain_flags(struct fclaw_global *glob); void fclaw_run_vtables_initialize(struct fclaw_global *glob); void fclaw_initialize (struct fclaw_global *glob); diff --git a/src/fclaw_initialize.c b/src/fclaw_initialize.c index 2aba547f3..8f0a0fd89 100644 --- a/src/fclaw_initialize.c +++ b/src/fclaw_initialize.c @@ -73,6 +73,7 @@ void cb_initialize (fclaw_domain_t *domain, static void build_initial_domain(fclaw_global_t *glob) { + fclaw_initialize_domain_flags(glob); fclaw_domain_t** domain = &glob->domain; const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); @@ -207,6 +208,19 @@ void build_initial_domain(fclaw_global_t *glob) } } +void fclaw_initialize_domain_flags(fclaw_global_t *glob) +{ + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); + + /* set specific refinement strategy */ + fclaw_domain_set_refinement + (glob->domain, fclaw_opt->smooth_refine, fclaw_opt->smooth_level, + fclaw_opt->coarsen_delay); + + /* set partitioning */ + fclaw_domain_set_partitioning(glob->domain, fclaw_opt->partition_for_coarsening); +} + /* ----------------------------------------------------------------- Public interface ----------------------------------------------------------------- */ @@ -216,9 +230,6 @@ void fclaw_initialize(fclaw_global_t *glob) const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); - /* set partitioning */ - fclaw_domain_set_partitioning(*domain, fclaw_opt->partition_for_coarsening); - /* This mapping context is needed by fortran mapping functions */ fclaw_map_context_t *cont = glob->cont; FCLAW_MAP_SET_CONTEXT(&cont); @@ -246,11 +257,6 @@ void fclaw_initialize(fclaw_global_t *glob) /* User defined problem setup */ fclaw_problem_setup(glob); - /* set specific refinement strategy */ - fclaw_domain_set_refinement - (*domain, fclaw_opt->smooth_refine, fclaw_opt->smooth_level, - fclaw_opt->coarsen_delay); - if(strcmp(fclaw_opt->restart_file,"") == 0) { // no restart file diff --git a/src/fclaw_patch.c b/src/fclaw_patch.c index 72bf73a87..1677e25c5 100644 --- a/src/fclaw_patch.c +++ b/src/fclaw_patch.c @@ -808,6 +808,41 @@ void fclaw_patch_partition_unpack(fclaw_global_t *glob, patch_data_unpack(glob,this_patch,pdata_unpack_data_from_here); } +/* ----------------------------------- Restart --------------------------------------- */ + +int fclaw_patch_restart_num_pointers(fclaw_global_t* glob) +{ + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + FCLAW_ASSERT(patch_vt->restart_num_pointers != NULL); + return patch_vt->restart_num_pointers(glob); +} + +void fclaw_patch_restart_pointer_sizes(struct fclaw_global *glob, size_t restart_sizes[]) +{ + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + FCLAW_ASSERT(patch_vt->restart_pointer_sizes != NULL); + patch_vt->restart_pointer_sizes(glob, restart_sizes); +} + +void fclaw_patch_restart_names(fclaw_global_t* glob, const char *names[]) +{ + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + FCLAW_ASSERT(patch_vt->restart_names != NULL); + return patch_vt->restart_names(glob, names); +} + +void* fclaw_patch_restart_get_pointer(struct fclaw_global* glob, + struct fclaw_patch* this_patch, + int blockno, + int patchno, + int pointerno) +{ + fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); + FCLAW_ASSERT(patch_vt->restart_get_pointer != NULL); + return patch_vt->restart_get_pointer(glob, this_patch, blockno, patchno, pointerno); +} + + /* ----------------------------- Conservative updates --------------------------------- */ /* We need to virtualize this because we call it from fclaw_face_neighbors */ diff --git a/src/fclaw_patch.h b/src/fclaw_patch.h index d0ec0ea61..01ef289fe 100644 --- a/src/fclaw_patch.h +++ b/src/fclaw_patch.h @@ -830,6 +830,41 @@ void fclaw_patch_partition_unpack(struct fclaw_global *glob, */ size_t fclaw_patch_partition_packsize(struct fclaw_global* glob); +///@} +/* ------------------------------------------------------------------------------------ */ +/// @name Restart +/* ------------------------------------------------------------------------------------ */ +///@{ + +/** + * @brief Get the number of restart pointers + * + * @param glob the global context + * @return int the number of restart pointers + */ +int fclaw_patch_restart_num_pointers(struct fclaw_global* glob); + +/** + * @brief Get the sizes of the restart data + * + * @param[in] glob the global context + * @param[out] restart_sizes an array of length ::fclaw_patch_restart_num_pointers + * with the sizes of the restart data + */ +void fclaw_patch_restart_pointer_sizes(struct fclaw_global* glob, size_t restart_sizes[]); +/** + * @brief Get the names of the restart data. + * + * @param glob the global context + * @return sc_array_t* an array of strings + */ +void fclaw_patch_restart_names(struct fclaw_global* glob, const char *names[]); + +void *fclaw_patch_restart_get_pointer(struct fclaw_global* glob, + struct fclaw_patch* this_patch, + int blockno, + int patchno, + int pointerno); ///@} /* ------------------------------------------------------------------------------------ */ @@ -1716,6 +1751,21 @@ struct fclaw_patch_vtable /** @} */ + /** @{ @name Restart Functions */ + + int (*restart_num_pointers)(struct fclaw_global *glob); + + void (*restart_pointer_sizes)(struct fclaw_global *glob, size_t sizes[]); + + void (*restart_names)(struct fclaw_global *glob, const char *restart_names[]); + + void *(*restart_get_pointer)(struct fclaw_global* glob, + struct fclaw_patch* this_patch, + int blockno, + int patchno, + int pointerno); + /** @} */ + /** True if vtable has been set */ int is_set; }; diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index a8ae55203..2221e0147 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -31,10 +31,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include -#include +#include +#include #define CHECK_ERROR_CODE(refine_dim, errcode, str) \ do { \ @@ -52,32 +52,28 @@ typedef struct pack_iter { fclaw_global_t * glob; int curr_index; - size_t packsize; + size_t size; sc_array_t* patches; - fclaw_patch_vtable_t *patch_vt; + int pointerno; + int reading; }pack_iter_t; static void -get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) +get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) { pack_iter_t *user_data = (pack_iter_t*)user; sc_array_t *patches = user_data->patches; sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); - sc_array_init_size (current_arr, user_data->packsize, 1); - void* buffer = sc_array_index (current_arr, 0); - fclaw_patch_partition_pack(user_data->glob, patch, blockno, patchno, buffer); - user_data->curr_index++; -} -static void -set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) -{ - pack_iter_t *user_data = (pack_iter_t*)user; - sc_array_t *patches = user_data->patches; - sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); - void* buffer = sc_array_index (current_arr, 0); - fclaw_patch_partition_unpack(user_data->glob, user_data->glob->domain, patch, blockno, patchno, buffer); + if(user_data->reading && user_data->pointerno == 0) + { + fclaw_build_mode_t build_mode = FCLAW_BUILD_FOR_UPDATE; + + fclaw_patch_build(user_data->glob, patch, blockno, patchno,(void*) &build_mode); + } + + void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); - sc_array_reset(current_arr); + sc_array_init_data(current_arr, data, user_data->size, 1); user_data->curr_index++; } @@ -92,11 +88,11 @@ void restart (fclaw_global_t * glob, fclaw_domain_reset(glob); int errcode; - fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); - sc_array_t* partition = sc_array_new(sizeof(p4est_gloidx_t)); + sc_array_t* partition = NULL; char user_string[FCLAW3D_FILE_USER_STRING_BYTES]; if(partition_filename != NULL) { + partition = sc_array_new(sizeof(p4est_gloidx_t)); fclaw_file_read_partition(refine_dim, partition_filename, user_string, @@ -118,7 +114,10 @@ void restart (fclaw_global_t * glob, fclaw_domain_setup(glob, glob->domain); - sc_array_destroy(partition); + if(partition != NULL) + { + sc_array_destroy(partition); + } sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); @@ -139,26 +138,42 @@ void restart (fclaw_global_t * glob, sc_array_reset(&glob_buffer); - - size_t packsize = patch_vt->partition_packsize(glob); - sc_array_t* patches = sc_array_new(sizeof(sc_array_t)); - - fc = fclaw_file_read_array(fc, user_string, packsize, patches, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart read patches"); - - pack_iter_t user; - user.glob = glob; - user.curr_index = 0; - user.patches = patches; - user.packsize = packsize; - user.patch_vt = patch_vt; - fclaw_domain_iterate_patches(glob->domain, set_patches, &user); - - sc_array_destroy(patches); + int num_pointers = fclaw_patch_restart_num_pointers(glob); + size_t sizes[num_pointers]; + fclaw_patch_restart_pointer_sizes(glob, sizes); + const char* names[num_pointers]; + fclaw_patch_restart_names(glob, names); + for(int i = 0; i < 1; i++) + { + sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); + pack_iter_t user; + user.glob = glob; + user.curr_index = 0; + user.patches = patches; + user.size = sizes[i]; + user.pointerno = i; + user.reading = 1; + fclaw_domain_iterate_patches(glob->domain, get_patches, &user); + + fc = fclaw_file_read_array(fc, user_string, sizes[i], patches, &errcode); + if(strncmp(user_string, names[i], strlen(names[i])) != 0) + { + fclaw_abortf("User string mismatch: %s != %s\n", user_string, names[i]); + } + CHECK_ERROR_CODE(refine_dim, errcode, "restart read patches"); + + for(int i = 0; i < glob->domain->local_num_patches; i++) + { + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, i); + sc_array_reset(current_arr); + } + sc_array_destroy(patches); + } fclaw_file_close(fc, &errcode); CHECK_ERROR_CODE(refine_dim, errcode, "restart close file"); + fclaw_initialize_domain_flags(glob); fclaw_exchange_setup(glob,timer); fclaw_regrid_set_neighbor_types(glob); } @@ -170,7 +185,6 @@ void fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) { int refine_dim = glob->domain->refine_dim; - fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); char filename[BUFSIZ]; char parition_filename[BUFSIZ]; @@ -203,27 +217,36 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) sc_array_reset(&glob_buffer); - size_t packsize = patch_vt->partition_packsize(glob); - sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); - pack_iter_t user; - user.glob = glob; - user.curr_index = 0; - user.patches = patches; - user.packsize = packsize; - user.patch_vt = patch_vt; - fclaw_domain_iterate_patches(glob->domain, get_patches, &user); - - - fc = fclaw_file_write_array(fc, "meqn", packsize, patches, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "write glob buffer"); - for(int i = 0; i < glob->domain->local_num_patches; i++) + int num_pointers = fclaw_patch_restart_num_pointers(glob); + size_t sizes[num_pointers]; + fclaw_patch_restart_pointer_sizes(glob, sizes); + const char* names[num_pointers]; + fclaw_patch_restart_names(glob, names); + for(int i = 0; i < 1; i++) { - sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, i); - sc_array_reset(current_arr); + sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); + pack_iter_t user; + user.glob = glob; + user.curr_index = 0; + user.patches = patches; + user.size = sizes[i]; + user.pointerno = i; + user.reading = 0; + fclaw_domain_iterate_patches(glob->domain, get_patches, &user); + + + fc = fclaw_file_write_array(fc, names[i], sizes[i], patches, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "write patches"); + + for(int i = 0; i < glob->domain->local_num_patches; i++) + { + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, i); + sc_array_reset(current_arr); + } + sc_array_destroy(patches); } - sc_array_destroy(patches); fclaw_file_close(fc, &errcode); fclaw_file_write_partition (parition_filename, diff --git a/src/patches/clawpatch/fclaw_clawpatch.cpp b/src/patches/clawpatch/fclaw_clawpatch.cpp index 6e5daa438..db509115b 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.cpp @@ -1550,6 +1550,57 @@ void clawpatch_partition_unpack(fclaw_global_t *glob, cp->griddata.copyFromMemory((double*)unpack_data_from_here); } +/* ---------------------------- Restart ----------------------------------------------- */ + +static +int restart_num_pointers(fclaw_global_t *glob) +{ + return 1; +} + +static +void restart_pointer_sizes(fclaw_global_t *glob, + size_t sizes[]) +{ + fclaw_clawpatch_options_t* opts = fclaw_clawpatch_get_options(glob); + sizes[0] = sizeof(double)*opts->meqn; + if(opts->patch_dim == 2) + { + sizes[0] *= (opts->mx+2*opts->mbc)*(opts->my+2*opts->mbc); + } + else if(opts->patch_dim == 3 && glob->domain->refine_dim == 2) + { + sizes[0] *= (opts->mx+2*opts->mbc)*(opts->my+2*opts->mbc)*opts->mz; + } + else + { + sizes[0] *= (opts->mx+2*opts->mbc)*(opts->my+2*opts->mbc)*(opts->mz+2*opts->mbc); + } +} +static +void restart_names(fclaw_global_t *glob, + const char *names[]) +{ + names[0] = "q"; +} + +static +void *get_pointer(fclaw_global_t *glob, + fclaw_patch_t *patch, + int blockno, + int patchno, + int pointerno) +{ + if (pointerno == 0) + { + return fclaw_clawpatch_get_q(glob,patch); + } + else + { + SC_ABORT_NOT_REACHED(); + } +} + /* ------------------------------------ Virtual table -------------------------------- */ static @@ -1850,6 +1901,12 @@ void fclaw_clawpatch_vtable_initialize(fclaw_global_t* glob, patch_vt->partition_pack = clawpatch_partition_pack; patch_vt->partition_unpack = clawpatch_partition_unpack; + /* restart */ + patch_vt->restart_num_pointers = restart_num_pointers; + patch_vt->restart_pointer_sizes = restart_pointer_sizes; + patch_vt->restart_names = restart_names; + patch_vt->restart_get_pointer = get_pointer; + /* output functions */ clawpatch_vt->time_header_ascii = fclaw_clawpatch_time_header_ascii; clawpatch_vt->cb_output_ascii = cb_clawpatch_output_ascii; From 772bc5bf05fdf04327a38f5d341337ad0db85660 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 19 Mar 2024 16:21:45 -0600 Subject: [PATCH 29/76] fix pointer sizes in clawpatch --- src/patches/clawpatch/fclaw_clawpatch.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/patches/clawpatch/fclaw_clawpatch.cpp b/src/patches/clawpatch/fclaw_clawpatch.cpp index db509115b..397cf0c91 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.cpp @@ -1568,10 +1568,6 @@ void restart_pointer_sizes(fclaw_global_t *glob, { sizes[0] *= (opts->mx+2*opts->mbc)*(opts->my+2*opts->mbc); } - else if(opts->patch_dim == 3 && glob->domain->refine_dim == 2) - { - sizes[0] *= (opts->mx+2*opts->mbc)*(opts->my+2*opts->mbc)*opts->mz; - } else { sizes[0] *= (opts->mx+2*opts->mbc)*(opts->my+2*opts->mbc)*(opts->mz+2*opts->mbc); From 764508004efb014dff5706bedd11183c6a218618 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 21 Mar 2024 15:56:20 -0600 Subject: [PATCH 30/76] update glob constructor in tests --- src/fclaw_diagnostics.h.TEST.cpp | 10 +++---- src/fclaw_elliptic_solver.h.TEST.cpp | 10 +++---- src/fclaw_gauges.h.TEST.cpp | 10 +++---- src/fclaw_global.h.TEST.cpp | 28 +++++++++---------- src/fclaw_options.h.TEST.cpp | 12 ++++---- src/fclaw_patch.h.TEST.cpp | 10 +++---- src/fclaw_vtable.h.TEST.cpp | 10 +++---- .../fclaw2d_clawpatch_fort.h.TEST.cpp | 4 +-- .../clawpatch/fclaw_clawpatch.h.2d.TEST.cpp | 20 ++++++------- .../clawpatch/fclaw_clawpatch.h.3d.TEST.cpp | 10 +++---- .../fclaw_clawpatch.h.3d.ghostfill.TEST.cpp | 2 +- .../clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp | 10 +++---- .../fclaw_clawpatch_diagnostics.h.TEST.cpp | 2 +- .../fclaw_clawpatch_options.h.TEST.cpp | 12 ++++---- src/patches/metric/fclaw2d_metric.h.TEST.cpp | 10 +++---- .../fc2d_clawpack46.h.TEST.cpp | 14 +++++----- .../fc2d_clawpack46_options.h.TEST.cpp | 12 ++++---- .../fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp | 14 +++++----- .../fc2d_clawpack5_options.h.TEST.cpp | 12 ++++---- .../fc2d_cudaclaw/fc2d_cudaclaw.h.TEST.cpp | 14 +++++----- .../fc2d_cudaclaw_options.h.TEST.cpp | 12 ++++---- .../fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp | 14 +++++----- .../fc2d_geoclaw_options.h.TEST.cpp | 12 ++++---- .../fc2d_thunderegg.h.TEST.cpp | 10 +++---- .../fc2d_thunderegg_options.h.TEST.cpp | 12 ++++---- .../fc3d_clawpack46.h.TEST.cpp | 14 +++++----- .../fc3d_clawpack46_options.h.TEST.cpp | 12 ++++---- 27 files changed, 156 insertions(+), 156 deletions(-) diff --git a/src/fclaw_diagnostics.h.TEST.cpp b/src/fclaw_diagnostics.h.TEST.cpp index b83e88ca3..eddf55ecd 100644 --- a/src/fclaw_diagnostics.h.TEST.cpp +++ b/src/fclaw_diagnostics.h.TEST.cpp @@ -29,8 +29,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw_diagnostics_vtable_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_diagnostics_vtable_initialize(glob1); fclaw_diagnostics_vtable_initialize(glob2); @@ -43,7 +43,7 @@ TEST_CASE("fclaw_diagnostics_vtable_initialize stores two seperate vtables in tw TEST_CASE("fclaw_diagnostics_vtable_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_diagnostics_vtable_initialize(glob); @@ -56,8 +56,8 @@ TEST_CASE("fclaw_diagnostics_vtable_initialize sets is_set flag") TEST_CASE("fclaw_diagnostics_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_diagnostics_vtable_initialize(glob1); CHECK_SC_ABORTED(fclaw_diagnostics_vtable_initialize(glob1)); diff --git a/src/fclaw_elliptic_solver.h.TEST.cpp b/src/fclaw_elliptic_solver.h.TEST.cpp index 41a0731ca..1c3431b38 100644 --- a/src/fclaw_elliptic_solver.h.TEST.cpp +++ b/src/fclaw_elliptic_solver.h.TEST.cpp @@ -29,8 +29,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw_elliptic_vtable_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_elliptic_vtable_initialize(glob1); fclaw_elliptic_vtable_initialize(glob2); @@ -43,7 +43,7 @@ TEST_CASE("fclaw_elliptic_vtable_initialize stores two seperate vtables in two s TEST_CASE("fclaw_elliptic_vtable_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_elliptic_vtable_initialize(glob); @@ -56,8 +56,8 @@ TEST_CASE("fclaw_elliptic_vtable_initialize sets is_set flag") TEST_CASE("fclaw_elliptic_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_elliptic_vtable_initialize(glob1); CHECK_SC_ABORTED(fclaw_elliptic_vtable_initialize(glob1)); diff --git a/src/fclaw_gauges.h.TEST.cpp b/src/fclaw_gauges.h.TEST.cpp index 845e4c8d3..f40749ea2 100644 --- a/src/fclaw_gauges.h.TEST.cpp +++ b/src/fclaw_gauges.h.TEST.cpp @@ -30,8 +30,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw_gauges_vtable_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_diagnostics_vtable_initialize(glob1); fclaw_gauges_vtable_initialize(glob1); @@ -47,7 +47,7 @@ TEST_CASE("fclaw_gauges_vtable_initialize stores two seperate vtables in two sep TEST_CASE("fclaw_gauges_vtable_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_diagnostics_vtable_initialize(glob); fclaw_gauges_vtable_initialize(glob); @@ -61,8 +61,8 @@ TEST_CASE("fclaw_gauges_vtable_initialize sets is_set flag") TEST_CASE("fclaw_guages_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_diagnostics_vtable_initialize(glob1); fclaw_gauges_vtable_initialize(glob1); diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index 492b39859..b0864c763 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include TEST_CASE("fclaw_global_new default options") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_EQ(glob->curr_time, 0.0); @@ -141,7 +141,7 @@ TEST_CASE("fclaw_global_pack with no packed attributes") for(double curr_dt : {1.0, 1.2}) { fclaw_global_t* glob1; - glob1 = fclaw_global_new(); + glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; glob1->curr_time = curr_time; glob1->curr_dt = curr_dt; @@ -160,7 +160,7 @@ TEST_CASE("fclaw_global_pack with no packed attributes") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; size_t bytes_read = fclaw_global_unpack(buffer, glob2); REQUIRE_EQ(bytes_read, packsize); @@ -186,7 +186,7 @@ TEST_CASE("fclaw_global_pack with a single packed attribute") std::vector args = {dummy}; //fclaw_app_t* app = fclaw_app_new_on_comm(sc_MPI_COMM_WORLD,&argc,&argv,NULL); fclaw_global_t* glob1; - glob1 = fclaw_global_new(); + glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_vtable_store(glob1, "dummy1_vtable", &dummy_opts_vt, NULL); glob1->curr_time = curr_time; @@ -210,7 +210,7 @@ TEST_CASE("fclaw_global_pack with a single packed attribute") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_vtable_store(glob2, "dummy1_vtable", &dummy_opts_vt, NULL); dummy_attribute* attribute2 = NULL; @@ -252,7 +252,7 @@ TEST_CASE("fclaw_global_pack with two packed attributes") for(double curr_dt : {1.0, 1.2}) { fclaw_global_t* glob1; - glob1 = fclaw_global_new(); + glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_vtable_store(glob1, "dummy1", &dummy_opts_vt, NULL); fclaw_global_vtable_store(glob1, "dummy2", &dummy_opts_vt, NULL); glob1->curr_time = curr_time; @@ -279,7 +279,7 @@ TEST_CASE("fclaw_global_pack with two packed attributes") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_vtable_store(glob2, "dummy1", &dummy_opts_vt, NULL); fclaw_global_vtable_store(glob2, "dummy2", &dummy_opts_vt, NULL); @@ -329,7 +329,7 @@ TEST_CASE("fclaw_global_pack with two packed attributes") TEST_CASE("fclaw_global_pack aborts with unregistered vtable") { fclaw_global_t* glob1; - glob1 = fclaw_global_new(); + glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; glob1->curr_time = 100; glob1->curr_dt = 200; @@ -342,7 +342,7 @@ TEST_CASE("fclaw_global_pack aborts with unregistered vtable") TEST_CASE("fclaw_global_packsize aborts with unregistered vtable") { fclaw_global_t* glob1; - glob1 = fclaw_global_new(); + glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; glob1->curr_time = 100; glob1->curr_dt = 200; @@ -354,7 +354,7 @@ TEST_CASE("fclaw_global_packsize aborts with unregistered vtable") TEST_CASE("fclaw_global_unpack aborts with unregistered vtable") { fclaw_global_t* glob1; - glob1 = fclaw_global_new(); + glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; glob1->curr_time = 1; glob1->curr_dt = 1; @@ -371,13 +371,13 @@ TEST_CASE("fclaw_global_unpack aborts with unregistered vtable") REQUIRE_EQ(bytes_written, packsize); - fclaw_global_t* glob2=fclaw_global_new(); + fclaw_global_t* glob2=fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; //no vtables in glob2 CHECK_SC_ABORTED(fclaw_global_unpack(buffer, glob2)); } TEST_CASE("fclaw_global_options_store and fclaw_global_get_options test") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; // Test with an integer int option1 = 10; @@ -454,7 +454,7 @@ TEST_CASE("fclaw_global_get_global assert fails when NULL") #endif TEST_CASE("fclaw_global_vtable_store and fclaw_global_get_vtable test") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; // Test with an integer int vtable1 = 10; @@ -489,7 +489,7 @@ TEST_CASE("fclaw_global_vtable_store and fclaw_global_get_vtable test") { } TEST_CASE("fclaw_global_attribute_store and fclaw_global_get_attribute test") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; // Test with an integer int attribute1 = 10; diff --git a/src/fclaw_options.h.TEST.cpp b/src/fclaw_options.h.TEST.cpp index d33dfe701..909200565 100644 --- a/src/fclaw_options.h.TEST.cpp +++ b/src/fclaw_options.h.TEST.cpp @@ -33,8 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_options_t* opts1 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); fclaw_options_t* opts2 = FCLAW_ALLOC_ZERO(fclaw_options_t,1); @@ -57,8 +57,8 @@ TEST_CASE("fclaw_options can store options in two seperate globs") TEST_CASE("fclaw_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fclaw_get_options(glob1)); @@ -70,8 +70,8 @@ TEST_CASE("fclaw_get_options fails if not intialized") TEST_CASE("fclaw_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_options_t,1)); CHECK_SC_ABORTED(fclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_options_t,1))); diff --git a/src/fclaw_patch.h.TEST.cpp b/src/fclaw_patch.h.TEST.cpp index 4d6e51494..21d0480c1 100644 --- a/src/fclaw_patch.h.TEST.cpp +++ b/src/fclaw_patch.h.TEST.cpp @@ -29,8 +29,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw_patch_vtable_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_patch_vtable_initialize(glob1); fclaw_patch_vtable_initialize(glob2); @@ -43,7 +43,7 @@ TEST_CASE("fclaw_patch_vtable_initialize stores two seperate vtables in two sepe TEST_CASE("fclaw_patch_vtable_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_patch_vtable_initialize(glob); @@ -56,8 +56,8 @@ TEST_CASE("fclaw_patch_vtable_initialize sets is_set flag") TEST_CASE("fclaw_patch_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_patch_vtable_initialize(glob1); CHECK_SC_ABORTED(fclaw_patch_vtable_initialize(glob1)); diff --git a/src/fclaw_vtable.h.TEST.cpp b/src/fclaw_vtable.h.TEST.cpp index cced16238..09fc885d6 100644 --- a/src/fclaw_vtable.h.TEST.cpp +++ b/src/fclaw_vtable.h.TEST.cpp @@ -29,8 +29,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw_vtable_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_vtable_initialize(glob1); fclaw_vtable_initialize(glob2); @@ -43,7 +43,7 @@ TEST_CASE("fclaw_vtable_initialize stores two seperate vtables in two seperate g TEST_CASE("fclaw_vtable_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_vtable_initialize(glob); @@ -56,8 +56,8 @@ TEST_CASE("fclaw_vtable_initialize sets is_set flag") TEST_CASE("fclaw_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_vtable_initialize(glob1); CHECK_SC_ABORTED(fclaw_vtable_initialize(glob1)); diff --git a/src/patches/clawpatch/fclaw2d_clawpatch_fort.h.TEST.cpp b/src/patches/clawpatch/fclaw2d_clawpatch_fort.h.TEST.cpp index c5a0d2033..18758d3c0 100644 --- a/src/patches/clawpatch/fclaw2d_clawpatch_fort.h.TEST.cpp +++ b/src/patches/clawpatch/fclaw2d_clawpatch_fort.h.TEST.cpp @@ -64,7 +64,7 @@ TEST_CASE("FCLAW2D_CLAWPATCH_EXCEEDS_THRESHOLD calls user function") exceeds_test_parameters& params = global_exceeds_test_parameters; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* clawpatch_opts = fclaw_clawpatch_options_new(2); @@ -136,7 +136,7 @@ TEST_CASE("FCLAW3DX_CLAWPATCH_EXCEEDS_THRESHOLD calls user function") exceeds_test_parameters& params = global_exceeds_test_parameters; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.2d.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.2d.TEST.cpp index d4f8860c6..90a97a67f 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.2d.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.2d.TEST.cpp @@ -33,9 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("2d fclaw_clawpatch_vtable_initialize stores two separate vtables in two separate globs") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob1 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob1, domain); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob2, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(2); @@ -59,9 +59,9 @@ TEST_CASE("2d fclaw_clawpatch_vtable_initialize stores two separate vtables in t TEST_CASE("3dx fclaw_clawpatch_vtable_initialize stores two separate vtables in two separate globs") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob1 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob1, domain); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob2, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); @@ -85,7 +85,7 @@ TEST_CASE("3dx fclaw_clawpatch_vtable_initialize stores two separate vtables in TEST_CASE("2d fclaw_clawpatch_vtable_initialize sets is_set flag") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(2); @@ -105,7 +105,7 @@ TEST_CASE("2d fclaw_clawpatch_vtable_initialize sets is_set flag") TEST_CASE("3dx fclaw_clawpatch_vtable_initialize sets is_set flag") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); @@ -127,9 +127,9 @@ TEST_CASE("3dx fclaw_clawpatch_vtable_initialize sets is_set flag") TEST_CASE("2d fclaw_clawpatch_vtable_initialize fails if called twice on a glob") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob1 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob1, domain); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob2, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(2); @@ -153,9 +153,9 @@ TEST_CASE("2d fclaw_clawpatch_vtable_initialize fails if called twice on a glob" TEST_CASE("3dx fclaw_clawpatch_vtable_initialize fails if called twice on a glob") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob1 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob1, domain); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob2, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp index 57198d449..d789808c0 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3d.TEST.cpp @@ -68,7 +68,7 @@ struct SinglePatchDomain { fclaw_clawpatch_options_t* opts; SinglePatchDomain(){ - glob = fclaw_global_new(); + glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; opts = fclaw_clawpatch_options_new(3); memset(&fopts, 0, sizeof(fopts)); fopts.mi=1; @@ -119,7 +119,7 @@ struct OctDomain { fclaw_clawpatch_options_t* opts; OctDomain(){ - glob = fclaw_global_new(); + glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; opts = fclaw_clawpatch_options_new(3); memset(&fopts, 0, sizeof(fopts)); fopts.mi=1; @@ -176,7 +176,7 @@ struct OctDomain { TEST_CASE("3d fclaw_clawpatch_vtable_initialize") { fclaw_domain_t* domain = fclaw_domain_new_unitcube(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); @@ -260,7 +260,7 @@ TEST_CASE("3d fclaw_clawpatch patch_build") for(const int& rhs_fields : {0,2}) for(fclaw_build_mode_t build_mode : {FCLAW_BUILD_FOR_GHOST_AREA_COMPUTED, FCLAW_BUILD_FOR_UPDATE}) { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_options_t fopts; memset(&fopts, 0, sizeof(fopts)); @@ -685,7 +685,7 @@ TEST_CASE("3d fclaw_clawpatch_metric_scalar") /* DAC : Fix this test for fclaw3d_metric? */ TEST_CASE("3d fclaw_clawpatch_metric_vector") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_vtables_initialize(glob); SinglePatchDomain test_data; diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp index 1212ff7fc..77b16cf3f 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3d.ghostfill.TEST.cpp @@ -58,7 +58,7 @@ struct TestData { fclaw_clawpatch_vtable_t * clawpatch_vt; TestData(fclaw_domain_t* domain, fclaw_map_context_t* map, int minlevel, int maxlevel){ - glob = fclaw_global_new(); + glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; opts = fclaw_clawpatch_options_new(3); memset(&fopts, 0, sizeof(fopts)); fopts.mi=1; diff --git a/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp index 9717d31fd..73447c62f 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.h.3dx.TEST.cpp @@ -69,7 +69,7 @@ struct SinglePatchDomain { fclaw_clawpatch_options_t* opts; SinglePatchDomain(){ - glob = fclaw_global_new(); + glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; opts = fclaw_clawpatch_options_new(3); memset(&fopts, 0, sizeof(fopts)); fopts.mi=1; @@ -122,7 +122,7 @@ struct QuadDomain { fclaw_clawpatch_options_t* opts; QuadDomain(){ - glob = fclaw_global_new(); + glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; opts = fclaw_clawpatch_options_new(3); memset(&fopts, 0, sizeof(fopts)); fopts.mi=1; @@ -178,7 +178,7 @@ struct QuadDomain { TEST_CASE("3dx fclaw_clawpatch_vtable_initialize") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); @@ -257,7 +257,7 @@ TEST_CASE("3dx fclaw_clawpatch patch_build") for(const int& rhs_fields : {0,2}) for(fclaw_build_mode_t build_mode : {FCLAW_BUILD_FOR_GHOST_AREA_COMPUTED, FCLAW_BUILD_FOR_UPDATE}) { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_options_t fopts; memset(&fopts, 0, sizeof(fopts)); @@ -682,7 +682,7 @@ TEST_CASE("3dx fclaw_clawpatch_metric_scalar") /* DAC : Fix this test for fclaw3d_metric? */ TEST_CASE("3dx fclaw_clawpatch_metric_vector") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_vtables_initialize(glob); SinglePatchDomain test_data; diff --git a/src/patches/clawpatch/fclaw_clawpatch_diagnostics.h.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch_diagnostics.h.TEST.cpp index 544492821..085769fcc 100644 --- a/src/patches/clawpatch/fclaw_clawpatch_diagnostics.h.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch_diagnostics.h.TEST.cpp @@ -33,7 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("2d fclaw_clawpatch_diagnostics_vtable_initialize fails if fclaw2d_diagnostics_vtable_initialize is not called first") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fclaw_clawpatch_diagnostics_vtable_initialize(glob)); fclaw_global_destroy(glob); } diff --git a/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp b/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp index d3018baa6..54e1d9f1a 100644 --- a/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch_options.h.TEST.cpp @@ -52,8 +52,8 @@ TEST_CASE("fclaw_clawpatch_options_new 3d") TEST_CASE("fclaw_clawpatch_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_clawpatch_options_t* opts1 = fclaw_clawpatch_options_new(2); fclaw_clawpatch_options_t* opts2 = fclaw_clawpatch_options_new(3); @@ -75,8 +75,8 @@ TEST_CASE("fclaw_clawpatch_options can store options in two seperate globs") TEST_CASE("fclaw_clawpatch_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fclaw_clawpatch_get_options(glob1)); @@ -88,8 +88,8 @@ TEST_CASE("fclaw_clawpatch_get_options fails if not intialized") TEST_CASE("fclaw_clawpatch_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_clawpatch_options_t* opts1 = fclaw_clawpatch_options_new(2); fclaw_clawpatch_options_t* opts2 = fclaw_clawpatch_options_new(3); diff --git a/src/patches/metric/fclaw2d_metric.h.TEST.cpp b/src/patches/metric/fclaw2d_metric.h.TEST.cpp index c7d59dcf9..04acea55e 100644 --- a/src/patches/metric/fclaw2d_metric.h.TEST.cpp +++ b/src/patches/metric/fclaw2d_metric.h.TEST.cpp @@ -29,8 +29,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fclaw2d_metric_vtable_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw2d_metric_vtable_initialize(glob1); fclaw2d_metric_vtable_initialize(glob2); @@ -43,7 +43,7 @@ TEST_CASE("fclaw2d_metric_vtable_initialize stores two seperate vtables in two s TEST_CASE("fclaw2d_metric_vtable_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw2d_metric_vtable_initialize(glob); @@ -56,8 +56,8 @@ TEST_CASE("fclaw2d_metric_vtable_initialize sets is_set flag") TEST_CASE("fclaw2d_metric_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw2d_metric_vtable_initialize(glob1); CHECK_SC_ABORTED(fclaw2d_metric_vtable_initialize(glob1)); diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp index 80a03d452..3973f08e4 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46.h.TEST.cpp @@ -33,8 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_clawpack46_solver_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); @@ -69,7 +69,7 @@ TEST_CASE("fc2d_clawpack46_solver_initialize stores two seperate vtables in two TEST_CASE("fc2d_clawpack46_solver_initialize sets is_set flag") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); /* create some empty options structures */ @@ -95,8 +95,8 @@ TEST_CASE("fc2d_clawpack46_solver_initialize sets is_set flag") TEST_CASE("fc2d_clawpack46_vt fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); @@ -113,8 +113,8 @@ TEST_CASE("fc2d_clawpack46_vt fails if not intialized") TEST_CASE("fc2d_clawpack46_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); diff --git a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp index b78ce3198..06376b40f 100644 --- a/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack4.6/fc2d_clawpack46_options.h.TEST.cpp @@ -31,8 +31,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_clawpack46_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_clawpack46_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); fc2d_clawpack46_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1); @@ -57,8 +57,8 @@ TEST_CASE("fc2d_clawpack46_options can store options in two seperate globs") TEST_CASE("fc2d_clawpack46_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc2d_clawpack46_get_options(glob1)); @@ -70,8 +70,8 @@ TEST_CASE("fc2d_clawpack46_get_options fails if not intialized") TEST_CASE("fc2d_clawpack46_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_clawpack46_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1)); CHECK_SC_ABORTED(fc2d_clawpack46_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_clawpack46_options_t,1))); diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp b/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp index 886a075ac..186105d0e 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5.h.TEST.cpp @@ -33,8 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_clawpack5_solver_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); @@ -68,7 +68,7 @@ TEST_CASE("fc2d_clawpack5_solver_initialize stores two seperate vtables in two s TEST_CASE("fc2d_clawpack5_solver_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob, domain); @@ -96,8 +96,8 @@ TEST_CASE("fc2d_clawpack5_solver_initialize sets is_set flag") TEST_CASE("fc2d_clawpack5_vt fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); @@ -114,8 +114,8 @@ TEST_CASE("fc2d_clawpack5_vt fails if not intialized") TEST_CASE("fc2d_clawpack5_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); diff --git a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp index 9a789d0ed..0ebf78b11 100644 --- a/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp +++ b/src/solvers/fc2d_clawpack5/fc2d_clawpack5_options.h.TEST.cpp @@ -31,8 +31,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_clawpack5_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_clawpack5_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1); fc2d_clawpack5_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1); @@ -57,8 +57,8 @@ TEST_CASE("fc2d_clawpack5_options can store options in two seperate globs") TEST_CASE("fc2d_clawpack5_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc2d_clawpack5_get_options(glob1)); @@ -70,8 +70,8 @@ TEST_CASE("fc2d_clawpack5_get_options fails if not intialized") TEST_CASE("fc2d_clawpack5_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_clawpack5_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1)); CHECK_SC_ABORTED(fc2d_clawpack5_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_clawpack5_options_t,1))); diff --git a/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw.h.TEST.cpp b/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw.h.TEST.cpp index 906ab9a22..50494265c 100644 --- a/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw.h.TEST.cpp +++ b/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw.h.TEST.cpp @@ -32,8 +32,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_cudaclaw_solver_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; /* create some empty options structures */ fclaw_clawpatch_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_clawpatch_options_t,1)); @@ -56,7 +56,7 @@ TEST_CASE("fc2d_cudaclaw_solver_initialize stores two seperate vtables in two se TEST_CASE("fc2d_cudaclaw_solver_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; /* create some empty options structures */ fclaw_clawpatch_options_store(glob, FCLAW_ALLOC_ZERO(fclaw_clawpatch_options_t,1)); @@ -75,8 +75,8 @@ TEST_CASE("fc2d_cudaclaw_solver_initialize sets is_set flag") TEST_CASE("fc2d_cudaclaw_vt fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc2d_cudaclaw_vt(glob1)); @@ -88,8 +88,8 @@ TEST_CASE("fc2d_cudaclaw_vt fails if not intialized") TEST_CASE("fc2d_cudaclaw_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; /* create some empty options structures */ fclaw_clawpatch_options_store(glob1, FCLAW_ALLOC_ZERO(fclaw_clawpatch_options_t,1)); diff --git a/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw_options.h.TEST.cpp b/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw_options.h.TEST.cpp index 2c52d9962..1301613a0 100644 --- a/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw_options.h.TEST.cpp +++ b/src/solvers/fc2d_cudaclaw/fc2d_cudaclaw_options.h.TEST.cpp @@ -30,8 +30,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_cudaclaw_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_cudaclaw_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_cudaclaw_options_t,1); fc2d_cudaclaw_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_cudaclaw_options_t,1); @@ -52,8 +52,8 @@ TEST_CASE("fc2d_cudaclaw_options can store options in two seperate globs") TEST_CASE("fc2d_cudaclaw_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc2d_cudaclaw_get_options(glob1)); @@ -65,8 +65,8 @@ TEST_CASE("fc2d_cudaclaw_get_options fails if not intialized") TEST_CASE("fc2d_cudaclaw_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_cudaclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_cudaclaw_options_t,1)); CHECK_SC_ABORTED(fc2d_cudaclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_cudaclaw_options_t,1))); diff --git a/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp b/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp index 71bcf2462..39cfade96 100644 --- a/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp +++ b/src/solvers/fc2d_geoclaw/fc2d_geoclaw.h.TEST.cpp @@ -34,8 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_geoclaw_solver_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); fclaw_global_store_domain(glob1, domain); @@ -77,7 +77,7 @@ TEST_CASE("fc2d_geoclaw_solver_initialize stores two seperate vtables in two sep TEST_CASE("fc2d_geoclaw_solver_initialize sets is_set flag") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* clawpatch_opt = fclaw_clawpatch_options_new(2); @@ -106,8 +106,8 @@ TEST_CASE("fc2d_geoclaw_solver_initialize sets is_set flag") TEST_CASE("fc2d_geoclaw_vt fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); fclaw_global_store_domain(glob1, domain); @@ -124,8 +124,8 @@ TEST_CASE("fc2d_geoclaw_vt fails if not intialized") TEST_CASE("fc2d_geoclaw_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); fclaw_global_store_domain(glob1, domain); diff --git a/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp b/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp index 6ead6a5b6..53fd7d697 100644 --- a/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp +++ b/src/solvers/fc2d_geoclaw/fc2d_geoclaw_options.h.TEST.cpp @@ -30,8 +30,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_geoclaw_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_geoclaw_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1); fc2d_geoclaw_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1); @@ -56,8 +56,8 @@ TEST_CASE("fc2d_geoclaw_options can store options in two seperate globs") TEST_CASE("fc2d_geoclaw_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc2d_geoclaw_get_options(glob1)); @@ -69,8 +69,8 @@ TEST_CASE("fc2d_geoclaw_get_options fails if not intialized") TEST_CASE("fc2d_geoclaw_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_geoclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1)); CHECK_SC_ABORTED(fc2d_geoclaw_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_geoclaw_options_t,1))); diff --git a/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp b/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp index df026918b..62f9e5e13 100644 --- a/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp +++ b/src/solvers/fc2d_thunderegg/fc2d_thunderegg.h.TEST.cpp @@ -32,8 +32,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_thunderegg_solver_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); fclaw_global_store_domain(glob1, domain); @@ -59,7 +59,7 @@ TEST_CASE("fc2d_thunderegg_solver_initialize stores two seperate vtables in two TEST_CASE("fc2d_thunderegg_solver_initialize sets is_set flag") { - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); fclaw_global_store_domain(glob, domain); @@ -82,8 +82,8 @@ TEST_CASE("fc2d_thunderegg_solver_initialize sets is_set flag") TEST_CASE("fc2d_thunderegg_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 1); fclaw_global_store_domain(glob1, domain); diff --git a/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp b/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp index df5dbb260..8c83a80b9 100644 --- a/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp +++ b/src/solvers/fc2d_thunderegg/fc2d_thunderegg_options.h.TEST.cpp @@ -30,8 +30,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc2d_thunderegg_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_thunderegg_options_t* opts1 = FCLAW_ALLOC_ZERO(fc2d_thunderegg_options_t,1); fc2d_thunderegg_options_t* opts2 = FCLAW_ALLOC_ZERO(fc2d_thunderegg_options_t,1); @@ -56,8 +56,8 @@ TEST_CASE("fc2d_thunderegg_options can store options in two seperate globs") TEST_CASE("fc2d_thunderegg_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc2d_thunderegg_get_options(glob1)); @@ -69,8 +69,8 @@ TEST_CASE("fc2d_thunderegg_get_options fails if not intialized") TEST_CASE("fc2d_thunderegg_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc2d_thunderegg_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_thunderegg_options_t,1)); CHECK_SC_ABORTED(fc2d_thunderegg_options_store(glob1, FCLAW_ALLOC_ZERO(fc2d_thunderegg_options_t,1))); diff --git a/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp b/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp index db481095b..949f2bc93 100644 --- a/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp +++ b/src/solvers/fc3d_clawpack46/fc3d_clawpack46.h.TEST.cpp @@ -33,8 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc3d_clawpack46_solver_initialize stores two seperate vtables in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); @@ -72,7 +72,7 @@ TEST_CASE("fc3d_clawpack46_solver_initialize stores two seperate vtables in two TEST_CASE("fc3d_clawpack46_solver_initialize sets is_set flag") { fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); - fclaw_global_t* glob = fclaw_global_new(); + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_global_store_domain(glob, domain); fclaw_clawpatch_options_t* opts = fclaw_clawpatch_options_new(3); @@ -98,8 +98,8 @@ TEST_CASE("fc3d_clawpack46_solver_initialize sets is_set flag") TEST_CASE("fc3d_clawpack46_vt fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); @@ -116,8 +116,8 @@ TEST_CASE("fc3d_clawpack46_vt fails if not intialized") TEST_CASE("fc3d_clawpack46_vtable_initialize fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fclaw_domain_t* domain = fclaw_domain_new_unitsquare(sc_MPI_COMM_WORLD, 0); fclaw_global_store_domain(glob1, domain); diff --git a/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp b/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp index 30b9962ac..1ef6583e9 100644 --- a/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp +++ b/src/solvers/fc3d_clawpack46/fc3d_clawpack46_options.h.TEST.cpp @@ -30,8 +30,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TEST_CASE("fc3d_clawpack46_options can store options in two seperate globs") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc3d_clawpack46_options_t* opts1 = FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1); fc3d_clawpack46_options_t* opts2 = FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1); @@ -56,8 +56,8 @@ TEST_CASE("fc3d_clawpack46_options can store options in two seperate globs") TEST_CASE("fc3d_clawpack46_get_options fails if not intialized") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; CHECK_SC_ABORTED(fc3d_clawpack46_get_options(glob1)); @@ -69,8 +69,8 @@ TEST_CASE("fc3d_clawpack46_get_options fails if not intialized") TEST_CASE("fc3d_clawpack46_options_store fails if called twice on a glob") { - fclaw_global_t* glob1 = fclaw_global_new(); - fclaw_global_t* glob2 = fclaw_global_new(); + fclaw_global_t* glob1 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0);; fc3d_clawpack46_options_store(glob1, FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1)); CHECK_SC_ABORTED(fc3d_clawpack46_options_store(glob1, FCLAW_ALLOC_ZERO(fc3d_clawpack46_options_t,1))); From 8a69e3b29b523e972217a89cfe0c381ca90c9d5f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 27 Mar 2024 11:35:42 -0600 Subject: [PATCH 31/76] add app constructor for glob, store options as attribute --- .../clawpack/advection/3d/swirl/swirl.cpp | 4 +--- src/fclaw_global.c | 21 +++++++++++++++++-- src/fclaw_global.h | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/applications/clawpack/advection/3d/swirl/swirl.cpp b/applications/clawpack/advection/3d/swirl/swirl.cpp index e9ac481f8..1f94824a7 100644 --- a/applications/clawpack/advection/3d/swirl/swirl.cpp +++ b/applications/clawpack/advection/3d/swirl/swirl.cpp @@ -205,9 +205,7 @@ main (int argc, char **argv) if (!vexit) { /* Options have been checked and are valid */ - int size, rank; - sc_MPI_Comm mpicomm = fclaw_app_get_mpi_size_rank (app, &size, &rank); - fclaw_global_t *glob = fclaw_global_new_comm (mpicomm, size, rank); + fclaw_global_t *glob = fclaw_global_new(app); /* Store option packages in glob */ fclaw_options_store (glob, fclaw_opt); diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 6f201238f..52125bbf0 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -38,7 +38,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -fclaw_global_t* fclaw_global_new (void) +static +fclaw_global_t* global_new (void) { fclaw_global_t *glob; @@ -70,10 +71,26 @@ fclaw_global_t* fclaw_global_new (void) return glob; } +fclaw_global_t* fclaw_global_new (fclaw_app_t * app) +{ + fclaw_global_t *glob = global_new (); + + glob->mpicomm = fclaw_app_get_mpi_size_rank(app, &glob->mpisize, &glob->mpirank); + + sc_options_t *sc_options = fclaw_app_get_options(app); + fclaw_global_attribute_store(glob, + "fclaw_options", + sc_options, + NULL, NULL); + + + return glob; +} + fclaw_global_t* fclaw_global_new_comm (sc_MPI_Comm mpicomm, int mpisize, int mpirank) { - fclaw_global_t *glob = fclaw_global_new (); + fclaw_global_t *glob = global_new (); /* * Set the communicator. diff --git a/src/fclaw_global.h b/src/fclaw_global.h index 68ae0eabd..a1d76a278 100644 --- a/src/fclaw_global.h +++ b/src/fclaw_global.h @@ -108,7 +108,7 @@ struct fclaw_package_container; struct fclaw_diagnostics_accumulator; /** Allocate a new global structure. */ -fclaw_global_t* fclaw_global_new (void); +fclaw_global_t* fclaw_global_new (fclaw_app_t * app); fclaw_global_t* fclaw_global_new_comm (sc_MPI_Comm mpicomm, int mpisize, int mpirank); From 9dd140ae92c46b048e14a7d2e23c86ba8fa5f109 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 28 Mar 2024 09:17:10 -0600 Subject: [PATCH 32/76] Fix how data is loaded in restart --- src/fclaw_restart.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 2221e0147..2d378dc21 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -57,6 +57,7 @@ typedef struct pack_iter int pointerno; int reading; }pack_iter_t; + static void get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) { @@ -64,16 +65,32 @@ get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat sc_array_t *patches = user_data->patches; sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); - if(user_data->reading && user_data->pointerno == 0) - { - fclaw_build_mode_t build_mode = FCLAW_BUILD_FOR_UPDATE; + void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); + sc_array_init_data(current_arr, data, user_data->size, 1); + + user_data->curr_index++; +} + +static void +set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) +{ + pack_iter_t *user_data = (pack_iter_t*)user; + sc_array_t *patches = user_data->patches; + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); + + fclaw_build_mode_t build_mode = FCLAW_BUILD_FOR_UPDATE; + + if(user_data->pointerno == 0) + { fclaw_patch_build(user_data->glob, patch, blockno, patchno,(void*) &build_mode); } void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); - sc_array_init_data(current_arr, data, user_data->size, 1); + memcpy(data, sc_array_index(current_arr, 0), user_data->size); + + sc_array_reset(current_arr); user_data->curr_index++; } @@ -153,7 +170,6 @@ void restart (fclaw_global_t * glob, user.size = sizes[i]; user.pointerno = i; user.reading = 1; - fclaw_domain_iterate_patches(glob->domain, get_patches, &user); fc = fclaw_file_read_array(fc, user_string, sizes[i], patches, &errcode); if(strncmp(user_string, names[i], strlen(names[i])) != 0) @@ -162,11 +178,8 @@ void restart (fclaw_global_t * glob, } CHECK_ERROR_CODE(refine_dim, errcode, "restart read patches"); - for(int i = 0; i < glob->domain->local_num_patches; i++) - { - sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, i); - sc_array_reset(current_arr); - } + fclaw_domain_iterate_patches(glob->domain, set_patches, &user); + sc_array_destroy(patches); } From a88d82d8c2dc4bf2e194b9447b7d5b77564a007e Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 28 Mar 2024 10:12:00 -0600 Subject: [PATCH 33/76] write used ini file to restart file --- src/fclaw_restart.c | 83 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 2d378dc21..9b55a8058 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -48,6 +48,63 @@ do { \ } \ } while(0) +static char* +get_used_ini(fclaw_global_t * glob) +{ + char *buffer = NULL; + long length; + if(glob->mpirank == 0) + { + sc_options_t * options = fclaw_global_get_attribute(glob, "fclaw_options"); + int retval = sc_options_save (fclaw_get_package_id (), + FCLAW_VERBOSITY_ERROR, + options, + "fclaw_options.ini.used"); + + // read the entire file into a string + FILE *file = fopen("fclaw_options.ini.used", "r"); + if (file == NULL) + { + printf("Cannot open file\n"); + return NULL; + } + + fseek(file, 0, SEEK_END); + length = ftell(file); + fseek(file, 0, SEEK_SET); + + buffer = FCLAW_ALLOC(char, length + 1); + if (buffer) + { + fread(buffer, 1, length, file); + } + fclose(file); + + buffer[length] = '\0'; + } + //broadcast the lenth + sc_MPI_Bcast(&length, 1, sc_MPI_LONG, 0, glob->mpicomm); + //allocate the buffer on other ranks + if(glob->mpirank != 0) + { + buffer = FCLAW_ALLOC(char, length + 1); + } + FCLAW_ASSERT(buffer != NULL); + //broadcast the string + sc_MPI_Bcast(buffer, length+1, sc_MPI_CHAR, 0, glob->mpicomm); + + return buffer; + + +} + +static void +free_used_ini(void* data) +{ + char* buffer = (char*) data; + FCLAW_FREE(buffer); +} + typedef struct pack_iter { fclaw_global_t * glob; @@ -136,7 +193,7 @@ void restart (fclaw_global_t * glob, sc_array_destroy(partition); } - sc_array_t globsize; + sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); @@ -209,7 +266,29 @@ fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) = fclaw_file_open_write (filename, "ForestClaw data file", glob->domain, &errcode); CHECK_ERROR_CODE(refine_dim , errcode, "restart open file"); - + + char* used_ini = fclaw_global_get_attribute(glob, "fclaw_used_ini"); + if(used_ini == NULL) + { + used_ini = get_used_ini(glob); + fclaw_global_attribute_store(glob, + "fclaw_used_ini", + used_ini, + NULL, + free_used_ini); + } + + size_t used_ini_length = strlen(used_ini); + sc_array_t array; + sc_array_init_data(&array, &used_ini_length, sizeof(size_t), 1); + + fc = fclaw_file_write_block(fc, "used_ini_length", sizeof(size_t), &array, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "write used_ini_length"); + + sc_array_init_data(&array, used_ini, used_ini_length, 1); + fc = fclaw_file_write_block(fc, "used_ini", used_ini_length, &array, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "write used_ini"); + size_t glob_packsize = fclaw_global_packsize(glob); sc_array_t globsize; From 171351e1026353d1f7b97e4b3b8874a099c24097 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 3 Apr 2024 17:10:27 -0600 Subject: [PATCH 34/76] handle return values of write calls correctly in fclaw_file --- src/fclaw_file.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/fclaw_file.c b/src/fclaw_file.c index e5f675a5f..414d2f3a7 100644 --- a/src/fclaw_file.c +++ b/src/fclaw_file.c @@ -60,6 +60,21 @@ static fclaw_file_context_t *wrap_file_3d(fclaw3d_file_context_t *d3) return fc; } +/* handle the return when the returned file context is NULL */ +static +fclaw_file_context_t* handle_return_value(fclaw_file_context_t * fc) +{ + if(fc->d2 == NULL && fc->d3 == NULL) + { + FCLAW_FREE(fc); + return NULL; + } + else + { + return fc; + } +} + fclaw_file_context_t *fclaw_file_open_write (const char *filename, const char *user_string, fclaw_domain_t * domain, @@ -109,18 +124,19 @@ fclaw_file_context_t *fclaw_file_write_block (fclaw_file_context_t * { if(fc->refine_dim == 2) { - return wrap_file_2d(fclaw2d_file_write_block (fc->d2, user_string, - block_size, block_data, errcode)); + fc->d2 = fclaw2d_file_write_block (fc->d2, user_string, + block_size, block_data, errcode); } else if(fc->refine_dim == 3) { - return wrap_file_3d(fclaw3d_file_write_block (fc->d3, user_string, - block_size, block_data, errcode)); + fc->d3 = fclaw3d_file_write_block (fc->d3, user_string, + block_size, block_data, errcode); } else { SC_ABORT_NOT_REACHED (); } + return handle_return_value(fc); } fclaw_file_context_t *fclaw_file_write_array (fclaw_file_context_t * @@ -131,18 +147,19 @@ fclaw_file_context_t *fclaw_file_write_array (fclaw_file_context_t * { if(fc->refine_dim == 2) { - return wrap_file_2d(fclaw2d_file_write_array (fc->d2, user_string, - patch_size, patch_data, errcode)); + fc->d2 = fclaw2d_file_write_array (fc->d2, user_string, + patch_size, patch_data, errcode); } else if(fc->refine_dim == 3) { - return wrap_file_3d(fclaw3d_file_write_array (fc->d3, user_string, - patch_size, patch_data, errcode)); + fc->d3 = fclaw3d_file_write_array (fc->d3, user_string, + patch_size, patch_data, errcode); } else { SC_ABORT_NOT_REACHED (); } + return handle_return_value(fc); } int fclaw_file_read_partition (int refine_dim, @@ -195,21 +212,6 @@ fclaw_file_context_t *fclaw_file_open_read (int refine_dim, } } -/* handle the return when the returned file context is NULL */ -static -fclaw_file_context_t* handle_return_value(fclaw_file_context_t * fc) -{ - if(fc->d2 == NULL && fc->d3 == NULL) - { - FCLAW_FREE(fc); - return NULL; - } - else - { - return fc; - } -} - fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * fc, char *user_string, size_t block_size, From 7e270d2bc650e7f878369287071291ca0141e592 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 24 Apr 2024 13:37:26 -0600 Subject: [PATCH 35/76] remove options packing from swirl_restart --- .../demo/2d/swirl_restart/swirl_options.c | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/applications/demo/2d/swirl_restart/swirl_options.c b/applications/demo/2d/swirl_restart/swirl_options.c index cecb029c8..f5037052c 100644 --- a/applications/demo/2d/swirl_restart/swirl_options.c +++ b/applications/demo/2d/swirl_restart/swirl_options.c @@ -65,45 +65,6 @@ swirl_destroy(user_options_t *user) FCLAW_FREE (user); } -static void -swirl_destroy_void(void *user) -{ - swirl_destroy((user_options_t*) user); -} - -static size_t -options_packsize(void* user) -{ - return sizeof(user_options_t); -} - -static size_t -options_pack(void* user, char* buffer) -{ - user_options_t* opts = (user_options_t*) user; - - //pack entire struct - return FCLAW_PACK(*opts, buffer); -} - -static size_t -options_unpack(char* buffer, void** user) -{ - user_options_t** opts_ptr = (user_options_t**) user; - - *opts_ptr = FCLAW_ALLOC(user_options_t,1); - - return FCLAW_UNPACK(buffer, *opts_ptr); -} - -static fclaw_packing_vtable_t packing_vt = -{ - options_pack, - options_unpack, - options_packsize, - swirl_destroy_void -}; - /* ------- Generic option handling routines that call above routines ----- */ static void* options_register (fclaw_app_t * app, void *package, sc_options_t * opt) @@ -189,8 +150,6 @@ user_options_t* swirl_options_register (fclaw_app_t * app, fclaw_app_set_attribute(app,"user",user); - fclaw_app_register_options_packing_vtable("user", &packing_vt); - return user; } From 134a1c20413de5d2503484a644bab5527ff50dd6 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 24 Apr 2024 13:52:16 -0600 Subject: [PATCH 36/76] rename opiton to checkpoint out, add fclaw_output_checkpoint function --- src/fclaw_options.c | 4 ++-- src/fclaw_options.h | 2 +- src/fclaw_output.c | 13 +------------ src/fclaw_output.h | 16 ++++++++++++++++ src/fclaw_restart.c | 14 ++++++++++++++ src/fclaw_restart.h | 1 - 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/fclaw_options.c b/src/fclaw_options.c index 20e1c7c31..e257da07d 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -124,8 +124,8 @@ fclaw_register (fclaw_options_t* fclaw_opt, sc_options_t * opt) sc_options_add_bool (opt, 0, "output", &fclaw_opt->output, 0, "Enable output [F]"); - sc_options_add_bool (opt, 0, "restart-out", &fclaw_opt->restart_out, 0, - "Enable restart output [F]"); + sc_options_add_bool (opt, 0, "checkpoint-out", &fclaw_opt->checkpoint_out, 0, + "Enable checkpoint output [F]"); /* -------------------------------------- Gauges --------------------------------- */ /* Gauge options */ diff --git a/src/fclaw_options.h b/src/fclaw_options.h index c7a36e63a..a5674cc01 100644 --- a/src/fclaw_options.h +++ b/src/fclaw_options.h @@ -221,7 +221,7 @@ struct fclaw_options int verbosity; /**< TODO: Do we have guidelines here? */ int output; - int restart_out; + int checkpoint_out; int tikz_out; /* Boolean */ const char *tikz_figsize_string; diff --git a/src/fclaw_output.c b/src/fclaw_output.c index 6cc172fb3..76f545383 100644 --- a/src/fclaw_output.c +++ b/src/fclaw_output.c @@ -71,16 +71,5 @@ fclaw_output_frame (fclaw_global_t * glob, int iframe) fclaw2d_output_frame_tikz(glob,iframe); } - if(fclaw_opt->restart_out) - { - fclaw_timer_start (&glob->timers[FCLAW_TIMER_OUTPUT]); - - fclaw_restart_output_frame(glob,iframe); - - fclaw_timer_stop (&glob->timers[FCLAW_TIMER_OUTPUT]); - } + } - - - - diff --git a/src/fclaw_output.h b/src/fclaw_output.h index 85eafd8a3..4bb1d02a2 100644 --- a/src/fclaw_output.h +++ b/src/fclaw_output.h @@ -38,6 +38,22 @@ struct fclaw_global; /* This is a hack !! */ void fclaw_output_frame(struct fclaw_global * glob, int iframe); +/** + * @brief Write out a checkpoint file. + * + * This will only output if the checkpoint_out flag is set in fclaw_options. + * + * This will write two files: a fort_frame_[iframe].checkpoint file and a + * fort_frame_[iframe].partition file. + * + * The partition file is optionally used when restarting to ensure that the + * domain is partitioned in the same way as before. + * + * @param glob the global context + * @param iframe the frame number + */ +void fclaw_output_checkpoint(struct fclaw_global * glob, int iframe); + void fclaw2d_output_frame_tikz(struct fclaw_global* glob, int iframe); #ifdef __cplusplus diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 9b55a8058..5df817b11 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -357,3 +357,17 @@ fclaw_restart_from_file (fclaw_global_t * glob, { restart(glob, restart_filename, partition_filename, FCLAW_TIMER_INIT); } + +void fclaw_output_checkpoint(fclaw_global_t* glob, int iframe) +{ + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); + + if(fclaw_opt->checkpoint_out) + { + fclaw_timer_start (&glob->timers[FCLAW_TIMER_OUTPUT]); + + fclaw_restart_output_frame(glob,iframe); + + fclaw_timer_stop (&glob->timers[FCLAW_TIMER_OUTPUT]); + } +} \ No newline at end of file diff --git a/src/fclaw_restart.h b/src/fclaw_restart.h index 669671c2b..4d45f3b48 100644 --- a/src/fclaw_restart.h +++ b/src/fclaw_restart.h @@ -36,7 +36,6 @@ extern "C" struct fclaw_global; /* This is a hack !! */ -void fclaw_restart_output_frame(struct fclaw_global * glob, int iframe); /** * @brief Restarts the forestclaw simulation from a restart file. From 992ddc88a86e4dcf5cf4cf1ddbf844b61bfa9d0f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 24 Apr 2024 21:48:22 -0600 Subject: [PATCH 37/76] write interface and tests for fclaw_context use in outstyle1 --- src/CMakeLists.txt | 3 + src/Makefile.am | 3 + src/fclaw_context.c | 52 ++++ src/fclaw_context.h | 139 +++++++++++ src/fclaw_context.h.TEST.cpp | 469 +++++++++++++++++++++++++++++++++++ src/fclaw_run.c | 198 ++++----------- 6 files changed, 715 insertions(+), 149 deletions(-) create mode 100644 src/fclaw_context.c create mode 100644 src/fclaw_context.h create mode 100644 src/fclaw_context.h.TEST.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed94410f5..df07dd8a5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ add_library(forestclaw_c OBJECT fclaw_face_neighbors.c fclaw_farraybox.cpp fclaw_file.c + fclaw_context.c fclaw2d_convenience.c fclaw2d_output_tikz.c fclaw2d_file.c @@ -133,6 +134,7 @@ install(FILES fclaw_map_query_defs.h fclaw_diagnostics.h fclaw_file.h + fclaw_context.h forestclaw2d.h fp_exception_glibc_extension.h fclaw2d_convenience.h @@ -159,6 +161,7 @@ if(BUILD_TESTING) fclaw_options.h.TEST.cpp fclaw_patch.h.TEST.cpp fclaw_vtable.h.TEST.cpp + fclaw_context.h.TEST.cpp ) target_link_libraries(forestclaw.TEST testutils forestclaw) diff --git a/src/Makefile.am b/src/Makefile.am index 467852f3e..beb26fd56 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,6 +49,7 @@ libforestclaw_installed_headers = \ src/fclaw_map_query_defs.h \ src/fclaw_diagnostics.h \ src/fclaw_file.h \ + src/fclaw_context.h \ src/forestclaw2d.h \ src/fclaw2d_convenience.h \ src/fp_exception_glibc_extension.h \ @@ -111,6 +112,7 @@ libforestclaw_compiled_sources = \ src/fclaw_face_neighbors.c \ src/fclaw_farraybox.cpp \ src/fclaw_file.c \ + src/fclaws_context.c \ src/fclaw2d_convenience.c \ src/fclaw2d_output_tikz.c \ src/fclaw2d_file.c \ @@ -198,6 +200,7 @@ src_forestclaw_TEST_SOURCES = \ src/fclaw_global.h.TEST.cpp \ src/fclaw_options.h.TEST.cpp \ src/fclaw_patch.h.TEST.cpp \ + src/fclaw_context.h.TEST.cpp \ src/fclaw_vtable.h.TEST.cpp src_forestclaw_TEST_CPPFLAGS = \ diff --git a/src/fclaw_context.c b/src/fclaw_context.c new file mode 100644 index 000000000..f0d4bd11a --- /dev/null +++ b/src/fclaw_context.c @@ -0,0 +1,52 @@ +/* +Copyright (c) 2012-2023 Carsten Burstedde, Donna Calhoun, Scott Aiton +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name) +{ + return NULL; +} + + +void fclaw_context_get_int(fclaw_context_t *context, + const char *name, + int *value, + int default_value) +{ + +} + +void fclaw_context_get_double(fclaw_context_t *context, + const char *name, + double *value, + double default_value) +{ + +} + +void fclaw_context_save(fclaw_context_t *context) +{ + +} \ No newline at end of file diff --git a/src/fclaw_context.h b/src/fclaw_context.h new file mode 100644 index 000000000..b85c099e1 --- /dev/null +++ b/src/fclaw_context.h @@ -0,0 +1,139 @@ +/* +Copyright (c) 2012-2023 Carsten Burstedde, Donna Calhoun, Scott Aiton +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @file + * + * @brief This file contains the declaration of the fclaw_context_t structure and related functions. + * + * The fclaw_context_t structure represents a context for functions that can be paused and resumed. + * It provides functions to retrieve and save values to the context object. + * + * Example usage: + * + * // Get the context object from the global context + * fclaw_context_t *context = fclaw_context_get(glob, "my_context"); + * + * // Get an integer value from the context object + * int value; + * fclaw_context_get_int(context, "my_value", &value, 10); + * + * // Get a double value from the context object + * double value; + * fclaw_context_get_double(context, "my_value", &value, 3.14); + * + * // Save values to the context object + * // This should be called right before exit points in a function + * fclaw_context_save(context); + * + * This is designed with some restrictions in mind: + * - The context object shoulde be retrieved at the beginning of a function with fclaw_context_get. + * - The values should be retrieved with fclaw_context_get_int or fclaw_context_get_double. + * - These should be called in the same manner every time the resumable function is called. + * - If these arent called in the same manner, the program will abort. + * - The values should be saved with fclaw_context_save right before exit points in the function. + * - the save call will save all the variables pointed to in the get_double/int calls. + * + * + */ + +#ifndef FCLAW_CONTEXT_H +#define FCLAW_CONTEXT_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} +#endif +#endif + +/** + * @brief Context structure + */ +typedef struct fclaw_context fclaw_context_t; + +/** + * @brief Get the context object from glob. If the context object does not exist, it is created. + * + * If the context exists, calling the function will reset all pointers associated with the values. + * + * @param glob the global context + * @return fclaw_context_t* the context object + */ +fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name); + +/** + * @brief Get an integer value from the context object. If the value does not exist, the default value is returned. + * + * If this isn't a new context and the value does not exist, an error message is printed and the program aborts. + * + * @param context the context object + * @param name the name of the value + * @param value the value + * @param default_value the default value + */ +void fclaw_context_get_int(fclaw_context_t *context, + const char *name, + int *value, + int default_value); + +/** + * @brief Get a double value from the context object. If the value does not exist, the default value is returned. + * + * If this isn't a new context and the value does not exist, an error message is printed and the program aborts. + * + * @param context the context object + * @param name the name of the value + * @param value the value + * @param default_value the default value + */ +void fclaw_context_get_double(fclaw_context_t *context, + const char *name, + double *value, + double default_value); + +/** + * @brief Save values to the context object. Should be called right before exit points in a function. + * + * This will get the values from the pointers provided in the get functions. + * + * If the context is not new, and all values have not been retrieved, + * this function will abort with an error message. + * + * @param context the context object to save to + */ +void fclaw_context_save(fclaw_context_t *context); + +#ifdef __cplusplus +#if 0 +{ +#endif +} +#endif + +#endif /* !FCLAW_MATH_H */ diff --git a/src/fclaw_context.h.TEST.cpp b/src/fclaw_context.h.TEST.cpp new file mode 100644 index 000000000..3181e8161 --- /dev/null +++ b/src/fclaw_context.h.TEST.cpp @@ -0,0 +1,469 @@ +/* +Copyright (c) 2012-2024 Carsten Burstedde, Donna Calhoun, Scott Aiton +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include + +TEST_CASE("fclaw_context_get new context") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + CHECK_NE(context, nullptr); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get two new contexts") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context1 = fclaw_context_get(glob, "test1"); + fclaw_context_t *context2 = fclaw_context_get(glob, "test2"); + CHECK_NE(context1, nullptr); + CHECK_NE(context2, nullptr); + CHECK_NE(context1, context2); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get existing context") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context1 = fclaw_context_get(glob, "test"); + CHECK_NE(context1, nullptr); + fclaw_context_t *context2 = fclaw_context_get(glob, "test"); + CHECK_EQ(context1, context2); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get two existing contexts") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context1 = fclaw_context_get(glob, "test1"); + fclaw_context_t *context2 = fclaw_context_get(glob, "test2"); + CHECK_NE(context1, nullptr); + CHECK_NE(context2, nullptr); + CHECK_NE(context1, context2); + fclaw_context_t *context3 = fclaw_context_get(glob, "test1"); + fclaw_context_t *context4 = fclaw_context_get(glob, "test2"); + CHECK_EQ(context1, context3); + CHECK_EQ(context2, context4); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_int new context") +{ + for(int default_value : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + int value; + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_int new context two values") +{ + for(int default_value1 : {-100, 0, 42}) + for(int default_value2 : {-1, 1, 1024}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + int value1; + fclaw_context_get_int(context, "test1", &value1, default_value1); + CHECK_EQ(value1, default_value1); + int value2; + fclaw_context_get_int(context, "test2", &value2, default_value2); + CHECK_EQ(value2, default_value2); + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_int existing context") +{ + for(int default_value : {-100, 0, 42}) + for(int changed_value : {-1, 4, 82}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + int value; + + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + fclaw_context_save(context); + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + value = changed_value; + fclaw_context_save(context); + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, changed_value); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_int existing context two values") +{ + for(int default_value1 : {-100, 0, 42}) + for(int changed_value1 : {-1, 4, 82}) + for(int default_value2: {-100, 0, 42}) + for(int changed_value2: {-1, 4, 82}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + int value, value2; + + fclaw_context_get_int(context, "test1", &value, default_value1); + fclaw_context_get_int(context, "test2", &value2, default_value2); + + CHECK_EQ(value, default_value1); + CHECK_EQ(value2, default_value2); + + fclaw_context_save(context); + + fclaw_context_get_int(context, "test1", &value, default_value1); + fclaw_context_get_int(context, "test2", &value2, default_value2); + + CHECK_EQ(value, default_value1); + CHECK_EQ(value2, default_value2); + + value = changed_value1; + value2 = changed_value2; + + fclaw_context_save(context); + + fclaw_context_get_int(context, "test1", &value, default_value1); + fclaw_context_get_int(context, "test2", &value2, default_value2); + + CHECK_EQ(value, changed_value1); + CHECK_EQ(value2, changed_value2); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_int called for non-existing value") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + // second get call, since we didn't get_int in first, should fail + context = fclaw_context_get(glob, "test"); + int value; + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, 0)); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_int called for non-exising value other value") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + int value; + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, 0)); + + // second get call, since we didn't get_int in first, should fail + context = fclaw_context_get(glob, "test"); + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test-does-not-exist", &value, 0)); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_int save without getting all variables") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + int value; + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, 0)); + + // second get call, since we don't get_int, should fail + context = fclaw_context_get(glob, "test"); + CHECK_SC_ABORTED(fclaw_context_save(context)); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_double new context") +{ + for(double default_value : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + double value; + fclaw_context_get_double(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_double new context two values") +{ + for(double default_value1 : {-100, 0, 42}) + for(double default_value2 : {-1, 1, 1024}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + double value1; + fclaw_context_get_double(context, "test1", &value1, default_value1); + CHECK_EQ(value1, default_value1); + double value2; + fclaw_context_get_double(context, "test2", &value2, default_value2); + CHECK_EQ(value2, default_value2); + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_double existing context") +{ + for(double default_value : {-100, 0, 42}) + for(double changed_value : {-1, 4, 82}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + double value; + + fclaw_context_get_double(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + fclaw_context_save(context); + value = 0; + fclaw_context_get_double(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + value = changed_value; + fclaw_context_save(context); + value = 0; + fclaw_context_get_double(context, "test", &value, default_value); + CHECK_EQ(value, changed_value); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_double existing context two values") +{ + for(double default_value1 : {-100, 0, 42}) + for(double changed_value1 : {-1, 4, 82}) + for(double default_value2: {-100, 0, 42}) + for(double changed_value2: {-1, 4, 82}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + double value, value2; + + fclaw_context_get_double(context, "test1", &value, default_value1); + fclaw_context_get_double(context, "test2", &value2, default_value2); + + CHECK_EQ(value, default_value1); + CHECK_EQ(value2, default_value2); + + fclaw_context_save(context); + value = 0; value2 = 0; + + fclaw_context_get_double(context, "test1", &value, default_value1); + fclaw_context_get_double(context, "test2", &value2, default_value2); + + CHECK_EQ(value, default_value1); + CHECK_EQ(value2, default_value2); + + value = changed_value1; + value2 = changed_value2; + + fclaw_context_save(context); + value = 0; value2 = 0; + + fclaw_context_get_double(context, "test1", &value, default_value1); + fclaw_context_get_double(context, "test2", &value2, default_value2); + + CHECK_EQ(value, changed_value1); + CHECK_EQ(value2, changed_value2); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_double called for non-existing value") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + // second get call, since we didn't get_double in first, should fail + context = fclaw_context_get(glob, "test"); + double value; + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value, 0)); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_double called for non-exising value other value") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + double value; + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value, 0)); + + // second get call, since we didn't get_double in first, should fail + context = fclaw_context_get(glob, "test"); + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test-does-not-exist", &value, 0)); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_double save without getting all variables") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + double value; + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value, 0)); + + // second get call, since we don't get_double, should fail + context = fclaw_context_get(glob, "test"); + CHECK_SC_ABORTED(fclaw_context_save(context)); + fclaw_global_destroy(glob); +} + +TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same value") +{ + for(int default_value : {-100, 0, 42}) + for(double default_double : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + int value; + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + double value_double; + fclaw_context_get_double(context, "test2", &value_double, default_double); + CHECK_EQ(value_double, default_double); + + fclaw_context_save(context); + value = 0; value_double = 0; + + fclaw_context_get_int(context, "test", &value, default_value); + fclaw_context_get_double(context, "test2", &value_double, default_double); + + CHECK_EQ(value, default_value); + CHECK_EQ(value_double, default_double); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same key") +{ + for(int default_value : {-100, 0, 42}) + for(double default_double : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + int value; + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + double value_double; + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value_double, default_double)); + + fclaw_global_destroy(glob); + } + + for(int default_value : {-100, 0, 42}) + for(double default_double : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + double value_double; + fclaw_context_get_double(context, "test", &value_double, default_double); + + int value; + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, default_value)); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context pack/unpack glob int and double without save") +{ + for(int default_value : {-100, 0, 42}) + for(double default_double : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + int value; + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + double value_double; + fclaw_context_get_double(context, "test2", &value_double, default_double); + CHECK_EQ(value_double, default_double); + + char buffer[fclaw_global_packsize(glob)]; + CHECK_SC_ABORTED(fclaw_global_pack(glob, buffer)); + + fclaw_global_destroy(glob); + } +} + +TEST_CASE("fclaw_context pack/unpack glob int and double") +{ + for(int default_value : {-100, 0, 42}) + for(double default_double : {-100, 0, 42}) + { + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context = fclaw_context_get(glob, "test"); + + int value; + fclaw_context_get_int(context, "test", &value, default_value); + CHECK_EQ(value, default_value); + + double value_double; + fclaw_context_get_double(context, "test2", &value_double, default_double); + CHECK_EQ(value_double, default_double); + + fclaw_context_save(context); + + char buffer[fclaw_global_packsize(glob)]; + fclaw_global_pack(glob, buffer); + + fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + + fclaw_global_unpack(buffer, glob2); + + fclaw_context_t *context2 = fclaw_context_get(glob2, "test"); + + fclaw_context_get_int(context2, "test", &value, -1); + CHECK_EQ(value, default_value); + + fclaw_context_get_double(context2, "test2", &value_double, -1); + CHECK_EQ(value_double, default_double); + + fclaw_global_destroy(glob); + fclaw_global_destroy(glob2); + } +} \ No newline at end of file diff --git a/src/fclaw_run.c b/src/fclaw_run.c index da24282cf..fd840ade6 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include "fclaw_math.h" @@ -112,87 +113,6 @@ static void outstyle_0(fclaw_global_t *glob) } -typedef -struct outstyle1_ctx -{ - int initalized; - int iframe; - int n; - int n_inner; - double dt_minlevel; -} outstyle1_ctx_t; - -static -size_t packsize_outstyle1_ctx(fclaw_global_t *glob, - void *user) -{ - outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; - size_t size = 0; - size += sizeof(ctx->initalized); - size += sizeof(ctx->iframe); - size += sizeof(ctx->n); - size += sizeof(ctx->n_inner); - size += sizeof(ctx->dt_minlevel); - return size; -} - -static -size_t pack_outstyle1_ctx(fclaw_global_t *glob, - void *user, - char *buffer) -{ - outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; - char* buffer_start = buffer; - buffer += fclaw_pack_int(ctx->initalized,buffer); - buffer += fclaw_pack_int(ctx->iframe,buffer); - buffer += fclaw_pack_int(ctx->n,buffer); - buffer += fclaw_pack_int(ctx->n_inner,buffer); - buffer += fclaw_pack_double(ctx->dt_minlevel,buffer); - return buffer - buffer_start; -} - -static -size_t unpack_outstyle1_ctx(fclaw_global_t *glob, - char *buffer, - void *user) -{ - outstyle1_ctx_t *ctx = (outstyle1_ctx_t*) user; - char* buffer_start = buffer; - buffer += fclaw_unpack_int(buffer,&ctx->initalized); - buffer += fclaw_unpack_int(buffer,&ctx->iframe); - buffer += fclaw_unpack_int(buffer,&ctx->n); - buffer += fclaw_unpack_int(buffer,&ctx->n_inner); - buffer += fclaw_unpack_double(buffer,&ctx->dt_minlevel); - return buffer - buffer_start; -} - -static -void *outstyle1_ctx_new(fclaw_global_t *glob) -{ - outstyle1_ctx_t *ctx = FCLAW_ALLOC_ZERO(outstyle1_ctx_t,1); - return (void*) ctx; -} - -static -void outstyle1_ctx_destroy(void *user) -{ - FCLAW_FREE(user); -} - -#define OUTSTYLE1_CTX_ATTRIBUTE_KEY "fclaw_run_outstyle1_ctx" -#define OUTSTYLE1_CTX_VTABLE_KEY "fclaw_run_outstyle1_ctx_vtable" - -static -fclaw_packing_vtable_t outstyle1_ctx_vt = -{ - pack_outstyle1_ctx, - unpack_outstyle1_ctx, - packsize_outstyle1_ctx, - outstyle1_ctx_new, - outstyle1_ctx_destroy -}; - - /* ------------------------------------------------------------------------------- Output style 1 Output times are at times [0,dT, 2*dT, 3*dT,...,Tfinal], where dT = tfinal/nout @@ -200,54 +120,38 @@ fclaw_packing_vtable_t outstyle1_ctx_vt = static void outstyle_1(fclaw_global_t *glob) { - const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); - outstyle1_ctx_t* ctx = (outstyle1_ctx_t*) fclaw_global_get_attribute(glob, OUTSTYLE1_CTX_ATTRIBUTE_KEY); - if(ctx == NULL) - { - FCLAW_ASSERT(strcmp(fclaw_opt->restart_file,"") == 0); - - ctx = (outstyle1_ctx_t*) outstyle1_ctx_new(glob); - fclaw_global_attribute_store(glob, - OUTSTYLE1_CTX_ATTRIBUTE_KEY, - ctx, - OUTSTYLE1_CTX_VTABLE_KEY, - outstyle1_ctx_destroy); - } fclaw_domain_t** domain = &glob->domain; + /* get context object from glob, if there is none, a new one will be created */ + fclaw_context_t *ctx = fclaw_context_get(glob, "fclaw_run_outstyle1_ctx"); /* Set error to 0 */ int init_flag = 1; /* Store anything that needs to be stored */ fclaw_diagnostics_gather(glob,init_flag); init_flag = 0; - if(!ctx->initalized) - { - ctx->iframe = 0; - fclaw_output_frame(glob,ctx->iframe); - } + int iframe; + fclaw_context_get_int(ctx, "iframe", &iframe, 0); + fclaw_output_frame(glob,iframe); + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); double final_time = fclaw_opt->tfinal; int nout = fclaw_opt->nout; double initial_dt = fclaw_opt->initial_dt; int level_factor = pow_int(2,fclaw_opt->maxlevel - fclaw_opt->minlevel); - if(!ctx->initalized) - { - ctx->dt_minlevel = initial_dt; - } + double dt_minlevel; + fclaw_context_get_double(ctx, "dt_minlevel", &dt_minlevel, initial_dt); double t0 = 0; double dt_outer = (final_time-t0)/((double) nout); - double t_curr = glob->curr_time; + double t_curr = t0; + int n_inner; + fclaw_context_get_int(ctx, "n_inner", &n_inner, 0); - if(!ctx->initalized) - { - ctx->n_inner = 0; - ctx->n = 0; - } - ctx->initalized = 1; - for(/* init above */; ctx->n < nout; ctx->n++) + int n; + fclaw_context_get_int(ctx, "n", &n, 0); + for(/* init above */; n < nout; n++) { double tstart = t_curr; @@ -268,7 +172,7 @@ void outstyle_1(fclaw_global_t *glob) the next step. Of course if 'tend - t_curr > dt_minlevel', then dt_minlevel doesn't change. */ - double dt_step = ctx->dt_minlevel; + double dt_step = dt_minlevel; if (fclaw_opt->advance_one_step) { dt_step /= level_factor; @@ -317,7 +221,7 @@ void outstyle_1(fclaw_global_t *glob) fclaw_opt->minlevel, (*domain)->global_minlevel, (*domain)->global_maxlevel, - ctx->n_inner+1,dt_step, + n_inner+1,dt_step, maxcfl_step, tc); if ((maxcfl_step > fclaw_opt->max_cfl) & fclaw_opt->reduce_cfl) @@ -330,7 +234,7 @@ void outstyle_1(fclaw_global_t *glob) restore_time_step(glob); /* Modify dt_level0 from step used. */ - ctx->dt_minlevel = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + dt_minlevel = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; /* Got back to start of loop, without incrementing step counter or time level */ @@ -339,7 +243,7 @@ void outstyle_1(fclaw_global_t *glob) } /* We are happy with this step */ - ctx->n_inner++; + n_inner++; t_curr += dt_step; @@ -363,10 +267,10 @@ void outstyle_1(fclaw_global_t *glob) /* New time step, which should give a cfl close to the desired cfl. */ - double dt_new = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + double dt_new = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; if (!took_small_step) { - ctx->dt_minlevel = dt_new; + dt_minlevel = dt_new; } else { @@ -383,9 +287,9 @@ void outstyle_1(fclaw_global_t *glob) if (fclaw_opt->regrid_interval > 0) { - if (ctx->n_inner % fclaw_opt->regrid_interval == 0) + if (n_inner % fclaw_opt->regrid_interval == 0) { - fclaw_global_infof("regridding at step %d\n",ctx->n); + fclaw_global_infof("regridding at step %d\n",n); fclaw_regrid(glob); } } @@ -394,8 +298,13 @@ void outstyle_1(fclaw_global_t *glob) /* Output file at every outer loop iteration */ fclaw_diagnostics_gather(glob, init_flag); glob->curr_time = t_curr; - ctx->iframe++; - fclaw_output_frame(glob,ctx->iframe); + iframe++; + fclaw_output_frame(glob,iframe); + + /* save context values */ + fclaw_context_save(ctx); + /* output checkpoint */ + fclaw_output_checkpoint(glob, iframe); } } @@ -407,25 +316,17 @@ static void outstyle_2(fclaw2d_global_t *glob) } #endif -typedef struct outstyle3_ctx -{ - int iframe; - int n; - double dt_minlevel; -} outstyle3_ctx_t; - static void outstyle_3(fclaw_global_t *glob) { - outstyle3_ctx_t* ctx = FCLAW_ALLOC(outstyle3_ctx_t,1); fclaw_domain_t** domain = &glob->domain; int init_flag = 1; fclaw_diagnostics_gather(glob,init_flag); init_flag = 0; - ctx->iframe = 0; - fclaw_output_frame(glob,ctx->iframe); + int iframe = 0; + fclaw_output_frame(glob,iframe); const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); @@ -435,7 +336,7 @@ void outstyle_3(fclaw_global_t *glob) //fclaw2d_time_sync_reset(glob,fclaw_opt->minlevel,fclaw_opt->maxlevel,1); double t0 = 0; - ctx->dt_minlevel = initial_dt; + double dt_minlevel = initial_dt; glob->curr_time = t0; int nstep_outer = fclaw_opt->nout; int nstep_inner = fclaw_opt->nstep; @@ -458,11 +359,11 @@ void outstyle_3(fclaw_global_t *glob) } } - ctx->n = 0; - double t_curr = glob->curr_time; - while (ctx->n < nstep_outer) + int n = 0; + double t_curr = t0; + while (n < nstep_outer) { - double dt_step = ctx->dt_minlevel; + double dt_step = dt_minlevel; if (!fclaw_opt->subcycle && fclaw_opt->advance_one_step) { /* if domain->global_maxlevel < fclaw_opt->maxlevel, this choice @@ -500,7 +401,7 @@ void outstyle_3(fclaw_global_t *glob) level2print, (*domain)->global_minlevel, (*domain)->global_maxlevel, - ctx->n+1,dt_step,maxcfl_step, tc); + n+1,dt_step,maxcfl_step, tc); if (fclaw_opt->reduce_cfl & (maxcfl_step > fclaw_opt->max_cfl)) { @@ -509,7 +410,7 @@ void outstyle_3(fclaw_global_t *glob) fclaw_global_productionf(" WARNING : Maximum CFL exceeded; retaking time step\n"); restore_time_step(glob); - ctx->dt_minlevel = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + dt_minlevel = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; /* Go back to start of loop without incrementing step counter or current time. */ @@ -528,16 +429,16 @@ void outstyle_3(fclaw_global_t *glob) /* New time step, which should give a cfl close to the desired cfl. */ if (!fclaw_opt->use_fixed_dt) { - ctx->dt_minlevel = ctx->dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; + dt_minlevel = dt_minlevel*fclaw_opt->desired_cfl/maxcfl_step; } - ctx->n++; /* Increment outer counter */ + n++; /* Increment outer counter */ if (fclaw_opt->regrid_interval > 0) { - if (ctx->n % nregrid_interval == 0) + if (n % nregrid_interval == 0) { - fclaw_global_infof("regridding at step %d\n",ctx->n); + fclaw_global_infof("regridding at step %d\n",n); fclaw_regrid(glob); } } @@ -547,14 +448,13 @@ void outstyle_3(fclaw_global_t *glob) //fclaw2d_diagnostics_gather(glob,init_flag); } - if (ctx->n % nstep_inner == 0) + if (n % nstep_inner == 0) { - ctx->iframe++; + iframe++; fclaw_diagnostics_gather(glob,init_flag); - fclaw_output_frame(glob,ctx->iframe); + fclaw_output_frame(glob,iframe); } } - FCLAW_FREE(ctx); } @@ -653,7 +553,7 @@ void fclaw_run(fclaw_global_t *glob) } } -void fclaw_run_vtables_initialize(fclaw_global_t *glob) +void fclaw_run_vtables_initialize(struct fclaw_global *glob) { - fclaw_global_vtable_store(glob, OUTSTYLE1_CTX_VTABLE_KEY, &outstyle1_ctx_vt, NULL); -} + +} \ No newline at end of file From a604dc474012cd3101be6ef3890057e0246ac95b Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 25 Apr 2024 10:53:07 -0600 Subject: [PATCH 38/76] context implimented without packing --- src/fclaw_context.c | 145 ++++++++++++++++++++++++++++++++++- src/fclaw_context.h.TEST.cpp | 44 +++++------ 2 files changed, 164 insertions(+), 25 deletions(-) diff --git a/src/fclaw_context.c b/src/fclaw_context.c index f0d4bd11a..042b2762c 100644 --- a/src/fclaw_context.c +++ b/src/fclaw_context.c @@ -24,9 +24,82 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include + +#define PACKING_VTABLE_NAME "fclaw_context_t" + +typedef enum +{ + FCLAW_CONTEXT_INT, + FCLAW_CONTEXT_DOUBLE, + FCLAW_CONTEXT_POINTER +} type_t; + +typedef struct value +{ + type_t type; + union + { + int i; + double d; + } value; + + void *pointer; + +} value_t; + +static void +value_destroy(void *data) +{ + value_t *value = (value_t *)data; + FCLAW_FREE(value); +} + +struct fclaw_context +{ + int initializing; + fclaw_pointer_map_t *values; +}; + +static fclaw_context_t * +context_new() +{ + fclaw_context_t *context = FCLAW_ALLOC(fclaw_context_t, 1); + context->initializing = 1; + context->values = fclaw_pointer_map_new(); + return context; +} + +static void +context_destroy(void *data) +{ + fclaw_context_t *context = (fclaw_context_t *)data; + fclaw_pointer_map_destroy(context->values); + FCLAW_FREE(context); +} + +static void +reset_pointers(const char *key, void *data, void *user) +{ + value_t *value = (value_t *)data; + value->pointer = NULL; +} + fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name) { - return NULL; + fclaw_context_t *context = fclaw_global_get_attribute(glob, name); + + if(context == NULL) + { + context = context_new(); + fclaw_global_attribute_store(glob, name, context, PACKING_VTABLE_NAME, context_destroy); + } + else + { + context->initializing = 0; + fclaw_pointer_map_iterate(context->values, reset_pointers, NULL); + } + + return context; } @@ -35,7 +108,29 @@ void fclaw_context_get_int(fclaw_context_t *context, int *value, int default_value) { - + value_t *v = fclaw_pointer_map_get(context->values, name); + if(v != NULL) + { + if(v->type != FCLAW_CONTEXT_INT) + { + fclaw_abortf("fclaw_context_get_int: Value %s is not an int", name); + } + *value = v->value.i; + } + else if (context->initializing) + { + v = FCLAW_ALLOC(value_t, 1); + v->type = FCLAW_CONTEXT_INT; + v->value.i = default_value; + fclaw_pointer_map_insert(context->values, name, v, value_destroy); + *value = default_value; + } + else + { + fclaw_abortf("fclaw_context_get_int: Value %s not found", name); + } + + v->pointer = value; } void fclaw_context_get_double(fclaw_context_t *context, @@ -43,10 +138,54 @@ void fclaw_context_get_double(fclaw_context_t *context, double *value, double default_value) { + value_t *v = fclaw_pointer_map_get(context->values, name); + if(v != NULL) + { + if(v->type != FCLAW_CONTEXT_DOUBLE) + { + fclaw_abortf("fclaw_context_get_double: Value %s is not a double", name); + } + *value = v->value.d; + } + else if(context->initializing) + { + v = FCLAW_ALLOC(value_t, 1); + v->type = FCLAW_CONTEXT_DOUBLE; + v->value.d = default_value; + fclaw_pointer_map_insert(context->values, name, v, value_destroy); + *value = default_value; + } + else + { + fclaw_abortf("fclaw_context_get_double: Value %s not found", name); + } + v->pointer = value; } -void fclaw_context_save(fclaw_context_t *context) +static +void save_value(const char *key, void *data, void *user) { + value_t *value = (value_t *)data; + if(value->pointer == NULL) + { + fclaw_abortf("fclaw_context_save: Value %s has no pointer", key); + } + if(value->type == FCLAW_CONTEXT_INT) + { + value->value.i = *(int *)value->pointer; + } + else if(value->type == FCLAW_CONTEXT_DOUBLE) + { + value->value.d = *(double *)value->pointer; + } + else + { + SC_ABORT_NOT_REACHED(); + } +} +void fclaw_context_save(fclaw_context_t *context) +{ + fclaw_pointer_map_iterate(context->values, save_value, NULL); } \ No newline at end of file diff --git a/src/fclaw_context.h.TEST.cpp b/src/fclaw_context.h.TEST.cpp index 3181e8161..1fa91158c 100644 --- a/src/fclaw_context.h.TEST.cpp +++ b/src/fclaw_context.h.TEST.cpp @@ -108,19 +108,21 @@ TEST_CASE("fclaw_context_get_int existing context") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; + int value1 = 0; - fclaw_context_get_int(context, "test", &value, default_value); - CHECK_EQ(value, default_value); + fclaw_context_get_int(context, "test", &value1, default_value); + CHECK_EQ(value1, default_value); fclaw_context_save(context); - fclaw_context_get_int(context, "test", &value, default_value); - CHECK_EQ(value, default_value); + int value2 = 0; + fclaw_context_get_int(context, "test", &value2, default_value); + CHECK_EQ(value2, default_value); - value = changed_value; + value2 = changed_value; fclaw_context_save(context); - fclaw_context_get_int(context, "test", &value, default_value); - CHECK_EQ(value, changed_value); + int value3 = 0; + fclaw_context_get_int(context, "test", &value3, default_value); + CHECK_EQ(value3, changed_value); fclaw_global_destroy(glob); } @@ -184,9 +186,8 @@ TEST_CASE("fclaw_context_get_int called for non-exising value other value") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); int value; - CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, 0)); + fclaw_context_get_int(context, "test", &value, 0); - // second get call, since we didn't get_int in first, should fail context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_get_int(context, "test-does-not-exist", &value, 0)); fclaw_global_destroy(glob); @@ -197,7 +198,7 @@ TEST_CASE("fclaw_context_get_int save without getting all variables") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); int value; - CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, 0)); + fclaw_context_get_int(context, "test", &value, 0); // second get call, since we don't get_int, should fail context = fclaw_context_get(glob, "test"); @@ -243,21 +244,21 @@ TEST_CASE("fclaw_context_get_double existing context") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value; + double value = 0; fclaw_context_get_double(context, "test", &value, default_value); CHECK_EQ(value, default_value); fclaw_context_save(context); - value = 0; - fclaw_context_get_double(context, "test", &value, default_value); - CHECK_EQ(value, default_value); + double value2 = 0; + fclaw_context_get_double(context, "test", &value2, default_value); + CHECK_EQ(value2, default_value); - value = changed_value; + value2 = changed_value; fclaw_context_save(context); - value = 0; - fclaw_context_get_double(context, "test", &value, default_value); - CHECK_EQ(value, changed_value); + double value3 = 0; + fclaw_context_get_double(context, "test", &value3, default_value); + CHECK_EQ(value3, changed_value); fclaw_global_destroy(glob); } @@ -323,9 +324,8 @@ TEST_CASE("fclaw_context_get_double called for non-exising value other value") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); double value; - CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value, 0)); + fclaw_context_get_double(context, "test", &value, 0); - // second get call, since we didn't get_double in first, should fail context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_get_double(context, "test-does-not-exist", &value, 0)); fclaw_global_destroy(glob); @@ -336,7 +336,7 @@ TEST_CASE("fclaw_context_get_double save without getting all variables") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); double value; - CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value, 0)); + fclaw_context_get_double(context, "test", &value, 0); // second get call, since we don't get_double, should fail context = fclaw_context_get(glob, "test"); From d9c082b0e60a6de3e68d10790d9ba1940d43f3fb Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Mon, 29 Apr 2024 09:58:01 -0600 Subject: [PATCH 39/76] context tests passing --- src/fclaw_context.c | 132 ++++++++++++++++++++++++++++++++++- src/fclaw_context.h | 9 ++- src/fclaw_context.h.TEST.cpp | 22 ++++++ src/fclaw_forestclaw.c | 3 +- 4 files changed, 163 insertions(+), 3 deletions(-) diff --git a/src/fclaw_context.c b/src/fclaw_context.c index 042b2762c..b4e62f73f 100644 --- a/src/fclaw_context.c +++ b/src/fclaw_context.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2012-2023 Carsten Burstedde, Donna Calhoun, Scott Aiton +Copyright (c) 2012-2024 Carsten Burstedde, Donna Calhoun, Scott Aiton All rights reserved. Redistribution and use in source and binary forms, with or without @@ -24,6 +24,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #define PACKING_VTABLE_NAME "fclaw_context_t" @@ -57,6 +58,7 @@ value_destroy(void *data) struct fclaw_context { int initializing; + int saved; fclaw_pointer_map_t *values; }; @@ -64,6 +66,7 @@ static fclaw_context_t * context_new() { fclaw_context_t *context = FCLAW_ALLOC(fclaw_context_t, 1); + context->saved = 0; context->initializing = 1; context->values = fclaw_pointer_map_new(); return context; @@ -96,6 +99,11 @@ fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name) else { context->initializing = 0; + if(!context->saved) + { + fclaw_abortf("fclaw_context_get: Context needs to be saved before it can be retrieved again"); + } + context->saved = 0; fclaw_pointer_map_iterate(context->values, reset_pointers, NULL); } @@ -188,4 +196,126 @@ void save_value(const char *key, void *data, void *user) void fclaw_context_save(fclaw_context_t *context) { fclaw_pointer_map_iterate(context->values, save_value, NULL); + context->saved = 1; +} + + +static +void pack_value(const char *key, void *data, void *user) +{ + char **buffer = (char **)user; + value_t *value = (value_t *)data; + *buffer += fclaw_pack_string(key, *buffer); + *buffer += fclaw_pack_int(value->type, *buffer); + if(value->type == FCLAW_CONTEXT_INT) + { + *buffer += fclaw_pack_int(value->value.i, *buffer); + } + else if(value->type == FCLAW_CONTEXT_DOUBLE) + { + *buffer += fclaw_pack_double(value->value.d, *buffer); + } + else + { + SC_ABORT_NOT_REACHED(); + } +} + +static +size_t pack_context(fclaw_global_t *glob, void *data, char *buffer) +{ + char* buffer_start = buffer; + fclaw_context_t *context = (fclaw_context_t *)data; + + if(!context->saved) + { + fclaw_abortf("fclaw_context: Context not saved, cannot pack"); + } + + buffer += fclaw_pack_int(fclaw_pointer_map_size(context->values), buffer); + fclaw_pointer_map_iterate(context->values, pack_value, &buffer); + return buffer - buffer_start; +} + +static +void value_packsize(const char *key, void *data, void *user) +{ + size_t *size = (size_t *)user; + value_t *value = (value_t *)data; + *size += fclaw_packsize_string(key); + *size += sizeof(int); + if(value->type == FCLAW_CONTEXT_INT) + { + *size += sizeof(int); + } + else if(value->type == FCLAW_CONTEXT_DOUBLE) + { + *size += sizeof(double); + } + else + { + SC_ABORT_NOT_REACHED(); + } +} + +static +size_t context_packsize(fclaw_global_t *glob, void *data) +{ + fclaw_context_t *context = (fclaw_context_t *)data; + size_t size = sizeof(int); + fclaw_pointer_map_iterate(context->values, value_packsize, &size); + return size; +} + +static +size_t context_unpack(fclaw_global_t *glob, char *buffer, void *data) +{ + char* buffer_start = buffer; + fclaw_context_t *context = (fclaw_context_t *)data; + context->initializing = 0; + context->saved = 1; + int size; + buffer += fclaw_unpack_int(buffer, &size); + int i; + for(i = 0; i < size; ++i) + { + char *key; + buffer += fclaw_unpack_string(buffer, &key); + value_t *value = FCLAW_ALLOC(value_t, 1); + buffer += fclaw_unpack_int(buffer,(int*) &value->type); + if(value->type == FCLAW_CONTEXT_INT) + { + buffer += fclaw_unpack_int(buffer, &value->value.i); + } + else if(value->type == FCLAW_CONTEXT_DOUBLE) + { + buffer += fclaw_unpack_double(buffer, &value->value.d); + } + else + { + SC_ABORT_NOT_REACHED(); + } + value->pointer = NULL; + fclaw_pointer_map_insert(context->values, key, value, value_destroy); + FCLAW_FREE(key); + } + return buffer - buffer_start; +} + +static void* context_new_void(fclaw_global_t *glob) +{ + return context_new(); +} + +fclaw_packing_vtable_t fclaw_context_vtable = { + pack_context, + context_unpack, + context_packsize, + context_new_void, + context_destroy +}; + +void fclaw_context_vtable_initialize(fclaw_global_t *glob) +{ + fclaw_global_vtable_store(glob, PACKING_VTABLE_NAME, &fclaw_context_vtable, NULL); } \ No newline at end of file diff --git a/src/fclaw_context.h b/src/fclaw_context.h index b85c099e1..d2491bce7 100644 --- a/src/fclaw_context.h +++ b/src/fclaw_context.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2012-2023 Carsten Burstedde, Donna Calhoun, Scott Aiton +Copyright (c) 2012-2024 Carsten Burstedde, Donna Calhoun, Scott Aiton All rights reserved. Redistribution and use in source and binary forms, with or without @@ -129,6 +129,13 @@ void fclaw_context_get_double(fclaw_context_t *context, */ void fclaw_context_save(fclaw_context_t *context); +/** + * @brief Initializes the vtable need for packing context objects + * + * @param glob the global context + */ +void fclaw_context_vtable_initialize(fclaw_global_t *glob); + #ifdef __cplusplus #if 0 { diff --git a/src/fclaw_context.h.TEST.cpp b/src/fclaw_context.h.TEST.cpp index 1fa91158c..a2893dc9a 100644 --- a/src/fclaw_context.h.TEST.cpp +++ b/src/fclaw_context.h.TEST.cpp @@ -45,11 +45,22 @@ TEST_CASE("fclaw_context_get two new contexts") fclaw_global_destroy(glob); } +TEST_CASE("fclaw_context_get existing context without saving") +{ + fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_t *context1 = fclaw_context_get(glob, "test"); + CHECK_NE(context1, nullptr); + //should fail since it wasnn't saved + CHECK_SC_ABORTED(fclaw_context_get(glob, "test")); + fclaw_global_destroy(glob); +} + TEST_CASE("fclaw_context_get existing context") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context1 = fclaw_context_get(glob, "test"); CHECK_NE(context1, nullptr); + fclaw_context_save(context1); fclaw_context_t *context2 = fclaw_context_get(glob, "test"); CHECK_EQ(context1, context2); fclaw_global_destroy(glob); @@ -63,6 +74,8 @@ TEST_CASE("fclaw_context_get two existing contexts") CHECK_NE(context1, nullptr); CHECK_NE(context2, nullptr); CHECK_NE(context1, context2); + fclaw_context_save(context1); + fclaw_context_save(context2); fclaw_context_t *context3 = fclaw_context_get(glob, "test1"); fclaw_context_t *context4 = fclaw_context_get(glob, "test2"); CHECK_EQ(context1, context3); @@ -173,6 +186,7 @@ TEST_CASE("fclaw_context_get_int called for non-existing value") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); + fclaw_context_save(context); // second get call, since we didn't get_int in first, should fail context = fclaw_context_get(glob, "test"); @@ -187,6 +201,7 @@ TEST_CASE("fclaw_context_get_int called for non-exising value other value") fclaw_context_t *context = fclaw_context_get(glob, "test"); int value; fclaw_context_get_int(context, "test", &value, 0); + fclaw_context_save(context); context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_get_int(context, "test-does-not-exist", &value, 0)); @@ -199,6 +214,7 @@ TEST_CASE("fclaw_context_get_int save without getting all variables") fclaw_context_t *context = fclaw_context_get(glob, "test"); int value; fclaw_context_get_int(context, "test", &value, 0); + fclaw_context_save(context); // second get call, since we don't get_int, should fail context = fclaw_context_get(glob, "test"); @@ -311,6 +327,7 @@ TEST_CASE("fclaw_context_get_double called for non-existing value") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); + fclaw_context_save(context); // second get call, since we didn't get_double in first, should fail context = fclaw_context_get(glob, "test"); @@ -325,6 +342,7 @@ TEST_CASE("fclaw_context_get_double called for non-exising value other value") fclaw_context_t *context = fclaw_context_get(glob, "test"); double value; fclaw_context_get_double(context, "test", &value, 0); + fclaw_context_save(context); context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_get_double(context, "test-does-not-exist", &value, 0)); @@ -337,6 +355,7 @@ TEST_CASE("fclaw_context_get_double save without getting all variables") fclaw_context_t *context = fclaw_context_get(glob, "test"); double value; fclaw_context_get_double(context, "test", &value, 0); + fclaw_context_save(context); // second get call, since we don't get_double, should fail context = fclaw_context_get(glob, "test"); @@ -413,6 +432,7 @@ TEST_CASE("fclaw_context pack/unpack glob int and double without save") for(double default_double : {-100, 0, 42}) { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_vtable_initialize(glob); fclaw_context_t *context = fclaw_context_get(glob, "test"); int value; @@ -436,6 +456,7 @@ TEST_CASE("fclaw_context pack/unpack glob int and double") for(double default_double : {-100, 0, 42}) { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_vtable_initialize(glob); fclaw_context_t *context = fclaw_context_get(glob, "test"); int value; @@ -452,6 +473,7 @@ TEST_CASE("fclaw_context pack/unpack glob int and double") fclaw_global_pack(glob, buffer); fclaw_global_t* glob2 = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); + fclaw_context_vtable_initialize(glob2); fclaw_global_unpack(buffer, glob2); diff --git a/src/fclaw_forestclaw.c b/src/fclaw_forestclaw.c index 3dab94a04..3a74c4265 100644 --- a/src/fclaw_forestclaw.c +++ b/src/fclaw_forestclaw.c @@ -31,6 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include @@ -42,7 +43,7 @@ void fclaw_vtables_initialize(fclaw_global_t *glob) fclaw_elliptic_vtable_initialize(glob); fclaw_gauges_vtable_initialize(glob); fclaw_ray_vtable_initialize(glob); - fclaw_run_vtables_initialize(glob); + fclaw_context_vtable_initialize(glob); } void fclaw_problem_setup(fclaw_global_t *glob) From ff1a7c18ca6b238e9f30e51fdb367948c0848d47 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Mon, 29 Apr 2024 10:01:00 -0600 Subject: [PATCH 40/76] fclaw_context doc changes --- src/fclaw_context.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fclaw_context.h b/src/fclaw_context.h index d2491bce7..15b30463a 100644 --- a/src/fclaw_context.h +++ b/src/fclaw_context.h @@ -81,6 +81,8 @@ typedef struct fclaw_context fclaw_context_t; * @brief Get the context object from glob. If the context object does not exist, it is created. * * If the context exists, calling the function will reset all pointers associated with the values. + * + * fclaw_context_save needs to be called before the context object can be retrieved again. * * @param glob the global context * @return fclaw_context_t* the context object @@ -90,7 +92,7 @@ fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name); /** * @brief Get an integer value from the context object. If the value does not exist, the default value is returned. * - * If this isn't a new context and the value does not exist, an error message is printed and the program aborts. + * If the context isn't new and the value does not exist, an error message is printed and the program aborts. * * @param context the context object * @param name the name of the value @@ -105,7 +107,7 @@ void fclaw_context_get_int(fclaw_context_t *context, /** * @brief Get a double value from the context object. If the value does not exist, the default value is returned. * - * If this isn't a new context and the value does not exist, an error message is printed and the program aborts. + * If the context isn't new and the value does not exist, an error message is printed and the program aborts. * * @param context the context object * @param name the name of the value @@ -122,7 +124,7 @@ void fclaw_context_get_double(fclaw_context_t *context, * * This will get the values from the pointers provided in the get functions. * - * If the context is not new, and all values have not been retrieved, + * If the context is not new, and all values have not been retrieved (ie fclaw_context_get_int or fclaw_context_get_double), * this function will abort with an error message. * * @param context the context object to save to @@ -130,7 +132,7 @@ void fclaw_context_get_double(fclaw_context_t *context, void fclaw_context_save(fclaw_context_t *context); /** - * @brief Initializes the vtable need for packing context objects + * @brief Initializes the vtable needed for packing context objects * * @param glob the global context */ From 77983c340a3cd949763f1966a285b438c43870d4 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Mon, 29 Apr 2024 16:47:20 -0600 Subject: [PATCH 41/76] check options when restarting --- src/fclaw_base.c | 8 +-- src/fclaw_global.c | 5 ++ src/fclaw_options.c | 28 +++++++++ src/fclaw_restart.c | 148 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 184 insertions(+), 5 deletions(-) diff --git a/src/fclaw_base.c b/src/fclaw_base.c index c0df4d475..22ad740e1 100644 --- a/src/fclaw_base.c +++ b/src/fclaw_base.c @@ -332,10 +332,6 @@ fclaw_app_destroy (fclaw_app_t * a) FCLAW_ASSERT (a->opt_pkg != NULL); FCLAW_ASSERT (a->opt != NULL); - /* destroy central structures */ - sc_keyvalue_destroy (a->attributes); - sc_options_destroy (a->opt); - /* let the options packages clean up their memory */ for (zz = a->opt_pkg->elem_count; zz > 0; --zz) { @@ -350,6 +346,10 @@ fclaw_app_destroy (fclaw_app_t * a) } sc_array_destroy (a->opt_pkg); + /* destroy central structures */ + sc_keyvalue_destroy (a->attributes); + sc_options_destroy (a->opt); + FCLAW_FREE (a); if(packing_vtables!=NULL) fclaw_pointer_map_destroy(packing_vtables); diff --git a/src/fclaw_global.c b/src/fclaw_global.c index 52125bbf0..ac48b00b1 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -83,6 +83,11 @@ fclaw_global_t* fclaw_global_new (fclaw_app_t * app) sc_options, NULL, NULL); + void *fclaw_opt_sections = fclaw_app_get_attribute(app, "fclaw_opt_sections", NULL); + fclaw_global_attribute_store(glob, + "fclaw_opt_sections", + fclaw_opt_sections, + NULL, NULL); return glob; } diff --git a/src/fclaw_options.c b/src/fclaw_options.c index e257da07d..2f879ad03 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -526,6 +526,14 @@ options_destroy (fclaw_app_t * a, void *package, void *registered) /* Destroy option arrays created in post-process */ fclaw_options_destroy (fclaw_opt); + + /* Destroy linked list of section names */ + sc_keyvalue_t * fclaw_opt_sections = fclaw_app_get_attribute(a, "fclaw_opt_sections", NULL); + if(fclaw_opt_sections != NULL) + { + sc_keyvalue_destroy(fclaw_opt_sections); + fclaw_app_set_attribute(a, "fclaw_opt_sections", NULL); + } } static const fclaw_app_options_vtable_t options_vtable = { @@ -561,6 +569,26 @@ fclaw_options_t* fclaw_options_register (fclaw_app_t * a, configfile, &options_vtable, fclaw_opt); + + /* append to list of sections for fclaw_opts */ + sc_keyvalue_t *fclaw_opt_sections = fclaw_app_get_attribute(a, "fclaw_opt_sections", NULL); + if(fclaw_opt_sections == NULL) + { + fclaw_opt_sections = sc_keyvalue_new(); + fclaw_app_set_attribute(a, "fclaw_opt_sections", fclaw_opt_sections); + } + char *key = strdup(section == NULL ? "Options" : section); + char* curr_char = key; + while(*curr_char != '\0') + { + *curr_char = tolower(*curr_char); + curr_char++; + } + /* set to 1 for the section, so if checking the section + exists int the keyvalue, the return value is 1 */ + sc_keyvalue_set_int(fclaw_opt_sections, + key, + 1); return fclaw_opt; } diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 5df817b11..43087ca19 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -35,6 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #define CHECK_ERROR_CODE(refine_dim, errcode, str) \ do { \ @@ -98,6 +99,126 @@ get_used_ini(fclaw_global_t * glob) } +static int +skip_option(sc_keyvalue_t *fclaw_opt_sections, const char* section, const char* key) +{ + int skip = 0; + if(sc_keyvalue_get_int(fclaw_opt_sections, section, 0)) + { + //skip the section: part of the key + const char* key_substr = key + strlen(section) + 1; + if(strcmp(key_substr, "restart-file") == 0) + { + skip = 1; + } + else if(strcmp(key_substr, "partition-file") == 0) + { + skip = 1; + } + } + return skip; +} + +static int +compare_dictionaries(sc_keyvalue_t *fclaw_opt_secitons, + dictionary *expected, + dictionary *actual) +{ + int num_differences = 0; + int nsec = iniparser_getnsec(expected); + for (int i_sec = 0; i_sec < nsec; i_sec++) + { + char* section = iniparser_getsecname(expected, i_sec); + if(strcmp(section, "arguments") != 0) + { + if(iniparser_find_entry(actual,section)) + { + int nkey = iniparser_getsecnkeys(expected, section); + char** keys = iniparser_getseckeys(expected, section); + + for (int i_key = 0; i_key < nkey; i_key++) + { + char* key = keys[i_key]; + if(skip_option(fclaw_opt_secitons, section, key)) + { + continue; + } + + if(iniparser_find_entry(actual, key)) + { + char* expected_value = iniparser_getstring(expected, key, NULL); + char* actual_value = iniparser_getstring(actual, key, NULL); + if(strcmp(expected_value, actual_value) != 0) + { + fclaw_global_productionf("%s has mismatched value for %s: %s != %s.\n", section, key, expected_value, actual_value); + num_differences++; + } + + } + else + { + //fclaw_global_productionf("%s has unused option %s.\n", filename, keys[i_key]); + } + } + free (keys); + } + else + { + //fclaw_global_productionf("%s has unused section [%s].\n", filename, section); + } + } + } + return num_differences; +} + +static void +check_options(fclaw_global_t * glob, const char* checkpoint_ini) +{ + if(glob->mpirank == 0) + { + fclaw_global_productionf("=========== Comparing with options stored in checkpoint ===========\n"); + fclaw_global_productionf("\n"); + + //save the used ini file + sc_options_t * options = fclaw_global_get_attribute(glob, "fclaw_options"); + int retval = sc_options_save (fclaw_get_package_id (), + FCLAW_VERBOSITY_ERROR, + options, + "fclaw_options.ini.used"); + + //save the restart ini file to fclaw_options.ini.checkpoint + FILE *file = fopen("fclaw_options.ini.checkpoint", "w"); + if (file == NULL) + { + printf("Cannot open file\n"); + return; + } + fprintf(file, "%s", checkpoint_ini); + fclose(file); + + fclaw_global_productionf("Checkpoints options saved to fclaw_options.ini.checkpoint\n"); + fclaw_global_productionf("\n"); + + dictionary *actual = iniparser_load("fclaw_options.ini.used"); + dictionary *expected = iniparser_load("fclaw_options.ini.checkpoint"); + + sc_keyvalue_t *fclaw_opt_sections + = fclaw_global_get_attribute(glob, "fclaw_opt_sections"); + int num_differences = compare_dictionaries(fclaw_opt_sections, expected, actual); + + iniparser_freedict(actual); + iniparser_freedict(expected); + + if(num_differences == 0) + { + fclaw_global_productionf("No differences found.\n"); + } + + fclaw_global_productionf("\n"); + fclaw_global_productionf("===================================================================\n"); + } +} + static void free_used_ini(void* data) { @@ -152,6 +273,14 @@ set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat user_data->curr_index++; } +static +void check_user_string(const char* expected, const char* actual) +{ + if(strncmp(expected, actual, strlen(expected)) != 0) + { + fclaw_abortf("User string mismatch: %s != %s\n", expected, actual); + } +} static void restart (fclaw_global_t * glob, const char* restart_filename, @@ -192,8 +321,25 @@ void restart (fclaw_global_t * glob, { sc_array_destroy(partition); } + sc_array_t array; + sc_array_init_size(&array, sizeof(size_t), 1); + fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &array, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "restart read used_ini_length"); + check_user_string("used_ini_length", user_string); + + size_t ini_length = *((size_t*) sc_array_index(&array, 0)); + sc_array_reset(&array); + + sc_array_init_size(&array, ini_length, 1); + fc = fclaw_file_read_block(fc, user_string, ini_length, &array, &errcode); + const char* used_ini = (const char*) sc_array_index(&array, 0); + check_options(glob, used_ini); - sc_array_t globsize; + + CHECK_ERROR_CODE(refine_dim, errcode, "restart read used_ini"); + sc_array_reset(&array); + + sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); From 82084df027874adefc0110c3fe42c3de37f2bde2 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Mon, 29 Apr 2024 16:47:58 -0600 Subject: [PATCH 42/76] change for loop to while loop for oustyle_1 --- src/fclaw_run.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fclaw_run.c b/src/fclaw_run.c index fd840ade6..c29903f09 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -151,7 +151,7 @@ void outstyle_1(fclaw_global_t *glob) int n; fclaw_context_get_int(ctx, "n", &n, 0); - for(/* init above */; n < nout; n++) + while(n < nout) { double tstart = t_curr; @@ -301,6 +301,10 @@ void outstyle_1(fclaw_global_t *glob) iframe++; fclaw_output_frame(glob,iframe); + /* increment n before checkpoint since we want to start at next + iteration when restarting */ + n++; + /* save context values */ fclaw_context_save(ctx); /* output checkpoint */ From 7f6cb7887a78f21c95c1c5e1f19d91fff07c1461 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Mon, 29 Apr 2024 21:05:55 -0600 Subject: [PATCH 43/76] make other outstyles restartable --- src/fclaw_run.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/fclaw_run.c b/src/fclaw_run.c index c29903f09..7c76aaf1d 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -145,7 +145,8 @@ void outstyle_1(fclaw_global_t *glob) double t0 = 0; double dt_outer = (final_time-t0)/((double) nout); - double t_curr = t0; + double t_curr; + fclaw_context_get_double(ctx, "t_curr", &t_curr, t0); int n_inner; fclaw_context_get_int(ctx, "n_inner", &n_inner, 0); @@ -324,12 +325,15 @@ static void outstyle_3(fclaw_global_t *glob) { fclaw_domain_t** domain = &glob->domain; + /* get context object from glob, if there is none, a new one will be created */ + fclaw_context_t *ctx = fclaw_context_get(glob, "fclaw_run_outstyle3_ctx"); int init_flag = 1; fclaw_diagnostics_gather(glob,init_flag); init_flag = 0; int iframe = 0; + fclaw_context_get_int(ctx, "iframe", &iframe, 0); fclaw_output_frame(glob,iframe); @@ -341,6 +345,7 @@ void outstyle_3(fclaw_global_t *glob) double t0 = 0; double dt_minlevel = initial_dt; + fclaw_context_get_double(ctx, "dt_minlevel", &dt_minlevel, initial_dt); glob->curr_time = t0; int nstep_outer = fclaw_opt->nout; int nstep_inner = fclaw_opt->nstep; @@ -364,7 +369,9 @@ void outstyle_3(fclaw_global_t *glob) } int n = 0; + fclaw_context_get_int(ctx, "n", &n, 0); double t_curr = t0; + fclaw_context_get_double(ctx, "t_curr", &t_curr, t0); while (n < nstep_outer) { double dt_step = dt_minlevel; @@ -457,6 +464,11 @@ void outstyle_3(fclaw_global_t *glob) iframe++; fclaw_diagnostics_gather(glob,init_flag); fclaw_output_frame(glob,iframe); + + /* save context values */ + fclaw_context_save(ctx); + /* output checkpoint */ + fclaw_output_checkpoint(glob, iframe); } } } @@ -465,9 +477,12 @@ void outstyle_3(fclaw_global_t *glob) static void outstyle_4(fclaw_global_t *glob) { + /* get context object from glob, if there is none, a new one will be created */ + fclaw_context_t *ctx = fclaw_context_get(glob, "fclaw_run_outstyle4_ctx"); /* Write out an initial time file */ int iframe = 0; + fclaw_context_get_int(ctx, "iframe", &iframe, 0); fclaw_output_frame(glob,iframe); int init_flag = 1; @@ -482,8 +497,10 @@ void outstyle_4(fclaw_global_t *glob) double t0 = 0; double t_curr = t0; + fclaw_context_get_double(ctx, "t_curr", &t_curr, t0); glob->curr_time = t_curr; int n = 0; + fclaw_context_get_int(ctx, "n", &n, 0); while (n < nstep_outer) { /* Get current domain data since it may change during regrid */ @@ -520,6 +537,11 @@ void outstyle_4(fclaw_global_t *glob) fclaw_diagnostics_gather(glob,init_flag); iframe++; fclaw_output_frame(glob,iframe); + + /* save context values */ + fclaw_context_save(ctx); + /* output checkpoint */ + fclaw_output_checkpoint(glob, iframe); } } } From c41fb72df13497b514fe4acbbf60445dccf54be6 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Mon, 29 Apr 2024 21:19:14 -0600 Subject: [PATCH 44/76] remove default arguments from fclaw_context --- src/fclaw_context.c | 10 +-- src/fclaw_context.h | 18 ++--- src/fclaw_context.h.TEST.cpp | 147 ++++++++++++++++++----------------- src/fclaw_run.c | 34 ++++---- 4 files changed, 102 insertions(+), 107 deletions(-) diff --git a/src/fclaw_context.c b/src/fclaw_context.c index b4e62f73f..66968f355 100644 --- a/src/fclaw_context.c +++ b/src/fclaw_context.c @@ -113,8 +113,7 @@ fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name) void fclaw_context_get_int(fclaw_context_t *context, const char *name, - int *value, - int default_value) + int *value) { value_t *v = fclaw_pointer_map_get(context->values, name); if(v != NULL) @@ -129,9 +128,7 @@ void fclaw_context_get_int(fclaw_context_t *context, { v = FCLAW_ALLOC(value_t, 1); v->type = FCLAW_CONTEXT_INT; - v->value.i = default_value; fclaw_pointer_map_insert(context->values, name, v, value_destroy); - *value = default_value; } else { @@ -143,8 +140,7 @@ void fclaw_context_get_int(fclaw_context_t *context, void fclaw_context_get_double(fclaw_context_t *context, const char *name, - double *value, - double default_value) + double *value) { value_t *v = fclaw_pointer_map_get(context->values, name); if(v != NULL) @@ -159,9 +155,7 @@ void fclaw_context_get_double(fclaw_context_t *context, { v = FCLAW_ALLOC(value_t, 1); v->type = FCLAW_CONTEXT_DOUBLE; - v->value.d = default_value; fclaw_pointer_map_insert(context->values, name, v, value_destroy); - *value = default_value; } else { diff --git a/src/fclaw_context.h b/src/fclaw_context.h index 15b30463a..81bec5c74 100644 --- a/src/fclaw_context.h +++ b/src/fclaw_context.h @@ -90,34 +90,32 @@ typedef struct fclaw_context fclaw_context_t; fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name); /** - * @brief Get an integer value from the context object. If the value does not exist, the default value is returned. + * @brief Get an integer value from the context object. + * If the value does not exist, the current value does not change. * * If the context isn't new and the value does not exist, an error message is printed and the program aborts. * * @param context the context object * @param name the name of the value - * @param value the value - * @param default_value the default value + * @param value a pointer the value, if the value does not exist, the value is not changed */ void fclaw_context_get_int(fclaw_context_t *context, const char *name, - int *value, - int default_value); + int *value); /** - * @brief Get a double value from the context object. If the value does not exist, the default value is returned. + * @brief Get a double value from the context object. + * If the value does not exist, the current value does not change. * * If the context isn't new and the value does not exist, an error message is printed and the program aborts. * * @param context the context object * @param name the name of the value - * @param value the value - * @param default_value the default value + * @param value a pointer the value, if the value does not exist, the value is not changed */ void fclaw_context_get_double(fclaw_context_t *context, const char *name, - double *value, - double default_value); + double *value); /** * @brief Save values to the context object. Should be called right before exit points in a function. diff --git a/src/fclaw_context.h.TEST.cpp b/src/fclaw_context.h.TEST.cpp index a2893dc9a..8afcb2653 100644 --- a/src/fclaw_context.h.TEST.cpp +++ b/src/fclaw_context.h.TEST.cpp @@ -89,8 +89,8 @@ TEST_CASE("fclaw_context_get_int new context") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, default_value); + int value = default_value; + fclaw_context_get_int(context, "test", &value); CHECK_EQ(value, default_value); fclaw_global_destroy(glob); } @@ -103,11 +103,11 @@ TEST_CASE("fclaw_context_get_int new context two values") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value1; - fclaw_context_get_int(context, "test1", &value1, default_value1); + int value1 = default_value1; + fclaw_context_get_int(context, "test1", &value1); CHECK_EQ(value1, default_value1); - int value2; - fclaw_context_get_int(context, "test2", &value2, default_value2); + int value2 = default_value2; + fclaw_context_get_int(context, "test2", &value2); CHECK_EQ(value2, default_value2); fclaw_global_destroy(glob); } @@ -121,20 +121,20 @@ TEST_CASE("fclaw_context_get_int existing context") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value1 = 0; + int value1 = default_value; - fclaw_context_get_int(context, "test", &value1, default_value); + fclaw_context_get_int(context, "test", &value1); CHECK_EQ(value1, default_value); fclaw_context_save(context); int value2 = 0; - fclaw_context_get_int(context, "test", &value2, default_value); + fclaw_context_get_int(context, "test", &value2); CHECK_EQ(value2, default_value); value2 = changed_value; fclaw_context_save(context); int value3 = 0; - fclaw_context_get_int(context, "test", &value3, default_value); + fclaw_context_get_int(context, "test", &value3); CHECK_EQ(value3, changed_value); fclaw_global_destroy(glob); @@ -151,18 +151,19 @@ TEST_CASE("fclaw_context_get_int existing context two values") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value, value2; + int value = default_value1; + int value2 = default_value2; - fclaw_context_get_int(context, "test1", &value, default_value1); - fclaw_context_get_int(context, "test2", &value2, default_value2); + fclaw_context_get_int(context, "test1", &value); + fclaw_context_get_int(context, "test2", &value2); CHECK_EQ(value, default_value1); CHECK_EQ(value2, default_value2); fclaw_context_save(context); - fclaw_context_get_int(context, "test1", &value, default_value1); - fclaw_context_get_int(context, "test2", &value2, default_value2); + fclaw_context_get_int(context, "test1", &value); + fclaw_context_get_int(context, "test2", &value2); CHECK_EQ(value, default_value1); CHECK_EQ(value2, default_value2); @@ -172,8 +173,8 @@ TEST_CASE("fclaw_context_get_int existing context two values") fclaw_context_save(context); - fclaw_context_get_int(context, "test1", &value, default_value1); - fclaw_context_get_int(context, "test2", &value2, default_value2); + fclaw_context_get_int(context, "test1", &value); + fclaw_context_get_int(context, "test2", &value2); CHECK_EQ(value, changed_value1); CHECK_EQ(value2, changed_value2); @@ -191,7 +192,7 @@ TEST_CASE("fclaw_context_get_int called for non-existing value") // second get call, since we didn't get_int in first, should fail context = fclaw_context_get(glob, "test"); int value; - CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, 0)); + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value)); fclaw_global_destroy(glob); } @@ -199,12 +200,12 @@ TEST_CASE("fclaw_context_get_int called for non-exising value other value") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, 0); + int value = 0; + fclaw_context_get_int(context, "test", &value); fclaw_context_save(context); context = fclaw_context_get(glob, "test"); - CHECK_SC_ABORTED(fclaw_context_get_int(context, "test-does-not-exist", &value, 0)); + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test-does-not-exist", &value)); fclaw_global_destroy(glob); } @@ -212,8 +213,8 @@ TEST_CASE("fclaw_context_get_int save without getting all variables") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, 0); + int value = 0; + fclaw_context_get_int(context, "test", &value); fclaw_context_save(context); // second get call, since we don't get_int, should fail @@ -228,8 +229,8 @@ TEST_CASE("fclaw_context_get_double new context") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value; - fclaw_context_get_double(context, "test", &value, default_value); + double value = default_value; + fclaw_context_get_double(context, "test", &value); CHECK_EQ(value, default_value); fclaw_global_destroy(glob); } @@ -242,11 +243,11 @@ TEST_CASE("fclaw_context_get_double new context two values") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value1; - fclaw_context_get_double(context, "test1", &value1, default_value1); + double value1 = default_value1; + fclaw_context_get_double(context, "test1", &value1); CHECK_EQ(value1, default_value1); - double value2; - fclaw_context_get_double(context, "test2", &value2, default_value2); + double value2 = default_value2; + fclaw_context_get_double(context, "test2", &value2); CHECK_EQ(value2, default_value2); fclaw_global_destroy(glob); } @@ -260,20 +261,20 @@ TEST_CASE("fclaw_context_get_double existing context") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value = 0; + double value = default_value; - fclaw_context_get_double(context, "test", &value, default_value); + fclaw_context_get_double(context, "test", &value); CHECK_EQ(value, default_value); fclaw_context_save(context); double value2 = 0; - fclaw_context_get_double(context, "test", &value2, default_value); + fclaw_context_get_double(context, "test", &value2); CHECK_EQ(value2, default_value); value2 = changed_value; fclaw_context_save(context); double value3 = 0; - fclaw_context_get_double(context, "test", &value3, default_value); + fclaw_context_get_double(context, "test", &value3); CHECK_EQ(value3, changed_value); fclaw_global_destroy(glob); @@ -290,10 +291,11 @@ TEST_CASE("fclaw_context_get_double existing context two values") fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value, value2; + double value = default_value1; + double value2 = default_value2; - fclaw_context_get_double(context, "test1", &value, default_value1); - fclaw_context_get_double(context, "test2", &value2, default_value2); + fclaw_context_get_double(context, "test1", &value); + fclaw_context_get_double(context, "test2", &value2); CHECK_EQ(value, default_value1); CHECK_EQ(value2, default_value2); @@ -301,8 +303,8 @@ TEST_CASE("fclaw_context_get_double existing context two values") fclaw_context_save(context); value = 0; value2 = 0; - fclaw_context_get_double(context, "test1", &value, default_value1); - fclaw_context_get_double(context, "test2", &value2, default_value2); + fclaw_context_get_double(context, "test1", &value); + fclaw_context_get_double(context, "test2", &value2); CHECK_EQ(value, default_value1); CHECK_EQ(value2, default_value2); @@ -313,8 +315,8 @@ TEST_CASE("fclaw_context_get_double existing context two values") fclaw_context_save(context); value = 0; value2 = 0; - fclaw_context_get_double(context, "test1", &value, default_value1); - fclaw_context_get_double(context, "test2", &value2, default_value2); + fclaw_context_get_double(context, "test1", &value); + fclaw_context_get_double(context, "test2", &value2); CHECK_EQ(value, changed_value1); CHECK_EQ(value2, changed_value2); @@ -332,7 +334,7 @@ TEST_CASE("fclaw_context_get_double called for non-existing value") // second get call, since we didn't get_double in first, should fail context = fclaw_context_get(glob, "test"); double value; - CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value, 0)); + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value)); fclaw_global_destroy(glob); } @@ -340,12 +342,12 @@ TEST_CASE("fclaw_context_get_double called for non-exising value other value") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value; - fclaw_context_get_double(context, "test", &value, 0); + double value = 0; + fclaw_context_get_double(context, "test", &value); fclaw_context_save(context); context = fclaw_context_get(glob, "test"); - CHECK_SC_ABORTED(fclaw_context_get_double(context, "test-does-not-exist", &value, 0)); + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test-does-not-exist", &value)); fclaw_global_destroy(glob); } @@ -353,8 +355,8 @@ TEST_CASE("fclaw_context_get_double save without getting all variables") { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value; - fclaw_context_get_double(context, "test", &value, 0); + double value = 0; + fclaw_context_get_double(context, "test", &value); fclaw_context_save(context); // second get call, since we don't get_double, should fail @@ -371,19 +373,19 @@ TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same va fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, default_value); + int value = default_value; + fclaw_context_get_int(context, "test", &value); CHECK_EQ(value, default_value); - double value_double; - fclaw_context_get_double(context, "test2", &value_double, default_double); + double value_double = default_double; + fclaw_context_get_double(context, "test2", &value_double); CHECK_EQ(value_double, default_double); fclaw_context_save(context); value = 0; value_double = 0; - fclaw_context_get_int(context, "test", &value, default_value); - fclaw_context_get_double(context, "test2", &value_double, default_double); + fclaw_context_get_int(context, "test", &value); + fclaw_context_get_double(context, "test2", &value_double); CHECK_EQ(value, default_value); CHECK_EQ(value_double, default_double); @@ -400,27 +402,26 @@ TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same ke fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, default_value); + int value = default_value; + fclaw_context_get_int(context, "test", &value); CHECK_EQ(value, default_value); - double value_double; - CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value_double, default_double)); + double value_double = default_double; + CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value_double)); fclaw_global_destroy(glob); } - for(int default_value : {-100, 0, 42}) for(double default_double : {-100, 0, 42}) { fclaw_global_t* glob = fclaw_global_new_comm(sc_MPI_COMM_SELF, 1, 0); fclaw_context_t *context = fclaw_context_get(glob, "test"); - double value_double; - fclaw_context_get_double(context, "test", &value_double, default_double); + double value_double = default_double; + fclaw_context_get_double(context, "test", &value_double); int value; - CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value, default_value)); + CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value)); fclaw_global_destroy(glob); } @@ -435,12 +436,12 @@ TEST_CASE("fclaw_context pack/unpack glob int and double without save") fclaw_context_vtable_initialize(glob); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, default_value); + int value = default_value; + fclaw_context_get_int(context, "test", &value); CHECK_EQ(value, default_value); - double value_double; - fclaw_context_get_double(context, "test2", &value_double, default_double); + double value_double = default_double; + fclaw_context_get_double(context, "test2", &value_double); CHECK_EQ(value_double, default_double); char buffer[fclaw_global_packsize(glob)]; @@ -459,12 +460,12 @@ TEST_CASE("fclaw_context pack/unpack glob int and double") fclaw_context_vtable_initialize(glob); fclaw_context_t *context = fclaw_context_get(glob, "test"); - int value; - fclaw_context_get_int(context, "test", &value, default_value); + int value = default_value; + fclaw_context_get_int(context, "test", &value); CHECK_EQ(value, default_value); - double value_double; - fclaw_context_get_double(context, "test2", &value_double, default_double); + double value_double = default_double; + fclaw_context_get_double(context, "test2", &value_double); CHECK_EQ(value_double, default_double); fclaw_context_save(context); @@ -478,12 +479,14 @@ TEST_CASE("fclaw_context pack/unpack glob int and double") fclaw_global_unpack(buffer, glob2); fclaw_context_t *context2 = fclaw_context_get(glob2, "test"); + int value2 = 0; + double value_double2 = 0; - fclaw_context_get_int(context2, "test", &value, -1); - CHECK_EQ(value, default_value); + fclaw_context_get_int(context2, "test", &value2); + CHECK_EQ(value2, default_value); - fclaw_context_get_double(context2, "test2", &value_double, -1); - CHECK_EQ(value_double, default_double); + fclaw_context_get_double(context2, "test2", &value_double2); + CHECK_EQ(value_double2, default_double); fclaw_global_destroy(glob); fclaw_global_destroy(glob2); diff --git a/src/fclaw_run.c b/src/fclaw_run.c index 7c76aaf1d..3ffb6b3fb 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -129,8 +129,8 @@ void outstyle_1(fclaw_global_t *glob) fclaw_diagnostics_gather(glob,init_flag); init_flag = 0; - int iframe; - fclaw_context_get_int(ctx, "iframe", &iframe, 0); + int iframe = 0; + fclaw_context_get_int(ctx, "iframe", &iframe); fclaw_output_frame(glob,iframe); const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); @@ -139,19 +139,19 @@ void outstyle_1(fclaw_global_t *glob) int nout = fclaw_opt->nout; double initial_dt = fclaw_opt->initial_dt; int level_factor = pow_int(2,fclaw_opt->maxlevel - fclaw_opt->minlevel); - double dt_minlevel; - fclaw_context_get_double(ctx, "dt_minlevel", &dt_minlevel, initial_dt); + double dt_minlevel = initial_dt; + fclaw_context_get_double(ctx, "dt_minlevel", &dt_minlevel); double t0 = 0; double dt_outer = (final_time-t0)/((double) nout); - double t_curr; - fclaw_context_get_double(ctx, "t_curr", &t_curr, t0); - int n_inner; - fclaw_context_get_int(ctx, "n_inner", &n_inner, 0); + double t_curr = t0; + fclaw_context_get_double(ctx, "t_curr", &t_curr); + int n_inner = 0; + fclaw_context_get_int(ctx, "n_inner", &n_inner); - int n; - fclaw_context_get_int(ctx, "n", &n, 0); + int n = 0; + fclaw_context_get_int(ctx, "n", &n); while(n < nout) { double tstart = t_curr; @@ -333,7 +333,7 @@ void outstyle_3(fclaw_global_t *glob) init_flag = 0; int iframe = 0; - fclaw_context_get_int(ctx, "iframe", &iframe, 0); + fclaw_context_get_int(ctx, "iframe", &iframe); fclaw_output_frame(glob,iframe); @@ -345,7 +345,7 @@ void outstyle_3(fclaw_global_t *glob) double t0 = 0; double dt_minlevel = initial_dt; - fclaw_context_get_double(ctx, "dt_minlevel", &dt_minlevel, initial_dt); + fclaw_context_get_double(ctx, "dt_minlevel", &dt_minlevel); glob->curr_time = t0; int nstep_outer = fclaw_opt->nout; int nstep_inner = fclaw_opt->nstep; @@ -369,9 +369,9 @@ void outstyle_3(fclaw_global_t *glob) } int n = 0; - fclaw_context_get_int(ctx, "n", &n, 0); + fclaw_context_get_int(ctx, "n", &n); double t_curr = t0; - fclaw_context_get_double(ctx, "t_curr", &t_curr, t0); + fclaw_context_get_double(ctx, "t_curr", &t_curr); while (n < nstep_outer) { double dt_step = dt_minlevel; @@ -482,7 +482,7 @@ void outstyle_4(fclaw_global_t *glob) /* Write out an initial time file */ int iframe = 0; - fclaw_context_get_int(ctx, "iframe", &iframe, 0); + fclaw_context_get_int(ctx, "iframe", &iframe); fclaw_output_frame(glob,iframe); int init_flag = 1; @@ -497,10 +497,10 @@ void outstyle_4(fclaw_global_t *glob) double t0 = 0; double t_curr = t0; - fclaw_context_get_double(ctx, "t_curr", &t_curr, t0); + fclaw_context_get_double(ctx, "t_curr", &t_curr); glob->curr_time = t_curr; int n = 0; - fclaw_context_get_int(ctx, "n", &n, 0); + fclaw_context_get_int(ctx, "n", &n); while (n < nstep_outer) { /* Get current domain data since it may change during regrid */ From 8e8ae55478a0dc75a454798a1af9fc2b56810046 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 14 May 2024 09:52:53 -0600 Subject: [PATCH 45/76] rename options --- src/fclaw_options.c | 27 ++++++++++++++++----------- src/fclaw_options.h | 10 ++++++---- src/fclaw_restart.c | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/fclaw_options.c b/src/fclaw_options.c index 2f879ad03..c9a97597e 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -124,9 +124,24 @@ fclaw_register (fclaw_options_t* fclaw_opt, sc_options_t * opt) sc_options_add_bool (opt, 0, "output", &fclaw_opt->output, 0, "Enable output [F]"); - sc_options_add_bool (opt, 0, "checkpoint-out", &fclaw_opt->checkpoint_out, 0, + sc_options_add_bool (opt, 0, "checkpoint", &fclaw_opt->checkpoint, 0, "Enable checkpoint output [F]"); + /* ------------------------------- Restart options --------------------------------- */ + + sc_options_add_bool (opt, 0, "restart", &fclaw_opt->restart, 0, + "Restart from file [F]"); + + sc_options_add_string(opt, 0, "restart-file", + &fclaw_opt->restart_file, + "","Filename of restart file. " + " If defined, a restart will be performed frome the specified file. [""]"); + + sc_options_add_string(opt, 0, "partition-file", + &fclaw_opt->partition_file, + "","Partition file associated with restart file. " + " This should be specified if a restart file is specified. [""]"); + /* -------------------------------------- Gauges --------------------------------- */ /* Gauge options */ sc_options_add_bool (opt, 0, "output-gauges", &fclaw_opt->output_gauges, 0, @@ -361,16 +376,6 @@ fclaw_register (fclaw_options_t* fclaw_opt, sc_options_t * opt) &fclaw_opt->max_refinement_ratio, 1.0, "Ratio of patches to refine before paritioning and continuing refinement. [1.0]"); - sc_options_add_string(opt, 0, "restart-file", - &fclaw_opt->restart_file, - "","Filename of restart file. " - " If defined, a restart will be performed frome the specified file. [""]"); - - sc_options_add_string(opt, 0, "partition-file", - &fclaw_opt->partition_file, - "","Partition file associated with restart file. " - " This should be specified if a restart file is specified. [""]"); - fclaw_opt->is_registered = 1; fclaw_opt->is_unpacked = 0; diff --git a/src/fclaw_options.h b/src/fclaw_options.h index a5674cc01..4efc45946 100644 --- a/src/fclaw_options.h +++ b/src/fclaw_options.h @@ -221,7 +221,12 @@ struct fclaw_options int verbosity; /**< TODO: Do we have guidelines here? */ int output; - int checkpoint_out; + int checkpoint; + + int restart; + const char * restart_file; /**< filename of restart file */ + const char * partition_file; /**< filename of partition file */ + int tikz_out; /* Boolean */ const char *tikz_figsize_string; @@ -246,9 +251,6 @@ struct fclaw_options const char * regression_check; /**< filename of regression check values */ double max_refinement_ratio; /**< Maximum refinment ratio before partitioning and continuing refinement. */ - - const char * restart_file; /**< filename of restart file */ - const char * partition_file; /**< filename of partition file */ }; struct fclaw_global; diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 43087ca19..4798a78c9 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -508,7 +508,7 @@ void fclaw_output_checkpoint(fclaw_global_t* glob, int iframe) { const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); - if(fclaw_opt->checkpoint_out) + if(fclaw_opt->checkpoint) { fclaw_timer_start (&glob->timers[FCLAW_TIMER_OUTPUT]); From b78336a787645f37e60f717aee51ee40a6e49dc0 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 11:43:42 -0600 Subject: [PATCH 46/76] reword some things --- src/fclaw_restart.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 4798a78c9..5285da843 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -49,11 +49,17 @@ do { \ } \ } while(0) +/** + * @brief Get the ini file for the options as a string + * + * @param glob the global context + * @return char* the ini file as a string, NULL if an error occurs. Needs to be freed by the caller + */ static char* get_used_ini(fclaw_global_t * glob) { char *buffer = NULL; - long length; + long length = 0; if(glob->mpirank == 0) { sc_options_t * options = fclaw_global_get_attribute(glob, "fclaw_options"); @@ -61,12 +67,17 @@ get_used_ini(fclaw_global_t * glob) FCLAW_VERBOSITY_ERROR, options, "fclaw_options.ini.used"); + if(retval != 0) + { + fclaw_global_productionf("fclaw_restart.c: Error saving options\n"); + return NULL; + } // read the entire file into a string FILE *file = fopen("fclaw_options.ini.used", "r"); if (file == NULL) { - printf("Cannot open file\n"); + printf("fclaw_restart.c: Cannot open file\n"); return NULL; } @@ -397,21 +408,21 @@ void restart (fclaw_global_t * glob, Public interface -------------------------------------------------------------------- */ -void -fclaw_restart_output_frame (fclaw_global_t * glob, int iframe) +static void +checkpoint_output_frame (fclaw_global_t * glob, int iframe) { int refine_dim = glob->domain->refine_dim; char filename[BUFSIZ]; char parition_filename[BUFSIZ]; - snprintf(filename, BUFSIZ, "fort_frame_%04d.restart", iframe); + snprintf(filename, BUFSIZ, "fort_frame_%04d.checkpoint", iframe); snprintf(parition_filename, BUFSIZ, "fort_frame_%04d.partition", iframe); int errcode; fclaw_file_context_t *fc = fclaw_file_open_write (filename, "ForestClaw data file", glob->domain, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "restart open file"); + CHECK_ERROR_CODE(refine_dim , errcode, "checkpoint open file"); char* used_ini = fclaw_global_get_attribute(glob, "fclaw_used_ini"); if(used_ini == NULL) @@ -512,7 +523,7 @@ void fclaw_output_checkpoint(fclaw_global_t* glob, int iframe) { fclaw_timer_start (&glob->timers[FCLAW_TIMER_OUTPUT]); - fclaw_restart_output_frame(glob,iframe); + checkpoint_output_frame(glob,iframe); fclaw_timer_stop (&glob->timers[FCLAW_TIMER_OUTPUT]); } From 5a0a8a53820fadad27f85f5bece647c7db4729f1 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 11:52:25 -0600 Subject: [PATCH 47/76] return on failure for writing checkpoint --- src/fclaw_restart.c | 75 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 5285da843..9a9fddc0c 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -37,15 +37,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#define CHECK_ERROR_CODE(refine_dim, errcode, str) \ +#define CHECK_ERROR_CODE(abort, refine_dim, errcode, str) \ do { \ int reslen, retval; \ char err_str[sc_MPI_MAX_ERROR_STRING]; \ if (errcode != FCLAW_FILE_ERR_SUCCESS) \ { \ retval = fclaw_file_error_string (refine_dim, errcode, err_str, &reslen); \ - SC_CHECK_ABORTF (!retval, "%s: error string function not successful", str); \ - SC_ABORTF ("%s: %*.*s", str, reslen, reslen, err_str); \ + if(abort) \ + { \ + SC_CHECK_ABORTF (!retval, "%s: error string function not successful", str); \ + SC_ABORTF ("%s: %*.*s", str, reslen, reslen, err_str); \ + } \ + else \ + { \ + fclaw_global_productionf("%s: %s\n", str, err_str); \ + } \ } \ } while(0) @@ -313,7 +320,7 @@ void restart (fclaw_global_t * glob, glob->mpicomm, partition, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart read_partition"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read_partition"); } fclaw_file_context_t *fc @@ -324,7 +331,7 @@ void restart (fclaw_global_t * glob, partition, &glob->domain, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart open_file"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart open_file"); fclaw_domain_setup(glob, glob->domain); @@ -335,7 +342,7 @@ void restart (fclaw_global_t * glob, sc_array_t array; sc_array_init_size(&array, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &array, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart read used_ini_length"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read used_ini_length"); check_user_string("used_ini_length", user_string); size_t ini_length = *((size_t*) sc_array_index(&array, 0)); @@ -347,14 +354,14 @@ void restart (fclaw_global_t * glob, check_options(glob, used_ini); - CHECK_ERROR_CODE(refine_dim, errcode, "restart read used_ini"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read used_ini"); sc_array_reset(&array); sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart read globsize"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read globsize"); size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); sc_array_reset(&globsize); @@ -363,7 +370,7 @@ void restart (fclaw_global_t * glob, sc_array_init_size(&glob_buffer, glob_packsize, 1); fc = fclaw_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart read glob buffer"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read glob buffer"); fclaw_global_unpack((char *) sc_array_index(&glob_buffer, 0), glob); @@ -390,7 +397,7 @@ void restart (fclaw_global_t * glob, { fclaw_abortf("User string mismatch: %s != %s\n", user_string, names[i]); } - CHECK_ERROR_CODE(refine_dim, errcode, "restart read patches"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read patches"); fclaw_domain_iterate_patches(glob->domain, set_patches, &user); @@ -398,7 +405,7 @@ void restart (fclaw_global_t * glob, } fclaw_file_close(fc, &errcode); - CHECK_ERROR_CODE(refine_dim, errcode, "restart close file"); + CHECK_ERROR_CODE(1, refine_dim, errcode, "restart close file"); fclaw_initialize_domain_flags(glob); fclaw_exchange_setup(glob,timer); @@ -422,12 +429,20 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_context_t *fc = fclaw_file_open_write (filename, "ForestClaw data file", glob->domain, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "checkpoint open file"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "checkpoint open file"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } char* used_ini = fclaw_global_get_attribute(glob, "fclaw_used_ini"); if(used_ini == NULL) { used_ini = get_used_ini(glob); + if(used_ini == NULL) + { + return; + } fclaw_global_attribute_store(glob, "fclaw_used_ini", used_ini, @@ -440,11 +455,19 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) sc_array_init_data(&array, &used_ini_length, sizeof(size_t), 1); fc = fclaw_file_write_block(fc, "used_ini_length", sizeof(size_t), &array, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "write used_ini_length"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "write used_ini_length"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } sc_array_init_data(&array, used_ini, used_ini_length, 1); fc = fclaw_file_write_block(fc, "used_ini", used_ini_length, &array, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "write used_ini"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "write used_ini"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } size_t glob_packsize = fclaw_global_packsize(glob); @@ -453,7 +476,11 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) *((size_t*) sc_array_index(&globsize, 0)) = glob_packsize; fc = fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "write globsize"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "write globsize"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } sc_array_reset(&globsize); @@ -462,7 +489,11 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_global_pack(glob,(char *) sc_array_index(&glob_buffer, 0)); fc = fclaw_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "write glob buffer"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "write glob buffer"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } sc_array_reset(&glob_buffer); @@ -486,7 +517,11 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fc = fclaw_file_write_array(fc, names[i], sizes[i], patches, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "write patches"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "write patches"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } for(int i = 0; i < glob->domain->local_num_patches; i++) { @@ -501,7 +536,11 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_write_partition (parition_filename, "Test partition write", glob->domain, &errcode); - CHECK_ERROR_CODE(refine_dim , errcode, "close file"); + CHECK_ERROR_CODE(0, refine_dim , errcode, "close file"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } //fclaw_restart_test_from_file(glob, filename, parition_filename); } From 99055ed6f6f31ac670a3e74f1588583d9288b502 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 12:55:18 -0600 Subject: [PATCH 48/76] clarify macro names --- src/fclaw_restart.c | 72 ++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 9a9fddc0c..006d7000c 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -37,25 +37,40 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#define CHECK_ERROR_CODE(abort, refine_dim, errcode, str) \ +/** + * @brief Check the error code and print an error message if not successful + */ +#define CHECK_ERROR_CODE(refine_dim, errcode, str) \ do { \ int reslen, retval; \ char err_str[sc_MPI_MAX_ERROR_STRING]; \ if (errcode != FCLAW_FILE_ERR_SUCCESS) \ { \ retval = fclaw_file_error_string (refine_dim, errcode, err_str, &reslen); \ - if(abort) \ - { \ - SC_CHECK_ABORTF (!retval, "%s: error string function not successful", str); \ - SC_ABORTF ("%s: %*.*s", str, reslen, reslen, err_str); \ - } \ - else \ + if(retval != 0) \ { \ - fclaw_global_productionf("%s: %s\n", str, err_str); \ + fclaw_global_errorf ("%s: error string function not successful", str); \ } \ + fclaw_global_errorf("%s: %s\n", str, err_str); \ } \ } while(0) +/** + * @brief Check the error code and abort with message if not successful + */ +#define CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, str) \ +do { \ + int reslen, retval; \ + char err_str[sc_MPI_MAX_ERROR_STRING]; \ + if (errcode != FCLAW_FILE_ERR_SUCCESS) \ + { \ + retval = fclaw_file_error_string (refine_dim, errcode, err_str, &reslen); \ + SC_CHECK_ABORTF (!retval, "%s: error string function not successful", str); \ + SC_ABORTF ("%s: %*.*s", str, reslen, reslen, err_str); \ + } \ +} while(0) + + /** * @brief Get the ini file for the options as a string * @@ -203,6 +218,11 @@ check_options(fclaw_global_t * glob, const char* checkpoint_ini) FCLAW_VERBOSITY_ERROR, options, "fclaw_options.ini.used"); + + if(retval != 0) + { + fclaw_abortf("fclaw_restart.c: Error saving current options\n"); + } //save the restart ini file to fclaw_options.ini.checkpoint FILE *file = fopen("fclaw_options.ini.checkpoint", "w"); @@ -320,7 +340,7 @@ void restart (fclaw_global_t * glob, glob->mpicomm, partition, &errcode); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read_partition"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read_partition"); } fclaw_file_context_t *fc @@ -331,7 +351,7 @@ void restart (fclaw_global_t * glob, partition, &glob->domain, &errcode); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart open_file"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart open_file"); fclaw_domain_setup(glob, glob->domain); @@ -342,7 +362,7 @@ void restart (fclaw_global_t * glob, sc_array_t array; sc_array_init_size(&array, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &array, &errcode); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read used_ini_length"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini_length"); check_user_string("used_ini_length", user_string); size_t ini_length = *((size_t*) sc_array_index(&array, 0)); @@ -354,14 +374,14 @@ void restart (fclaw_global_t * glob, check_options(glob, used_ini); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read used_ini"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini"); sc_array_reset(&array); sc_array_t globsize; sc_array_init_size(&globsize, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read globsize"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read globsize"); size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); sc_array_reset(&globsize); @@ -370,7 +390,7 @@ void restart (fclaw_global_t * glob, sc_array_init_size(&glob_buffer, glob_packsize, 1); fc = fclaw_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read glob buffer"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read glob buffer"); fclaw_global_unpack((char *) sc_array_index(&glob_buffer, 0), glob); @@ -381,7 +401,7 @@ void restart (fclaw_global_t * glob, fclaw_patch_restart_pointer_sizes(glob, sizes); const char* names[num_pointers]; fclaw_patch_restart_names(glob, names); - for(int i = 0; i < 1; i++) + for(int i = 0; i < num_pointers; i++) { sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); pack_iter_t user; @@ -397,7 +417,7 @@ void restart (fclaw_global_t * glob, { fclaw_abortf("User string mismatch: %s != %s\n", user_string, names[i]); } - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart read patches"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read patches"); fclaw_domain_iterate_patches(glob->domain, set_patches, &user); @@ -405,7 +425,7 @@ void restart (fclaw_global_t * glob, } fclaw_file_close(fc, &errcode); - CHECK_ERROR_CODE(1, refine_dim, errcode, "restart close file"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart close file"); fclaw_initialize_domain_flags(glob); fclaw_exchange_setup(glob,timer); @@ -429,7 +449,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_context_t *fc = fclaw_file_open_write (filename, "ForestClaw data file", glob->domain, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "checkpoint open file"); + CHECK_ERROR_CODE(refine_dim , errcode, "checkpoint open file"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; @@ -455,7 +475,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) sc_array_init_data(&array, &used_ini_length, sizeof(size_t), 1); fc = fclaw_file_write_block(fc, "used_ini_length", sizeof(size_t), &array, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "write used_ini_length"); + CHECK_ERROR_CODE(refine_dim , errcode, "write used_ini_length"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; @@ -463,7 +483,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) sc_array_init_data(&array, used_ini, used_ini_length, 1); fc = fclaw_file_write_block(fc, "used_ini", used_ini_length, &array, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "write used_ini"); + CHECK_ERROR_CODE(refine_dim , errcode, "write used_ini"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; @@ -476,7 +496,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) *((size_t*) sc_array_index(&globsize, 0)) = glob_packsize; fc = fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "write globsize"); + CHECK_ERROR_CODE(refine_dim , errcode, "write globsize"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; @@ -489,7 +509,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_global_pack(glob,(char *) sc_array_index(&glob_buffer, 0)); fc = fclaw_file_write_block(fc, "glob", glob_packsize, &glob_buffer, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "write glob buffer"); + CHECK_ERROR_CODE(refine_dim , errcode, "write glob buffer"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; @@ -503,7 +523,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_patch_restart_pointer_sizes(glob, sizes); const char* names[num_pointers]; fclaw_patch_restart_names(glob, names); - for(int i = 0; i < 1; i++) + for(int i = 0; i < num_pointers; i++) { sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); pack_iter_t user; @@ -517,7 +537,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fc = fclaw_file_write_array(fc, names[i], sizes[i], patches, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "write patches"); + CHECK_ERROR_CODE(refine_dim , errcode, "write patches"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; @@ -536,13 +556,11 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_write_partition (parition_filename, "Test partition write", glob->domain, &errcode); - CHECK_ERROR_CODE(0, refine_dim , errcode, "close file"); + CHECK_ERROR_CODE(refine_dim , errcode, "close file"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; } - - //fclaw_restart_test_from_file(glob, filename, parition_filename); } From b36b1d9621415419d081e0a3c8e30d4357958831 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 13:15:16 -0600 Subject: [PATCH 49/76] documentation/cleanup --- src/fclaw_restart.c | 82 ++++++++++++++++++++++++++++++--------------- src/fclaw_restart.h | 4 ++- 2 files changed, 58 insertions(+), 28 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 006d7000c..a53bb93f8 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -132,6 +132,14 @@ get_used_ini(fclaw_global_t * glob) } +/** + * @brief Check if option should be skipped for comparison + * + * @param fclaw_opt_sections the sections containing the core options + * @param section the section name + * @param key the key name + * @return int true if the option should be skipped, false otherwise + */ static int skip_option(sc_keyvalue_t *fclaw_opt_sections, const char* section, const char* key) { @@ -152,6 +160,14 @@ skip_option(sc_keyvalue_t *fclaw_opt_sections, const char* section, const char* return skip; } +/** + * @brief compare two ini dictionaries + * + * @param fclaw_opt_secitons the sections containing the core options + * @param expected the expected dictionary + * @param actual the actual dictionary + * @return int the number of differences found + */ static int compare_dictionaries(sc_keyvalue_t *fclaw_opt_secitons, dictionary *expected, @@ -204,6 +220,12 @@ compare_dictionaries(sc_keyvalue_t *fclaw_opt_secitons, return num_differences; } +/** + * @brief Compare provided options with the options stored in the checkpoint + * + * @param glob the global context + * @param checkpoint_ini the ini file from the checkpoint + */ static void check_options(fclaw_global_t * glob, const char* checkpoint_ini) { @@ -264,6 +286,15 @@ free_used_ini(void* data) FCLAW_FREE(buffer); } +static +void check_user_string(const char* expected, const char* actual) +{ + if(strncmp(expected, actual, strlen(expected)) != 0) + { + fclaw_abortf("User string mismatch: %s != %s\n", expected, actual); + } +} + typedef struct pack_iter { fclaw_global_t * glob; @@ -271,23 +302,12 @@ typedef struct pack_iter size_t size; sc_array_t* patches; int pointerno; - int reading; }pack_iter_t; -static void -get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) -{ - pack_iter_t *user_data = (pack_iter_t*)user; - sc_array_t *patches = user_data->patches; - sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); - - void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); - - sc_array_init_data(current_arr, data, user_data->size, 1); - - user_data->curr_index++; -} +/** + * @brief Set patch data from the checkpoint, user data is a pack_iter_t + */ static void set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) { @@ -311,14 +331,6 @@ set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat user_data->curr_index++; } -static -void check_user_string(const char* expected, const char* actual) -{ - if(strncmp(expected, actual, strlen(expected)) != 0) - { - fclaw_abortf("User string mismatch: %s != %s\n", expected, actual); - } -} static void restart (fclaw_global_t * glob, const char* restart_filename, @@ -410,7 +422,6 @@ void restart (fclaw_global_t * glob, user.patches = patches; user.size = sizes[i]; user.pointerno = i; - user.reading = 1; fc = fclaw_file_read_array(fc, user_string, sizes[i], patches, &errcode); if(strncmp(user_string, names[i], strlen(names[i])) != 0) @@ -431,9 +442,24 @@ void restart (fclaw_global_t * glob, fclaw_exchange_setup(glob,timer); fclaw_regrid_set_neighbor_types(glob); } -/* ----------------------------------------------------------------------- - Public interface - -------------------------------------------------------------------- */ + +/** + * @brief Get patch data for the checkpoint, user data is a pack_iter_t + */ +static void +get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int patchno, void *user) +{ + pack_iter_t *user_data = (pack_iter_t*)user; + sc_array_t *patches = user_data->patches; + sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); + + void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); + + sc_array_init_data(current_arr, data, user_data->size, 1); + + user_data->curr_index++; +} + static void checkpoint_output_frame (fclaw_global_t * glob, int iframe) @@ -532,7 +558,6 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) user.patches = patches; user.size = sizes[i]; user.pointerno = i; - user.reading = 0; fclaw_domain_iterate_patches(glob->domain, get_patches, &user); @@ -563,6 +588,9 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) } } +/* ----------------------------------------------------------------------- + Public interface + -------------------------------------------------------------------- */ void fclaw_restart_from_file (fclaw_global_t * glob, diff --git a/src/fclaw_restart.h b/src/fclaw_restart.h index 4d45f3b48..df5474336 100644 --- a/src/fclaw_restart.h +++ b/src/fclaw_restart.h @@ -41,7 +41,9 @@ struct fclaw_global; /* This is a hack !! */ * @brief Restarts the forestclaw simulation from a restart file. * * This function is responsible for restarting the simulation from a previously saved state. - * This is meant to be called fclaw_initalize() + * This is meant to be called from fclaw_initalize() + * + * This will print an error message and exit for any error. * * @param glob The global context * @param restart_filename The filename of the restart file. From b1d42d6ff9ce6cd7c11b4928318a7c9222e7c688 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 13:33:18 -0600 Subject: [PATCH 50/76] check user strings when restarting --- src/fclaw_restart.c | 66 +++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index a53bb93f8..b276369e7 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -291,7 +291,15 @@ void check_user_string(const char* expected, const char* actual) { if(strncmp(expected, actual, strlen(expected)) != 0) { - fclaw_abortf("User string mismatch: %s != %s\n", expected, actual); + //also check that rest of the string is just spaces + for(int i = strlen(expected); i < FCLAW_FILE_USER_STRING_BYTES; i++) + { + if(actual[i] != ' ') + { + fclaw_abortf("fclaw_restart.c: User string mismatch: %s != %s\n", expected, actual); + } + } + fclaw_abortf("fclaw_restart.c: User string mismatch: %s != %s\n", expected, actual); } } @@ -352,6 +360,7 @@ void restart (fclaw_global_t * glob, glob->mpicomm, partition, &errcode); + check_user_string("Partition", user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read_partition"); } @@ -363,6 +372,7 @@ void restart (fclaw_global_t * glob, partition, &glob->domain, &errcode); + check_user_string("ForestClaw checkpoint file", user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart open_file"); fclaw_domain_setup(glob, glob->domain); @@ -371,48 +381,66 @@ void restart (fclaw_global_t * glob, { sc_array_destroy(partition); } + sc_array_t array; sc_array_init_size(&array, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &array, &errcode); - CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini_length"); + + //read the length of the used_ini string + check_user_string("used_ini_length", user_string); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini_length"); size_t ini_length = *((size_t*) sc_array_index(&array, 0)); sc_array_reset(&array); sc_array_init_size(&array, ini_length, 1); fc = fclaw_file_read_block(fc, user_string, ini_length, &array, &errcode); + + //read the used_ini string + + check_user_string(user_string, "used_ini"); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini"); + const char* used_ini = (const char*) sc_array_index(&array, 0); check_options(glob, used_ini); - - CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini"); sc_array_reset(&array); - sc_array_t globsize; - sc_array_init_size(&globsize, sizeof(size_t), 1); + //read the length of the glob buffer - fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &globsize, &errcode); + sc_array_init_size(&array, sizeof(size_t), 1); + + fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &array, &errcode); + + check_user_string("glob_size", user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read globsize"); - size_t glob_packsize = *((size_t*) sc_array_index(&globsize, 0)); - sc_array_reset(&globsize); + size_t glob_packsize = *((size_t*) sc_array_index(&array, 0)); - sc_array_t glob_buffer; - sc_array_init_size(&glob_buffer, glob_packsize, 1); + sc_array_reset(&array); + + //read the glob buffer + + sc_array_init_size(&array, glob_packsize, 1); - fc = fclaw_file_read_block(fc, user_string, glob_packsize, &glob_buffer, &errcode); + fc = fclaw_file_read_block(fc, user_string, glob_packsize, &array, &errcode); + + check_user_string("glob", user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read glob buffer"); - fclaw_global_unpack((char *) sc_array_index(&glob_buffer, 0), glob); + fclaw_global_unpack((char *) sc_array_index(&array, 0), glob); - sc_array_reset(&glob_buffer); + sc_array_reset(&array); + + //read patch data int num_pointers = fclaw_patch_restart_num_pointers(glob); size_t sizes[num_pointers]; fclaw_patch_restart_pointer_sizes(glob, sizes); const char* names[num_pointers]; fclaw_patch_restart_names(glob, names); + for(int i = 0; i < num_pointers; i++) { sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); @@ -424,10 +452,8 @@ void restart (fclaw_global_t * glob, user.pointerno = i; fc = fclaw_file_read_array(fc, user_string, sizes[i], patches, &errcode); - if(strncmp(user_string, names[i], strlen(names[i])) != 0) - { - fclaw_abortf("User string mismatch: %s != %s\n", user_string, names[i]); - } + + check_user_string(names[i], user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read patches"); fclaw_domain_iterate_patches(glob->domain, set_patches, &user); @@ -473,7 +499,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) int errcode; fclaw_file_context_t *fc - = fclaw_file_open_write (filename, "ForestClaw data file", + = fclaw_file_open_write (filename, "ForestClaw checkpoint file", glob->domain, &errcode); CHECK_ERROR_CODE(refine_dim , errcode, "checkpoint open file"); if(errcode != FCLAW_FILE_ERR_SUCCESS) @@ -579,7 +605,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) fclaw_file_close(fc, &errcode); fclaw_file_write_partition (parition_filename, - "Test partition write", + "Paritition", glob->domain, &errcode); CHECK_ERROR_CODE(refine_dim , errcode, "close file"); if(errcode != FCLAW_FILE_ERR_SUCCESS) From 0afd78eec1c8f6ef45c42ade7dd6187a49cba794 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 14:17:55 -0600 Subject: [PATCH 51/76] include initializer_list header in test.hpp --- test/test.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test.hpp b/test/test.hpp index 20f6ad870..c54e36bb9 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -2,6 +2,7 @@ #define FCLAW_TEST_HPP #include #include +#include bool test_output_vtk(); From cbcee147098b266f55ac9dedd70a06bebaa61c17 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Tue, 21 May 2024 14:21:10 -0600 Subject: [PATCH 52/76] fix test for fclaw_global_new --- src/fclaw_global.h.TEST.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fclaw_global.h.TEST.cpp b/src/fclaw_global.h.TEST.cpp index b0864c763..9c2a6cf89 100644 --- a/src/fclaw_global.h.TEST.cpp +++ b/src/fclaw_global.h.TEST.cpp @@ -51,8 +51,8 @@ TEST_CASE("fclaw_global_new default options") CHECK_EQ(glob->count_grids_remote_boundary, 0); CHECK_EQ(glob->count_grids_local_boundary, 0); - CHECK_EQ(glob->mpisize, 0); - CHECK_EQ(glob->mpirank, -1); + CHECK_EQ(glob->mpisize, 1); + CHECK_EQ(glob->mpirank, 0); CHECK_EQ(fclaw_pointer_map_size(glob->vtables), 0); CHECK_EQ(fclaw_pointer_map_size(glob->options), 0); From 746bdfc43b63b062a5ef83dd38801df55a4d58e0 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 22 May 2024 13:19:11 -0600 Subject: [PATCH 53/76] seperate out restart funcitonality from fclaw_initialize into fclaw_restart --- src/fclaw_forestclaw.h | 6 ++++ src/fclaw_initialize.c | 62 ++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/fclaw_forestclaw.h b/src/fclaw_forestclaw.h index 495abacf4..fb9ba5426 100644 --- a/src/fclaw_forestclaw.h +++ b/src/fclaw_forestclaw.h @@ -47,6 +47,12 @@ void fclaw_initialize_domain_flags(struct fclaw_global *glob); void fclaw_run_vtables_initialize(struct fclaw_global *glob); void fclaw_initialize (struct fclaw_global *glob); +/** + * @brief Perform a restart. This will use the settings in fclaw_options + * + * @param glob the global context + */ +void fclaw_restart (struct fclaw_global *glob); void fclaw_run (struct fclaw_global *glob); void fclaw_finalize(struct fclaw_global *glob); diff --git a/src/fclaw_initialize.c b/src/fclaw_initialize.c index 8f0a0fd89..fa0c8a96c 100644 --- a/src/fclaw_initialize.c +++ b/src/fclaw_initialize.c @@ -221,15 +221,11 @@ void fclaw_initialize_domain_flags(fclaw_global_t *glob) fclaw_domain_set_partitioning(glob->domain, fclaw_opt->partition_for_coarsening); } -/* ----------------------------------------------------------------- - Public interface - ----------------------------------------------------------------- */ -void fclaw_initialize(fclaw_global_t *glob) +static void +pre_setup(fclaw_global_t* glob) { fclaw_domain_t** domain = &glob->domain; - const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); - /* This mapping context is needed by fortran mapping functions */ fclaw_map_context_t *cont = glob->cont; FCLAW_MAP_SET_CONTEXT(&cont); @@ -256,26 +252,11 @@ void fclaw_initialize(fclaw_global_t *glob) /* User defined problem setup */ fclaw_problem_setup(glob); +} - if(strcmp(fclaw_opt->restart_file,"") == 0) - { - // no restart file - build_initial_domain(glob); - } - else - { - const char* partition_filename = NULL; - if(strcmp(fclaw_opt->partition_file,"") != 0) - { - partition_filename = fclaw_opt->partition_file; - } - - fclaw_restart_from_file(glob, fclaw_opt->restart_file, - partition_filename); - } - - - +static void +post_setup(fclaw_global_t* glob) +{ fclaw_diagnostics_initialize(glob); fclaw_locate_gauges(glob); @@ -283,8 +264,37 @@ void fclaw_initialize(fclaw_global_t *glob) /* Print global minimum and maximum levels */ fclaw_global_infof("Global minlevel %d maxlevel %d\n", - (*domain)->global_minlevel, (*domain)->global_maxlevel); + glob->domain->global_minlevel, glob->domain->global_maxlevel); /* Stop timer */ fclaw_timer_stop (&glob->timers[FCLAW_TIMER_INIT]); } +/* ----------------------------------------------------------------- + Public interface + ----------------------------------------------------------------- */ +void fclaw_initialize(fclaw_global_t *glob) +{ + pre_setup(glob); + + build_initial_domain(glob); + + post_setup(glob); +} + +void fclaw_restart(fclaw_global_t *glob) +{ + pre_setup(glob); + + const fclaw_options_t *fclaw_opt = fclaw_get_options(glob); + + const char* partition_filename = NULL; + if(strcmp(fclaw_opt->partition_file,"") != 0) + { + partition_filename = fclaw_opt->partition_file; + } + + fclaw_restart_from_file(glob, fclaw_opt->restart_file, + partition_filename); + + post_setup(glob); +} From f4f686b173c1d6846082f6bdeaa9799acfc22736 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 29 May 2024 14:25:11 -0600 Subject: [PATCH 54/76] handle error codes properly for fclaw_file --- src/fclaw2d_to_3d.h | 1 + src/fclaw2d_wrap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/fclaw2d_wrap.h | 2 ++ src/fclaw3d_wrap.h | 3 +++ src/fclaw_file.c | 32 +++++++++++++++++++++--- src/fclaw_file.h | 2 -- src/fclaw_restart.c | 2 +- 7 files changed, 95 insertions(+), 7 deletions(-) diff --git a/src/fclaw2d_to_3d.h b/src/fclaw2d_to_3d.h index 4f747679c..3a151c29e 100644 --- a/src/fclaw2d_to_3d.h +++ b/src/fclaw2d_to_3d.h @@ -211,5 +211,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define fclaw2d_match_wrap_cb fclaw3d_match_wrap_cb #define fclaw2d_intersect_wrap_cb fclaw3d_intersect_wrap_cb #define fclaw2d_interpolate_point_wrap_cb fclaw3d_interpolate_point_wrap_cb +#define fclaw2d_file_error_wrap fclaw3d_file_error_wrap #endif /* !FCLAW2D_TO_3D_H */ diff --git a/src/fclaw2d_wrap.c b/src/fclaw2d_wrap.c index 7836a287b..f01d3f23a 100644 --- a/src/fclaw2d_wrap.c +++ b/src/fclaw2d_wrap.c @@ -24,16 +24,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #ifndef P4_TO_P8 #include #include +#include #else #include #include +#include #endif @@ -322,3 +325,60 @@ fclaw2d_interpolate_point_wrap_cb (fclaw2d_domain_t * domain_2d, return retval; } + +int fclaw2d_file_error_wrap(int errcode) +{ + switch(errcode) + { + case FCLAW2D_FILE_ERR_SUCCESS: + return FCLAW_FILE_ERR_SUCCESS; + case FCLAW2D_FILE_ERR_FILE: + return FCLAW_FILE_ERR_FILE; + case FCLAW2D_FILE_ERR_NOT_SAME: + return FCLAW_FILE_ERR_NOT_SAME; + case FCLAW2D_FILE_ERR_AMODE: + return FCLAW_FILE_ERR_AMODE; + case FCLAW2D_FILE_ERR_NO_SUCH_FILE: + return FCLAW_FILE_ERR_NO_SUCH_FILE; + case FCLAW2D_FILE_ERR_FILE_EXIST: + return FCLAW_FILE_ERR_FILE_EXIST; + case FCLAW2D_FILE_ERR_BAD_FILE: + return FCLAW_FILE_ERR_BAD_FILE; + case FCLAW2D_FILE_ERR_ACCESS: + return FCLAW_FILE_ERR_ACCESS; + case FCLAW2D_FILE_ERR_NO_SPACE: + return FCLAW_FILE_ERR_NO_SPACE; + case FCLAW2D_FILE_ERR_QUOTA: + return FCLAW_FILE_ERR_QUOTA; + case FCLAW2D_FILE_ERR_READ_ONLY: + return FCLAW_FILE_ERR_READ_ONLY; + case FCLAW2D_FILE_ERR_IN_USE: + return FCLAW_FILE_ERR_IN_USE; + case FCLAW2D_FILE_ERR_IO: + return FCLAW_FILE_ERR_IO; + case FCLAW2D_FILE_ERR_FORMAT: + return FCLAW_FILE_ERR_FORMAT; + case FCLAW2D_FILE_ERR_SECTION_TYPE: + return FCLAW_FILE_ERR_SECTION_TYPE; + case FCLAW2D_FILE_ERR_CONN: + return FCLAW_FILE_ERR_CONN; + case FCLAW2D_FILE_ERR_P4EST: + return FCLAW_FILE_ERR_P4EST; + case FCLAW2D_FILE_ERR_IN_DATA: + return FCLAW_FILE_ERR_IN_DATA; + case FCLAW2D_FILE_ERR_COUNT: + return FCLAW_FILE_ERR_COUNT; + case FCLAW2D_FILE_ERR_DIM: + return FCLAW_FILE_ERR_DIM; + case FCLAW2D_FILE_ERR_UNKNOWN: + return FCLAW_FILE_ERR_UNKNOWN; + case FCLAW2D_FILE_ERR_PART: + return FCLAW_FILE_ERR_PART; + case FCLAW2D_FILE_ERR_NOT_IMPLEMENTED: + return FCLAW_FILE_ERR_NOT_IMPLEMENTED; + case FCLAW2D_FILE_ERR_LASTCODE: + return FCLAW_FILE_ERR_LASTCODE; + default: + SC_ABORT_NOT_REACHED(); + } +} \ No newline at end of file diff --git a/src/fclaw2d_wrap.h b/src/fclaw2d_wrap.h index 913188614..a2e4aa0b7 100644 --- a/src/fclaw2d_wrap.h +++ b/src/fclaw2d_wrap.h @@ -113,6 +113,8 @@ fclaw2d_interpolate_point_wrap_cb (fclaw2d_domain_t * domain, int blockno, int patchno, void *point, void *user); +int fclaw2d_file_error_wrap(int errcode); + #ifdef __cplusplus #if 0 { diff --git a/src/fclaw3d_wrap.h b/src/fclaw3d_wrap.h index fb78b81e9..963c02694 100644 --- a/src/fclaw3d_wrap.h +++ b/src/fclaw3d_wrap.h @@ -115,6 +115,9 @@ fclaw3d_interpolate_point_wrap_cb (fclaw3d_domain_t * domain, int blockno, int patchno, void *point, void *user); +int +fclaw3d_file_error_wrap(int errcode); + #ifdef __cplusplus #if 0 { diff --git a/src/fclaw_file.c b/src/fclaw_file.c index 414d2f3a7..f2b0f0313 100644 --- a/src/fclaw_file.c +++ b/src/fclaw_file.c @@ -24,6 +24,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include +#include #include #include @@ -84,12 +86,14 @@ fclaw_file_context_t *fclaw_file_open_write (const char *filename, { fclaw2d_file_context_t *d2 = fclaw2d_file_open_write (filename, user_string, domain->d2, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); return wrap_file_2d(d2); } else if(domain->refine_dim == 3) { fclaw3d_file_context_t *d3 = fclaw3d_file_open_write (filename, user_string, domain->d3, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); return wrap_file_3d(d3); } else @@ -104,11 +108,15 @@ int fclaw_file_write_partition (const char *filename, { if(domain->refine_dim == 2) { - return fclaw2d_file_write_partition (filename, user_string, domain->d2, errcode); + int retval = fclaw2d_file_write_partition (filename, user_string, domain->d2, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); + return retval; } else if(domain->refine_dim == 3) { - return fclaw3d_file_write_partition (filename, user_string, domain->d3, errcode); + int retval = fclaw3d_file_write_partition (filename, user_string, domain->d3, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); + return retval; } else { @@ -126,11 +134,13 @@ fclaw_file_context_t *fclaw_file_write_block (fclaw_file_context_t * { fc->d2 = fclaw2d_file_write_block (fc->d2, user_string, block_size, block_data, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); } else if(fc->refine_dim == 3) { fc->d3 = fclaw3d_file_write_block (fc->d3, user_string, block_size, block_data, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); } else { @@ -149,11 +159,13 @@ fclaw_file_context_t *fclaw_file_write_array (fclaw_file_context_t * { fc->d2 = fclaw2d_file_write_array (fc->d2, user_string, patch_size, patch_data, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); } else if(fc->refine_dim == 3) { fc->d3 = fclaw3d_file_write_array (fc->d3, user_string, patch_size, patch_data, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); } else { @@ -169,11 +181,15 @@ int fclaw_file_read_partition (int refine_dim, { if(refine_dim == 2) { - return fclaw2d_file_read_partition (filename, user_string, mpicomm, partition, errcode); + int retval = fclaw2d_file_read_partition (filename, user_string, mpicomm, partition, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); + return retval; } else if(refine_dim == 3) { - return fclaw3d_file_read_partition (filename, user_string, mpicomm, partition, errcode); + int retval = fclaw3d_file_read_partition (filename, user_string, mpicomm, partition, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); + return retval; } else { @@ -196,6 +212,7 @@ fclaw_file_context_t *fclaw_file_open_read (int refine_dim, mpicomm, partition, &new_domain, errcode); *domain = fclaw_domain_wrap_2d(new_domain); + *errcode = fclaw2d_file_error_wrap(*errcode); return wrap_file_2d(d2); } else if(refine_dim == 3) @@ -204,6 +221,7 @@ fclaw_file_context_t *fclaw_file_open_read (int refine_dim, fclaw3d_file_context_t *d3 = fclaw3d_file_open_read (filename, user_string, mpicomm, partition, &new_domain, errcode); *domain = fclaw_domain_wrap_3d(new_domain); + *errcode = fclaw3d_file_error_wrap(*errcode); return wrap_file_3d(d3); } else @@ -222,11 +240,13 @@ fclaw_file_context_t *fclaw_file_read_block (fclaw_file_context_t * { fc->d2 = fclaw2d_file_read_block (fc->d2, user_string, block_size, block_data, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); } else if(fc->refine_dim == 3) { fc->d3 = fclaw3d_file_read_block (fc->d3, user_string, block_size, block_data, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); } else { @@ -245,11 +265,13 @@ fclaw_file_context_t *fclaw_file_read_array (fclaw_file_context_t * { fc->d2 = fclaw2d_file_read_array (fc->d2, user_string, patch_size, patch_data, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); } else if(fc->refine_dim == 3) { fc->d3 = fclaw3d_file_read_array (fc->d3, user_string, patch_size, patch_data, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); } else { @@ -264,10 +286,12 @@ int fclaw_file_close (fclaw_file_context_t * fc, int *errcode) if(fc->refine_dim == 2) { retval = fclaw2d_file_close (fc->d2, errcode); + *errcode = fclaw2d_file_error_wrap(*errcode); } else if(fc->refine_dim == 3) { retval = fclaw3d_file_close (fc->d3, errcode); + *errcode = fclaw3d_file_error_wrap(*errcode); } else { diff --git a/src/fclaw_file.h b/src/fclaw_file.h index 5bbdf4390..1f80fd52d 100644 --- a/src/fclaw_file.h +++ b/src/fclaw_file.h @@ -34,8 +34,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define FCLAW_FILE_H #include -#include -#include #ifdef __cplusplus extern "C" diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index b276369e7..a458bdf7f 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -350,7 +350,7 @@ void restart (fclaw_global_t * glob, int errcode; sc_array_t* partition = NULL; - char user_string[FCLAW3D_FILE_USER_STRING_BYTES]; + char user_string[FCLAW_FILE_USER_STRING_BYTES]; if(partition_filename != NULL) { partition = sc_array_new(sizeof(p4est_gloidx_t)); From 13bbd2db76b361a78ba71a09c3bddd3f741000f8 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Wed, 29 May 2024 17:38:54 -0600 Subject: [PATCH 55/76] fix typo in makefile --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index beb26fd56..c11ca1e58 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -112,7 +112,7 @@ libforestclaw_compiled_sources = \ src/fclaw_face_neighbors.c \ src/fclaw_farraybox.cpp \ src/fclaw_file.c \ - src/fclaws_context.c \ + src/fclaw_context.c \ src/fclaw2d_convenience.c \ src/fclaw2d_output_tikz.c \ src/fclaw2d_file.c \ From 48c2f991d4fd4d3a11600ba0bf62c084616e5aec Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 10:36:29 -0600 Subject: [PATCH 56/76] add version to checkpoint, add some comments to checkpoint output --- src/fclaw_restart.c | 81 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index a458bdf7f..c362887f6 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -383,10 +383,43 @@ void restart (fclaw_global_t * glob, } sc_array_t array; + + //read the version major + + sc_array_init_size(&array, sizeof(int), 1); + fc = fclaw_file_read_block(fc, user_string, sizeof(int), &array, &errcode); + + check_user_string("checkpoint_version_major", user_string); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read version_major"); + + int version_major = *((int*) sc_array_index(&array, 0)); + + sc_array_reset(&array); + + + //read the version minor + + sc_array_init_size(&array, sizeof(int), 1); + fc = fclaw_file_read_block(fc, user_string, sizeof(int), &array, &errcode); + + check_user_string("checkpoint_version_minor", user_string); + CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read version_minor"); + + int version_minor = *((int*) sc_array_index(&array, 0)); + + sc_array_reset(&array); + + //version check + if(version_major != 1 || version_minor != 0) + { + fclaw_abortf("fclaw_restart.c: Incompatible checkpoint version: %d.%d\n", version_major, version_minor); + } + + //read the length of the used_ini string + sc_array_init_size(&array, sizeof(size_t), 1); fc = fclaw_file_read_block(fc, user_string, sizeof(size_t), &array, &errcode); - //read the length of the used_ini string check_user_string("used_ini_length", user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini_length"); @@ -394,10 +427,11 @@ void restart (fclaw_global_t * glob, size_t ini_length = *((size_t*) sc_array_index(&array, 0)); sc_array_reset(&array); + //read the used_ini string + sc_array_init_size(&array, ini_length, 1); fc = fclaw_file_read_block(fc, user_string, ini_length, &array, &errcode); - //read the used_ini string check_user_string(user_string, "used_ini"); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini"); @@ -507,6 +541,36 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) return; } + sc_array_t array; + + //dont know if we are going to bother with supporting older versions + //of checkpoint files, but we will write the version number anyway + + //write version major + + int version_major = 1; + sc_array_init_data(&array, &version_major, sizeof(int), 1); + + fc = fclaw_file_write_block(fc, "checkpoint_version_major", sizeof(int), &array, &errcode); + CHECK_ERROR_CODE(refine_dim, errcode, "checkpoint write version_major"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } + + //write version minor + + int version_minor = 0; + sc_array_init_data(&array, &version_minor, sizeof(int), 1); + fc = fclaw_file_write_block(fc, "checkpoint_version_minor", sizeof(int), &array, &errcode); + CHECK_ERROR_CODE(refine_dim , errcode, "checkpoint write version_minor"); + if(errcode != FCLAW_FILE_ERR_SUCCESS) + { + return; + } + + //write the used_ini length and string + char* used_ini = fclaw_global_get_attribute(glob, "fclaw_used_ini"); if(used_ini == NULL) { @@ -523,7 +587,6 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) } size_t used_ini_length = strlen(used_ini); - sc_array_t array; sc_array_init_data(&array, &used_ini_length, sizeof(size_t), 1); fc = fclaw_file_write_block(fc, "used_ini_length", sizeof(size_t), &array, &errcode); @@ -541,20 +604,19 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) return; } - size_t glob_packsize = fclaw_global_packsize(glob); + //write size of glob buffer - sc_array_t globsize; - sc_array_init_size(&globsize, sizeof(size_t), 1); - *((size_t*) sc_array_index(&globsize, 0)) = glob_packsize; + size_t glob_packsize = fclaw_global_packsize(glob); + sc_array_init_data(&array, &glob_packsize, sizeof(size_t), 1); - fc = fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &globsize, &errcode); + fc = fclaw_file_write_block(fc, "glob_size", sizeof(size_t), &array, &errcode); CHECK_ERROR_CODE(refine_dim , errcode, "write globsize"); if(errcode != FCLAW_FILE_ERR_SUCCESS) { return; } - sc_array_reset(&globsize); + //write glob buffer sc_array_t glob_buffer; sc_array_init_size(&glob_buffer, glob_packsize, 1); @@ -569,6 +631,7 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) sc_array_reset(&glob_buffer); + //write patch data int num_pointers = fclaw_patch_restart_num_pointers(glob); size_t sizes[num_pointers]; From 6bec5921180a0d5ae7f3a55341c2034c565f4210 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 12:04:37 -0600 Subject: [PATCH 57/76] add restart to 2d/3d swirl --- applications/clawpack/advection/2d/swirl/swirl.cpp | 12 +++++++++++- applications/clawpack/advection/3d/swirl/swirl.cpp | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/applications/clawpack/advection/2d/swirl/swirl.cpp b/applications/clawpack/advection/2d/swirl/swirl.cpp index 1370c532e..ebc4c15f3 100644 --- a/applications/clawpack/advection/2d/swirl/swirl.cpp +++ b/applications/clawpack/advection/2d/swirl/swirl.cpp @@ -74,7 +74,17 @@ void run_program(fclaw_global_t* glob) /* --------------------------------------------------------------- Run --------------------------------------------------------------- */ - fclaw_initialize(glob); + + fclaw_options_t *fclaw_opt = fclaw_get_options(glob); + if(fclaw_opt->restart) + { + fclaw_restart(glob); + } + else + { + fclaw_initialize(glob); + } + fclaw_run(glob); fclaw_finalize(glob); diff --git a/applications/clawpack/advection/3d/swirl/swirl.cpp b/applications/clawpack/advection/3d/swirl/swirl.cpp index 1f94824a7..a7f523712 100644 --- a/applications/clawpack/advection/3d/swirl/swirl.cpp +++ b/applications/clawpack/advection/3d/swirl/swirl.cpp @@ -173,7 +173,18 @@ void run_program(fclaw_global_t* glob) /* --------------------------------------------------------------- Run --------------------------------------------------------------- */ - fclaw_initialize(glob); + + fclaw_options_t *fclaw_opt = fclaw_get_options(glob); + if(fclaw_opt->restart) + { + fclaw_restart(glob); + } + else + { + fclaw_initialize(glob); + } + + fclaw_run(glob); fclaw_finalize(glob); } From 266bb44d83cc64ce7d3f938c5f9884b6b7feda2f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 13:20:27 -0600 Subject: [PATCH 58/76] fix the check_user_string function --- src/fclaw_restart.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index c362887f6..b5a881211 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -286,20 +286,36 @@ free_used_ini(void* data) FCLAW_FREE(buffer); } +/** + * @brief Check that the user string matches an expected string. + * The user string returned by fclaw_file functions is padded with spaces, + * so we need to check that the strings match up to the first space and that + * the rest of the string is just spaces. + * + * @param expected the expected string + * @param actual the actual string + */ static void check_user_string(const char* expected, const char* actual) { if(strncmp(expected, actual, strlen(expected)) != 0) + { + fclaw_abortf("fclaw_restart.c: User string mismatch: %s != %s\n", expected, actual); + } + else { //also check that rest of the string is just spaces for(int i = strlen(expected); i < FCLAW_FILE_USER_STRING_BYTES; i++) { - if(actual[i] != ' ') + if(actual[i] != '\0') + { + break; + } + else if(actual[i] != ' ') { fclaw_abortf("fclaw_restart.c: User string mismatch: %s != %s\n", expected, actual); } } - fclaw_abortf("fclaw_restart.c: User string mismatch: %s != %s\n", expected, actual); } } @@ -433,7 +449,7 @@ void restart (fclaw_global_t * glob, fc = fclaw_file_read_block(fc, user_string, ini_length, &array, &errcode); - check_user_string(user_string, "used_ini"); + check_user_string("used_ini", user_string); CHECK_ERROR_CODE_AND_ABORT(refine_dim, errcode, "restart read used_ini"); const char* used_ini = (const char*) sc_array_index(&array, 0); From 5a542d9b5fa5adc6e4f13e6e22b0766400efd196 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 13:38:32 -0600 Subject: [PATCH 59/76] consider all cases when checking options --- src/fclaw_restart.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index b5a881211..048b5f283 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -199,21 +199,58 @@ compare_dictionaries(sc_keyvalue_t *fclaw_opt_secitons, char* actual_value = iniparser_getstring(actual, key, NULL); if(strcmp(expected_value, actual_value) != 0) { - fclaw_global_productionf("%s has mismatched value for %s: %s != %s.\n", section, key, expected_value, actual_value); + fclaw_global_productionf("restarting with mismatched value for [%s]. Value in checkpoint [%s], value being run with [%s].\n", key, expected_value, actual_value); num_differences++; } } else { - //fclaw_global_productionf("%s has unused option %s.\n", filename, keys[i_key]); + fclaw_global_productionf("Checkpoint file has unused option %s.\n", keys[i_key]); + num_differences++; } } free (keys); } else { - //fclaw_global_productionf("%s has unused section [%s].\n", filename, section); + fclaw_global_productionf("Checkpoint file has unused section [%s].\n", section); + num_differences++; + } + } + } + // do inverse and look for options in actual that are not in expected + nsec = iniparser_getnsec(actual); + for(int i_sec = 0; i_sec < nsec; i_sec++) + { + char* section = iniparser_getsecname(actual, i_sec); + if(strcmp(section, "arguments") != 0) + { + if(!iniparser_find_entry(expected, section)) + { + fclaw_global_productionf("Checkpoint file is missing section [%s].\n", section); + num_differences++; + } + else + { + int nkey = iniparser_getsecnkeys(actual, section); + char** keys = iniparser_getseckeys(actual, section); + + for(int i_key = 0; i_key < nkey; i_key++) + { + char* key = keys[i_key]; + if(skip_option(fclaw_opt_secitons, section, key)) + { + continue; + } + + if(!iniparser_find_entry(expected, key)) + { + fclaw_global_productionf("Checkpoint file is missing option %s.\n", keys[i_key]); + num_differences++; + } + } + free(keys); } } } From 6763fe29d9ed07c32f44a041ab345fa4ec545a24 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 13:41:10 -0600 Subject: [PATCH 60/76] add some more options to ingore when comparing options --- src/fclaw_restart.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 048b5f283..730e5e6b0 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -156,6 +156,14 @@ skip_option(sc_keyvalue_t *fclaw_opt_sections, const char* section, const char* { skip = 1; } + else if(strcmp(key_substr, "restart") == 0) + { + skip = 1; + } + else if(strcmp(key_substr, "checkpoint") == 0) + { + skip = 1; + } } return skip; } From bed87a76347f0246208775036b8b8bdd6363ff7f Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 13:44:45 -0600 Subject: [PATCH 61/76] add some more breakpoints in output --- src/fclaw_restart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 730e5e6b0..21e78dc09 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -276,6 +276,7 @@ check_options(fclaw_global_t * glob, const char* checkpoint_ini) { if(glob->mpirank == 0) { + fclaw_global_productionf("\n"); fclaw_global_productionf("=========== Comparing with options stored in checkpoint ===========\n"); fclaw_global_productionf("\n"); @@ -301,7 +302,7 @@ check_options(fclaw_global_t * glob, const char* checkpoint_ini) fprintf(file, "%s", checkpoint_ini); fclose(file); - fclaw_global_productionf("Checkpoints options saved to fclaw_options.ini.checkpoint\n"); + fclaw_global_productionf("Checkpoint options have been saved to fclaw_options.ini.checkpoint\n"); fclaw_global_productionf("\n"); dictionary *actual = iniparser_load("fclaw_options.ini.used"); @@ -321,6 +322,7 @@ check_options(fclaw_global_t * glob, const char* checkpoint_ini) fclaw_global_productionf("\n"); fclaw_global_productionf("===================================================================\n"); + fclaw_global_productionf("\n"); } } From e6fd4372435960d94e667aaf214717686fe3d268 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 14:29:09 -0600 Subject: [PATCH 62/76] add error message if sc options structure is used in glob --- src/fclaw_restart.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 21e78dc09..f61a94ea7 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -85,6 +85,12 @@ get_used_ini(fclaw_global_t * glob) if(glob->mpirank == 0) { sc_options_t * options = fclaw_global_get_attribute(glob, "fclaw_options"); + if(options == NULL) + { + fclaw_abortf("fclaw_restart.c: Cannot find sc options structure in glob." + " Make sure the fclaw_global_new(app) constructor is being used in main.\n"); + } + int retval = sc_options_save (fclaw_get_package_id (), FCLAW_VERBOSITY_ERROR, options, From 97cd5d5211ceb9657e965669fe617cd4b9941afe Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 14:48:52 -0600 Subject: [PATCH 63/76] update glob constructor in 2d/swirl --- applications/clawpack/advection/2d/swirl/swirl.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/applications/clawpack/advection/2d/swirl/swirl.cpp b/applications/clawpack/advection/2d/swirl/swirl.cpp index ebc4c15f3..daaee6f93 100644 --- a/applications/clawpack/advection/2d/swirl/swirl.cpp +++ b/applications/clawpack/advection/2d/swirl/swirl.cpp @@ -119,9 +119,7 @@ main (int argc, char **argv) if (!vexit) { /* Create global structure which stores the domain, timers, etc */ - int size, rank; - sc_MPI_Comm mpicomm = fclaw_app_get_mpi_size_rank (app, &size, &rank); - fclaw_global_t *glob = fclaw_global_new_comm (mpicomm, size, rank); + fclaw_global_t *glob = fclaw_global_new (app); /* Store option packages in glob */ fclaw_options_store (glob, fclaw_opt); From ae76ec26519f5a45497a98332cd1367cd0ec6f39 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 15:22:16 -0600 Subject: [PATCH 64/76] remove fclaw_run_vtables_intialize --- src/fclaw_forestclaw.h | 1 - src/fclaw_run.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/fclaw_forestclaw.h b/src/fclaw_forestclaw.h index fb9ba5426..20e46e373 100644 --- a/src/fclaw_forestclaw.h +++ b/src/fclaw_forestclaw.h @@ -44,7 +44,6 @@ void fclaw_vtables_initialize(struct fclaw_global *glob); * @param glob the global context */ void fclaw_initialize_domain_flags(struct fclaw_global *glob); -void fclaw_run_vtables_initialize(struct fclaw_global *glob); void fclaw_initialize (struct fclaw_global *glob); /** diff --git a/src/fclaw_run.c b/src/fclaw_run.c index 3ffb6b3fb..8fa534b2f 100644 --- a/src/fclaw_run.c +++ b/src/fclaw_run.c @@ -577,9 +577,4 @@ void fclaw_run(fclaw_global_t *glob) fclaw_global_essentialf("Outstyle %d not implemented yet\n", fclaw_opt->outstyle); exit(0); } -} - -void fclaw_run_vtables_initialize(struct fclaw_global *glob) -{ - } \ No newline at end of file From 165ff132dcd3b6cc09f183c470341083b3ea6b43 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 15:25:57 -0600 Subject: [PATCH 65/76] add some missing pointer casts --- src/fclaw_context.c | 7 ++++--- src/fclaw_gauges.c | 3 ++- src/fclaw_restart.c | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/fclaw_context.c b/src/fclaw_context.c index 66968f355..76ab801eb 100644 --- a/src/fclaw_context.c +++ b/src/fclaw_context.c @@ -89,7 +89,8 @@ reset_pointers(const char *key, void *data, void *user) fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name) { - fclaw_context_t *context = fclaw_global_get_attribute(glob, name); + fclaw_context_t *context = + (fclaw_context_t*) fclaw_global_get_attribute(glob, name); if(context == NULL) { @@ -115,7 +116,7 @@ void fclaw_context_get_int(fclaw_context_t *context, const char *name, int *value) { - value_t *v = fclaw_pointer_map_get(context->values, name); + value_t *v = (value_t*) fclaw_pointer_map_get(context->values, name); if(v != NULL) { if(v->type != FCLAW_CONTEXT_INT) @@ -142,7 +143,7 @@ void fclaw_context_get_double(fclaw_context_t *context, const char *name, double *value) { - value_t *v = fclaw_pointer_map_get(context->values, name); + value_t *v = (value_t*) fclaw_pointer_map_get(context->values, name); if(v != NULL) { if(v->type != FCLAW_CONTEXT_DOUBLE) diff --git a/src/fclaw_gauges.c b/src/fclaw_gauges.c index a2c390559..1dfd6d079 100644 --- a/src/fclaw_gauges.c +++ b/src/fclaw_gauges.c @@ -355,7 +355,8 @@ void fclaw_locate_gauges(fclaw_global_t *glob) fclaw_gauge_t *g; - fclaw_gauge_acc_t* gauge_acc = fclaw_diagnostics_get_acc(glob)->gauge_accumulator; + fclaw_gauge_acc_t* gauge_acc = + (fclaw_gauge_acc_t*) fclaw_diagnostics_get_acc(glob)->gauge_accumulator; //fclaw_gauge_info_t* gauge_info = glob->gauge_info; /* Locate each gauge in the new mesh */ diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index f61a94ea7..97079b0aa 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -84,7 +84,7 @@ get_used_ini(fclaw_global_t * glob) long length = 0; if(glob->mpirank == 0) { - sc_options_t * options = fclaw_global_get_attribute(glob, "fclaw_options"); + sc_options_t * options = (sc_options_t*) fclaw_global_get_attribute(glob, "fclaw_options"); if(options == NULL) { fclaw_abortf("fclaw_restart.c: Cannot find sc options structure in glob." @@ -287,7 +287,8 @@ check_options(fclaw_global_t * glob, const char* checkpoint_ini) fclaw_global_productionf("\n"); //save the used ini file - sc_options_t * options = fclaw_global_get_attribute(glob, "fclaw_options"); + sc_options_t * options = + (sc_options_t*) fclaw_global_get_attribute(glob, "fclaw_options"); int retval = sc_options_save (fclaw_get_package_id (), FCLAW_VERBOSITY_ERROR, options, @@ -315,7 +316,7 @@ check_options(fclaw_global_t * glob, const char* checkpoint_ini) dictionary *expected = iniparser_load("fclaw_options.ini.checkpoint"); sc_keyvalue_t *fclaw_opt_sections - = fclaw_global_get_attribute(glob, "fclaw_opt_sections"); + = (sc_keyvalue_t*) fclaw_global_get_attribute(glob, "fclaw_opt_sections"); int num_differences = compare_dictionaries(fclaw_opt_sections, expected, actual); iniparser_freedict(actual); @@ -640,7 +641,8 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) //write the used_ini length and string - char* used_ini = fclaw_global_get_attribute(glob, "fclaw_used_ini"); + char* used_ini = + (char*) fclaw_global_get_attribute(glob, "fclaw_used_ini"); if(used_ini == NULL) { used_ini = get_used_ini(glob); From 197de68bd2320bb52b1cfdd8d0e8c9ca1b7a693d Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 15:30:39 -0600 Subject: [PATCH 66/76] add another missing cast in fclaw_options.c --- src/fclaw_options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fclaw_options.c b/src/fclaw_options.c index c9a97597e..32b541e60 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -533,7 +533,8 @@ options_destroy (fclaw_app_t * a, void *package, void *registered) fclaw_options_destroy (fclaw_opt); /* Destroy linked list of section names */ - sc_keyvalue_t * fclaw_opt_sections = fclaw_app_get_attribute(a, "fclaw_opt_sections", NULL); + sc_keyvalue_t * fclaw_opt_sections = + (sc_keyvalue_t*) fclaw_app_get_attribute(a, "fclaw_opt_sections", NULL); if(fclaw_opt_sections != NULL) { sc_keyvalue_destroy(fclaw_opt_sections); From 912d2d5eb8231002ebf663468884fc438c321aad Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 15:31:42 -0600 Subject: [PATCH 67/76] use enum typename --- src/fclaw_restart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 97079b0aa..f7da1662b 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -413,7 +413,7 @@ static void restart (fclaw_global_t * glob, const char* restart_filename, const char* partition_filename, - int timer) + fclaw_timer_names_t timer) { int refine_dim = glob->domain->refine_dim; fclaw_domain_reset(glob); From 1df4a83045f9ab88488996de4b4f279607206cc3 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 16:56:27 -0600 Subject: [PATCH 68/76] fix another pointer case in fclaw_options.c --- src/fclaw_options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fclaw_options.c b/src/fclaw_options.c index 32b541e60..d9fd58f0e 100644 --- a/src/fclaw_options.c +++ b/src/fclaw_options.c @@ -577,7 +577,8 @@ fclaw_options_t* fclaw_options_register (fclaw_app_t * a, fclaw_opt); /* append to list of sections for fclaw_opts */ - sc_keyvalue_t *fclaw_opt_sections = fclaw_app_get_attribute(a, "fclaw_opt_sections", NULL); + sc_keyvalue_t *fclaw_opt_sections = + (sc_keyvalue_t*) fclaw_app_get_attribute(a, "fclaw_opt_sections", NULL); if(fclaw_opt_sections == NULL) { fclaw_opt_sections = sc_keyvalue_new(); From 0f7ee7e57e90d4aeaa6f681e7c30c35eb91b53bb Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 16:59:40 -0600 Subject: [PATCH 69/76] remove packing vtables form fclaw_base --- src/fclaw_base.c | 19 ------------------- src/fclaw_base.h | 18 ------------------ src/fclaw_global.c | 1 + src/fclaw_packing.h | 2 +- 4 files changed, 2 insertions(+), 38 deletions(-) diff --git a/src/fclaw_base.c b/src/fclaw_base.c index 22ad740e1..c84fd393d 100644 --- a/src/fclaw_base.c +++ b/src/fclaw_base.c @@ -31,7 +31,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static const char *fclaw_configdir = ".forestclaw"; static const char *fclaw_env_configdir = "FCLAW_INI_DIR"; static int fclaw_package_id = -1; -static fclaw_pointer_map_t* packing_vtables = NULL; int fclaw_app_exit_type_to_status (fclaw_exit_type_t vexit) @@ -352,8 +351,6 @@ fclaw_app_destroy (fclaw_app_t * a) FCLAW_FREE (a); - if(packing_vtables!=NULL) fclaw_pointer_map_destroy(packing_vtables); - sc_finalize (); mpiret = sc_MPI_Finalize (); @@ -929,22 +926,6 @@ fclaw_app_get_options (fclaw_app_t * a) } -void fclaw_app_register_options_packing_vtable(const char*name,fclaw_packing_vtable_t* vtable){ - if(packing_vtables == NULL) - { - packing_vtables = fclaw_pointer_map_new(); - } - fclaw_pointer_map_insert(packing_vtables, name, vtable, NULL); -} - -fclaw_packing_vtable_t* fclaw_app_get_options_packing_vtable(const char*name){ - if(packing_vtables == NULL) - { - packing_vtables = fclaw_pointer_map_new(); - } - return (fclaw_packing_vtable_t*) fclaw_pointer_map_get(packing_vtables,name); -} - void fclaw_abortf(const char *fmt, ...){ va_list ap; diff --git a/src/fclaw_base.h b/src/fclaw_base.h index 66d8ff61f..677f096aa 100644 --- a/src/fclaw_base.h +++ b/src/fclaw_base.h @@ -488,24 +488,6 @@ void fclaw_app_options_register (fclaw_app_t * a, const fclaw_app_options_vtable_t * vt, void *package); -typedef struct fclaw_packing_vtable fclaw_packing_vtable_t; - -/** - * @brief Register a vtable used for packing an options structure - * - * @param name the name, this should be the same name used for storing options in the glob - * @param vtable the vtable - */ -void fclaw_app_register_options_packing_vtable(const char*name,fclaw_packing_vtable_t* vtable); - -/** - * @brief Get an options packing vtable - * - * @param name the name, this should be the same name used for storing options in the glob - * @return fclaw_packing_vtable_t* the vtable - */ -fclaw_packing_vtable_t* fclaw_app_get_options_packing_vtable(const char* name); - /** * \brief Check if core options have been registered for this app * diff --git a/src/fclaw_global.c b/src/fclaw_global.c index ac48b00b1..507a99a5d 100644 --- a/src/fclaw_global.c +++ b/src/fclaw_global.c @@ -37,6 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include static fclaw_global_t* global_new (void) diff --git a/src/fclaw_packing.h b/src/fclaw_packing.h index 1f3276ad0..28c9b1165 100644 --- a/src/fclaw_packing.h +++ b/src/fclaw_packing.h @@ -101,7 +101,7 @@ typedef struct fclaw_packing_vtable fclaw_packing_packsize_t size; /**< function for packing size */ fclaw_packing_new_t new_data; /**< function for creating new data */ fclaw_packing_destroy_t destroy; /**< function for destroying */ -} fclaw_useradata_vtable_t; +} fclaw_packing_vtable_t; /** * @brief Get the size needed for packing a string From 9f9112072ce61e527607ae28d338d7562dc719f0 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 17:12:08 -0600 Subject: [PATCH 70/76] add fclaw_output header to fclaw_restart.c --- src/fclaw_restart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index f7da1662b..84abc5614 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -35,6 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include /** From bdbfed909ca7eab9f57007cc6222ce277ff7e66c Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 17:15:38 -0600 Subject: [PATCH 71/76] fix fclaw_diagnostics.h --- src/fclaw_diagnostics.h | 159 ---------------------------------------- 1 file changed, 159 deletions(-) diff --git a/src/fclaw_diagnostics.h b/src/fclaw_diagnostics.h index 1fadd2407..b2486ee1d 100644 --- a/src/fclaw_diagnostics.h +++ b/src/fclaw_diagnostics.h @@ -28,165 +28,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef __cplusplus extern "C" -/** - * @file fclaw_diagnostics.h - * @brief Header file containing declarations for diagnostic functions and structures. - */ - -#ifndef FCLAW_DIAGNOSTICS_H -#define FCLAW_DIAGNOSTICS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** - * @struct fclaw_diagnostics_accumulator - * @brief Structure representing the accumulator for diagnostic information. - */ -struct fclaw_diagnostics_accumulator -{ - void* patch_accumulator; /**< Pointer to the patch accumulator */ - void* solver_accumulator; /**< Pointer to the solver accumulator */ - void* user_accumulator; /**< Pointer to the user accumulator */ - void* gauge_accumulator; /**< Pointer to the gauge accumulator */ - void* ray_accumulator; /**< Pointer to the ray accumulator */ -}; - -/** - * @typedef fclaw_diagnostics_initialize_t - * @brief Function pointer type for the initialization of diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @param acc Pointer to the accumulator. - */ -typedef void (*fclaw_diagnostics_initialize_t)(struct fclaw_global *glob, void** acc); - -/** - * @typedef fclaw_diagnostics_compute_t - * @brief Function pointer type for the computation of diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @param acc Pointer to the accumulator. - */ -typedef void (*fclaw_diagnostics_compute_t)(struct fclaw_global *glob, void* acc); - -/** - * @typedef fclaw_diagnostics_gather_t - * @brief Function pointer type for the gathering of diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @param acc Pointer to the accumulator. - * @param init_flag Flag indicating whether the gathering is for initialization. - */ -typedef void (*fclaw_diagnostics_gather_t)(struct fclaw_global *glob, void* acc, int init_flag); - -/** - * @typedef fclaw_diagnostics_reset_t - * @brief Function pointer type for the resetting of diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @param acc Pointer to the accumulator. - */ -typedef void (*fclaw_diagnostics_reset_t)(struct fclaw_global *glob, void* acc); - -/** - * @typedef fclaw_diagnostics_finalize_t - * @brief Function pointer type for the finalization of diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @param acc Pointer to the accumulator. - */ -typedef void (*fclaw_diagnostics_finalize_t)(struct fclaw_global *glob, void** acc); - -/** - * @struct fclaw_diagnostics_vtable - * @brief Structure representing the virtual table for diagnostic functions. - */ -struct fclaw_diagnostics_vtable -{ - fclaw_diagnostics_initialize_t patch_init_diagnostics; /**< Function pointer for patch diagnostic initialization */ - fclaw_diagnostics_compute_t patch_compute_diagnostics; /**< Function pointer for patch diagnostic computation */ - fclaw_diagnostics_gather_t patch_gather_diagnostics; /**< Function pointer for patch diagnostic gathering */ - fclaw_diagnostics_reset_t patch_reset_diagnostics; /**< Function pointer for patch diagnostic resetting */ - fclaw_diagnostics_finalize_t patch_finalize_diagnostics; /**< Function pointer for patch diagnostic finalization */ - fclaw_diagnostics_initialize_t solver_init_diagnostics; /**< Function pointer for solver diagnostic initialization */ - fclaw_diagnostics_compute_t solver_compute_diagnostics; /**< Function pointer for solver diagnostic computation */ - fclaw_diagnostics_gather_t solver_gather_diagnostics; /**< Function pointer for solver diagnostic gathering */ - fclaw_diagnostics_reset_t solver_reset_diagnostics; /**< Function pointer for solver diagnostic resetting */ - fclaw_diagnostics_finalize_t solver_finalize_diagnostics; /**< Function pointer for solver diagnostic finalization */ - fclaw_diagnostics_initialize_t gauges_init_diagnostics; /**< Function pointer for gauge diagnostic initialization */ - fclaw_diagnostics_compute_t gauges_compute_diagnostics; /**< Function pointer for gauge diagnostic computation */ - fclaw_diagnostics_gather_t gauges_gather_diagnostics; /**< Function pointer for gauge diagnostic gathering */ - fclaw_diagnostics_reset_t gauges_reset_diagnostics; /**< Function pointer for gauge diagnostic resetting */ - fclaw_diagnostics_finalize_t gauges_finalize_diagnostics; /**< Function pointer for gauge diagnostic finalization */ - fclaw_diagnostics_initialize_t ray_init_diagnostics; /**< Function pointer for ray diagnostic initialization */ - fclaw_diagnostics_compute_t ray_compute_diagnostics; /**< Function pointer for ray diagnostic computation */ - fclaw_diagnostics_gather_t ray_gather_diagnostics; /**< Function pointer for ray diagnostic gathering */ - fclaw_diagnostics_reset_t ray_reset_diagnostics; /**< Function pointer for ray diagnostic resetting */ - fclaw_diagnostics_finalize_t ray_finalize_diagnostics; /**< Function pointer for ray diagnostic finalization */ - fclaw_diagnostics_initialize_t user_init_diagnostics; /**< Function pointer for user-defined diagnostic initialization */ - fclaw_diagnostics_compute_t user_compute_diagnostics; /**< Function pointer for user-defined diagnostic computation */ - fclaw_diagnostics_gather_t user_gather_diagnostics; /**< Function pointer for user-defined diagnostic gathering */ - fclaw_diagnostics_reset_t user_reset_diagnostics; /**< Function pointer for user-defined diagnostic resetting */ - fclaw_diagnostics_finalize_t user_finalize_diagnostics; /**< Function pointer for user-defined diagnostic finalization */ - int is_set; /**< Flag indicating whether the virtual table is set */ -}; - -/** - * @brief Retrieves the virtual table for diagnostic functions. - * @param glob Pointer to the fclaw_global structure. - * @return Pointer to the fclaw_diagnostics_vtable structure. - */ -fclaw_diagnostics_vtable_t* fclaw_diagnostics_vt(struct fclaw_global* glob); - -/** - * @brief Retrieves the accumulator for diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @return Pointer to the fclaw_diagnostics_accumulator structure. - */ -fclaw_diagnostics_accumulator_t* fclaw_diagnostics_get_acc(struct fclaw_global* glob); - -/** - * @brief Initializes the virtual table for diagnostic functions. - * @param glob Pointer to the fclaw_global structure. - */ -void fclaw_diagnostics_vtable_initialize(struct fclaw_global* glob); - -/** - * @brief Computes the global minimum value within a domain. - * @param domain Pointer to the fclaw_domain structure. - * @param d The value to compute the minimum for. - * @return The global minimum value. - */ -double fclaw_domain_global_minimum(struct fclaw_domain* domain, double d); - -/** - * @brief Initializes the diagnostic information. - * @param glob Pointer to the fclaw_global structure. - */ -void fclaw_diagnostics_initialize(struct fclaw_global* glob); - -/** - * @brief Gathers the diagnostic information. - * @param glob Pointer to the fclaw_global structure. - * @param init_flag Flag indicating whether the gathering is for initialization. - */ -void fclaw_diagnostics_gather(struct fclaw_global* glob, int init_flag); - -/** - * @brief Resets the diagnostic information. - * @param glob Pointer to the fclaw_global structure. - */ -void fclaw_diagnostics_reset(struct fclaw_global* glob); - -/** - * @brief Finalizes the diagnostic information. - * @param glob Pointer to the fclaw_global structure. - */ -void fclaw_diagnostics_finalize(struct fclaw_global* glob); - -#ifdef __cplusplus -} -#endif - -#endif /* FCLAW_DIAGNOSTICS_H */ { #endif From d2d5a7aa4321cc85ce9e61d914ce47ce82a94278 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 17:18:31 -0600 Subject: [PATCH 72/76] add missing wrap documentation --- src/fclaw2d_wrap.h | 6 ++++++ src/fclaw3d_wrap.h | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/fclaw2d_wrap.h b/src/fclaw2d_wrap.h index a2e4aa0b7..8b531f7d2 100644 --- a/src/fclaw2d_wrap.h +++ b/src/fclaw2d_wrap.h @@ -113,6 +113,12 @@ fclaw2d_interpolate_point_wrap_cb (fclaw2d_domain_t * domain, int blockno, int patchno, void *point, void *user); +/** + * @brief Wrap get dimension independent domain from a 2d error code. + * + * @param errcode the 2d error code + * @return int the dimension independent error code + */ int fclaw2d_file_error_wrap(int errcode); #ifdef __cplusplus diff --git a/src/fclaw3d_wrap.h b/src/fclaw3d_wrap.h index 963c02694..0a9089994 100644 --- a/src/fclaw3d_wrap.h +++ b/src/fclaw3d_wrap.h @@ -115,8 +115,13 @@ fclaw3d_interpolate_point_wrap_cb (fclaw3d_domain_t * domain, int blockno, int patchno, void *point, void *user); -int -fclaw3d_file_error_wrap(int errcode); +/** + * @brief Wrap get dimension independent domain from a 3d error code. + * + * @param errcode the 3d error code + * @return int the dimension independent error code + */ +int fclaw3d_file_error_wrap(int errcode); #ifdef __cplusplus #if 0 From 6de3f0480ba6730d68ccf2ad027a9d68c3d6d403 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 17:32:49 -0600 Subject: [PATCH 73/76] fix formatting in wrap headers --- src/fclaw2d_wrap.h | 3 ++- src/fclaw3d_wrap.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fclaw2d_wrap.h b/src/fclaw2d_wrap.h index 8b531f7d2..0bc40e712 100644 --- a/src/fclaw2d_wrap.h +++ b/src/fclaw2d_wrap.h @@ -119,7 +119,8 @@ fclaw2d_interpolate_point_wrap_cb (fclaw2d_domain_t * domain, * @param errcode the 2d error code * @return int the dimension independent error code */ -int fclaw2d_file_error_wrap(int errcode); +int +fclaw2d_file_error_wrap(int errcode); #ifdef __cplusplus #if 0 diff --git a/src/fclaw3d_wrap.h b/src/fclaw3d_wrap.h index 0a9089994..3f9b42ba1 100644 --- a/src/fclaw3d_wrap.h +++ b/src/fclaw3d_wrap.h @@ -121,7 +121,8 @@ fclaw3d_interpolate_point_wrap_cb (fclaw3d_domain_t * domain, * @param errcode the 3d error code * @return int the dimension independent error code */ -int fclaw3d_file_error_wrap(int errcode); +int +fclaw3d_file_error_wrap(int errcode); #ifdef __cplusplus #if 0 From 01c3f395986c9e38156fd8b0c1e0aa642f788637 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Thu, 6 Jun 2024 17:45:39 -0600 Subject: [PATCH 74/76] cleanup patch vtable additions --- src/fclaw_patch.c | 24 ++--- src/fclaw_patch.h | 102 +++++++++++++++++----- src/fclaw_restart.c | 16 ++-- src/patches/clawpatch/fclaw_clawpatch.cpp | 8 +- 4 files changed, 103 insertions(+), 47 deletions(-) diff --git a/src/fclaw_patch.c b/src/fclaw_patch.c index 1677e25c5..d592b7aa2 100644 --- a/src/fclaw_patch.c +++ b/src/fclaw_patch.c @@ -810,36 +810,36 @@ void fclaw_patch_partition_unpack(fclaw_global_t *glob, /* ----------------------------------- Restart --------------------------------------- */ -int fclaw_patch_restart_num_pointers(fclaw_global_t* glob) +int fclaw_patch_checkpoint_num_pointers(fclaw_global_t* glob) { fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); - FCLAW_ASSERT(patch_vt->restart_num_pointers != NULL); - return patch_vt->restart_num_pointers(glob); + FCLAW_ASSERT(patch_vt->checkpoint_num_pointers != NULL); + return patch_vt->checkpoint_num_pointers(glob); } -void fclaw_patch_restart_pointer_sizes(struct fclaw_global *glob, size_t restart_sizes[]) +void fclaw_patch_checkpoint_pointer_sizes(struct fclaw_global *glob, size_t restart_sizes[]) { fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); - FCLAW_ASSERT(patch_vt->restart_pointer_sizes != NULL); - patch_vt->restart_pointer_sizes(glob, restart_sizes); + FCLAW_ASSERT(patch_vt->checkpoint_pointer_sizes != NULL); + patch_vt->checkpoint_pointer_sizes(glob, restart_sizes); } -void fclaw_patch_restart_names(fclaw_global_t* glob, const char *names[]) +void fclaw_patch_checkpoint_names(fclaw_global_t* glob, const char *names[]) { fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); - FCLAW_ASSERT(patch_vt->restart_names != NULL); - return patch_vt->restart_names(glob, names); + FCLAW_ASSERT(patch_vt->checkpoint_names != NULL); + return patch_vt->checkpoint_names(glob, names); } -void* fclaw_patch_restart_get_pointer(struct fclaw_global* glob, +void* fclaw_patch_checkpoint_get_pointer(struct fclaw_global* glob, struct fclaw_patch* this_patch, int blockno, int patchno, int pointerno) { fclaw_patch_vtable_t *patch_vt = fclaw_patch_vt(glob); - FCLAW_ASSERT(patch_vt->restart_get_pointer != NULL); - return patch_vt->restart_get_pointer(glob, this_patch, blockno, patchno, pointerno); + FCLAW_ASSERT(patch_vt->checkpoint_get_pointer != NULL); + return patch_vt->checkpoint_get_pointer(glob, this_patch, blockno, patchno, pointerno); } diff --git a/src/fclaw_patch.h b/src/fclaw_patch.h index 01ef289fe..7122778b6 100644 --- a/src/fclaw_patch.h +++ b/src/fclaw_patch.h @@ -832,39 +832,50 @@ size_t fclaw_patch_partition_packsize(struct fclaw_global* glob); ///@} /* ------------------------------------------------------------------------------------ */ -/// @name Restart +/// @name Checkpoint /* ------------------------------------------------------------------------------------ */ ///@{ /** - * @brief Get the number of restart pointers + * @brief Get the number of pointers to store in the checkpoint * * @param glob the global context * @return int the number of restart pointers */ -int fclaw_patch_restart_num_pointers(struct fclaw_global* glob); +int fclaw_patch_checkpoint_num_pointers(struct fclaw_global* glob); /** - * @brief Get the sizes of the restart data + * @brief Get the sizes of the checkpoint data * * @param[in] glob the global context * @param[out] restart_sizes an array of length ::fclaw_patch_restart_num_pointers * with the sizes of the restart data */ -void fclaw_patch_restart_pointer_sizes(struct fclaw_global* glob, size_t restart_sizes[]); +void fclaw_patch_checkpoint_pointer_sizes(struct fclaw_global* glob, size_t restart_sizes[]); + /** - * @brief Get the names of the restart data. + * @brief Get the names of the checkpoint data. * * @param glob the global context * @return sc_array_t* an array of strings */ -void fclaw_patch_restart_names(struct fclaw_global* glob, const char *names[]); +void fclaw_patch_checkpoint_names(struct fclaw_global* glob, const char *names[]); -void *fclaw_patch_restart_get_pointer(struct fclaw_global* glob, - struct fclaw_patch* this_patch, - int blockno, - int patchno, - int pointerno); +/** + * @brief Get a specific pointer for the checkpoint + * + * @param glob the global context + * @param this_patch the patch context + * @param blockno the block number + * @param patchno the patch number + * @param pointerno the pointer number + * @return void* the pointer + */ +void *fclaw_patch_checkpoint_get_pointer(struct fclaw_global* glob, + struct fclaw_patch* this_patch, + int blockno, + int patchno, + int pointerno); ///@} /* ------------------------------------------------------------------------------------ */ @@ -1579,6 +1590,53 @@ typedef void (*fclaw_patch_destroy_user_data_t)(struct fclaw_global* glob, */ typedef void* (*fclaw_patch_metric_patch_t)(struct fclaw_patch *patch); +///@} +/* ------------------------------------------------------------------------------------ */ +/// @name Checkpoint Functions (typedefs) +/* ------------------------------------------------------------------------------------ */ +///@{ + +/** + * @brief Get the number of pointers to store in the checkpoint + * + * @param glob the global context + * @return int the number of restart pointers + */ +typedef int (*checkpoint_num_pointers_t)(struct fclaw_global *glob); + +/** + * @brief Get the sizes of the checkpoint data + * + * @param[in] glob the global context + * @param[out] restart_sizes an array of length ::fclaw_patch_restart_num_pointers + * with the sizes of the restart data + */ +typedef void (*checkpoint_pointer_sizes_t)(struct fclaw_global *glob, size_t sizes[]); + +/** + * @brief Get the names of the checkpoint data. + * + * @param glob the global context + * @return sc_array_t* an array of strings + */ +typedef void (*checkpoint_names_t)(struct fclaw_global *glob, const char *restart_names[]); + +/** + * @brief Get a specific pointer for the checkpoint + * + * @param glob the global context + * @param this_patch the patch context + * @param blockno the block number + * @param patchno the patch number + * @param pointerno the pointer number + * @return void* the pointer + */ +typedef void *(*checkpoint_get_pointer_t)(struct fclaw_global* glob, + struct fclaw_patch* this_patch, + int blockno, + int patchno, + int pointerno); + ///@} /* ------------------------------------------------------------------------------------ */ /// @name Virtual Table @@ -1751,19 +1809,17 @@ struct fclaw_patch_vtable /** @} */ - /** @{ @name Restart Functions */ - - int (*restart_num_pointers)(struct fclaw_global *glob); - - void (*restart_pointer_sizes)(struct fclaw_global *glob, size_t sizes[]); + /** @{ @name Checkpoint Functions */ - void (*restart_names)(struct fclaw_global *glob, const char *restart_names[]); + /** @copybrief :: checkpoint_num_pointers_t */ + checkpoint_num_pointers_t checkpoint_num_pointers; + /** @copybrief :: checkpoint_pointer_sizes_t */ + checkpoint_pointer_sizes_t checkpoint_pointer_sizes; + /** @copybrief :: checkpoint_names_t */ + checkpoint_names_t checkpoint_names; + /** @copybrief :: checkpoint_get_pointer_t */ + checkpoint_get_pointer_t checkpoint_get_pointer; - void *(*restart_get_pointer)(struct fclaw_global* glob, - struct fclaw_patch* this_patch, - int blockno, - int patchno, - int pointerno); /** @} */ /** True if vtable has been set */ diff --git a/src/fclaw_restart.c b/src/fclaw_restart.c index 84abc5614..564b86637 100644 --- a/src/fclaw_restart.c +++ b/src/fclaw_restart.c @@ -401,7 +401,7 @@ set_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat fclaw_patch_build(user_data->glob, patch, blockno, patchno,(void*) &build_mode); } - void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); + void* data = fclaw_patch_checkpoint_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); memcpy(data, sc_array_index(current_arr, 0), user_data->size); @@ -540,11 +540,11 @@ void restart (fclaw_global_t * glob, //read patch data - int num_pointers = fclaw_patch_restart_num_pointers(glob); + int num_pointers = fclaw_patch_checkpoint_num_pointers(glob); size_t sizes[num_pointers]; - fclaw_patch_restart_pointer_sizes(glob, sizes); + fclaw_patch_checkpoint_pointer_sizes(glob, sizes); const char* names[num_pointers]; - fclaw_patch_restart_names(glob, names); + fclaw_patch_checkpoint_names(glob, names); for(int i = 0; i < num_pointers; i++) { @@ -584,7 +584,7 @@ get_patches(fclaw_domain_t * domain, fclaw_patch_t * patch, int blockno, int pat sc_array_t *patches = user_data->patches; sc_array_t * current_arr = (sc_array_t *) sc_array_index (patches, user_data->curr_index); - void* data = fclaw_patch_restart_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); + void* data = fclaw_patch_checkpoint_get_pointer(user_data->glob, patch, blockno, patchno, user_data->pointerno); sc_array_init_data(current_arr, data, user_data->size, 1); @@ -705,11 +705,11 @@ checkpoint_output_frame (fclaw_global_t * glob, int iframe) //write patch data - int num_pointers = fclaw_patch_restart_num_pointers(glob); + int num_pointers = fclaw_patch_checkpoint_num_pointers(glob); size_t sizes[num_pointers]; - fclaw_patch_restart_pointer_sizes(glob, sizes); + fclaw_patch_checkpoint_pointer_sizes(glob, sizes); const char* names[num_pointers]; - fclaw_patch_restart_names(glob, names); + fclaw_patch_checkpoint_names(glob, names); for(int i = 0; i < num_pointers; i++) { sc_array_t *patches = sc_array_new_count(sizeof(sc_array_t), glob->domain->local_num_patches); diff --git a/src/patches/clawpatch/fclaw_clawpatch.cpp b/src/patches/clawpatch/fclaw_clawpatch.cpp index 397cf0c91..2a52820ee 100644 --- a/src/patches/clawpatch/fclaw_clawpatch.cpp +++ b/src/patches/clawpatch/fclaw_clawpatch.cpp @@ -1898,10 +1898,10 @@ void fclaw_clawpatch_vtable_initialize(fclaw_global_t* glob, patch_vt->partition_unpack = clawpatch_partition_unpack; /* restart */ - patch_vt->restart_num_pointers = restart_num_pointers; - patch_vt->restart_pointer_sizes = restart_pointer_sizes; - patch_vt->restart_names = restart_names; - patch_vt->restart_get_pointer = get_pointer; + patch_vt->checkpoint_num_pointers = restart_num_pointers; + patch_vt->checkpoint_pointer_sizes = restart_pointer_sizes; + patch_vt->checkpoint_names = restart_names; + patch_vt->checkpoint_get_pointer = get_pointer; /* output functions */ clawpatch_vt->time_header_ascii = fclaw_clawpatch_time_header_ascii; From 3b7247efefb596bb737f27697e309d431a7e404d Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 7 Jun 2024 10:29:11 -0600 Subject: [PATCH 75/76] add newlines to error mesage in fclaw_context.c --- src/fclaw_context.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fclaw_context.c b/src/fclaw_context.c index 76ab801eb..d2857fa75 100644 --- a/src/fclaw_context.c +++ b/src/fclaw_context.c @@ -102,7 +102,7 @@ fclaw_context_t* fclaw_context_get(fclaw_global_t *glob, const char *name) context->initializing = 0; if(!context->saved) { - fclaw_abortf("fclaw_context_get: Context needs to be saved before it can be retrieved again"); + fclaw_abortf("fclaw_context_get: Context needs to be saved before it can be retrieved again\n"); } context->saved = 0; fclaw_pointer_map_iterate(context->values, reset_pointers, NULL); @@ -121,7 +121,7 @@ void fclaw_context_get_int(fclaw_context_t *context, { if(v->type != FCLAW_CONTEXT_INT) { - fclaw_abortf("fclaw_context_get_int: Value %s is not an int", name); + fclaw_abortf("fclaw_context_get_int: Value %s is not an int\n", name); } *value = v->value.i; } @@ -133,7 +133,7 @@ void fclaw_context_get_int(fclaw_context_t *context, } else { - fclaw_abortf("fclaw_context_get_int: Value %s not found", name); + fclaw_abortf("fclaw_context_get_int: Value %s not found\n", name); } v->pointer = value; @@ -148,7 +148,7 @@ void fclaw_context_get_double(fclaw_context_t *context, { if(v->type != FCLAW_CONTEXT_DOUBLE) { - fclaw_abortf("fclaw_context_get_double: Value %s is not a double", name); + fclaw_abortf("fclaw_context_get_double: Value %s is not a double\n", name); } *value = v->value.d; } @@ -160,7 +160,7 @@ void fclaw_context_get_double(fclaw_context_t *context, } else { - fclaw_abortf("fclaw_context_get_double: Value %s not found", name); + fclaw_abortf("fclaw_context_get_double: Value %s not found\n", name); } v->pointer = value; @@ -169,10 +169,10 @@ void fclaw_context_get_double(fclaw_context_t *context, static void save_value(const char *key, void *data, void *user) { - value_t *value = (value_t *)data; + value_t *value = (value_t *) data; if(value->pointer == NULL) { - fclaw_abortf("fclaw_context_save: Value %s has no pointer", key); + fclaw_abortf("fclaw_context_save: Value %s has no pointer\n", key); } if(value->type == FCLAW_CONTEXT_INT) { @@ -224,7 +224,7 @@ size_t pack_context(fclaw_global_t *glob, void *data, char *buffer) if(!context->saved) { - fclaw_abortf("fclaw_context: Context not saved, cannot pack"); + fclaw_abortf("fclaw_context: Context not saved, cannot pack\n"); } buffer += fclaw_pack_int(fclaw_pointer_map_size(context->values), buffer); From 99d5f3286cbc8eac698be47c3bbf3718441f00e4 Mon Sep 17 00:00:00 2001 From: Scott Aiton Date: Fri, 7 Jun 2024 10:58:41 -0600 Subject: [PATCH 76/76] don't destroy after an abort, triggers an sc assert --- src/fclaw_context.h.TEST.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/fclaw_context.h.TEST.cpp b/src/fclaw_context.h.TEST.cpp index 8afcb2653..d3f07a833 100644 --- a/src/fclaw_context.h.TEST.cpp +++ b/src/fclaw_context.h.TEST.cpp @@ -52,7 +52,6 @@ TEST_CASE("fclaw_context_get existing context without saving") CHECK_NE(context1, nullptr); //should fail since it wasnn't saved CHECK_SC_ABORTED(fclaw_context_get(glob, "test")); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get existing context") @@ -193,7 +192,6 @@ TEST_CASE("fclaw_context_get_int called for non-existing value") context = fclaw_context_get(glob, "test"); int value; CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value)); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get_int called for non-exising value other value") @@ -206,7 +204,6 @@ TEST_CASE("fclaw_context_get_int called for non-exising value other value") context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_get_int(context, "test-does-not-exist", &value)); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get_int save without getting all variables") @@ -220,7 +217,6 @@ TEST_CASE("fclaw_context_get_int save without getting all variables") // second get call, since we don't get_int, should fail context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_save(context)); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get_double new context") @@ -335,7 +331,6 @@ TEST_CASE("fclaw_context_get_double called for non-existing value") context = fclaw_context_get(glob, "test"); double value; CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value)); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get_double called for non-exising value other value") @@ -348,7 +343,6 @@ TEST_CASE("fclaw_context_get_double called for non-exising value other value") context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_get_double(context, "test-does-not-exist", &value)); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get_double save without getting all variables") @@ -362,7 +356,6 @@ TEST_CASE("fclaw_context_get_double save without getting all variables") // second get call, since we don't get_double, should fail context = fclaw_context_get(glob, "test"); CHECK_SC_ABORTED(fclaw_context_save(context)); - fclaw_global_destroy(glob); } TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same value") @@ -408,8 +401,6 @@ TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same ke double value_double = default_double; CHECK_SC_ABORTED(fclaw_context_get_double(context, "test", &value_double)); - - fclaw_global_destroy(glob); } for(double default_double : {-100, 0, 42}) @@ -422,8 +413,6 @@ TEST_CASE("fclaw_context_get_double and fclaw_context_get_int called for same ke int value; CHECK_SC_ABORTED(fclaw_context_get_int(context, "test", &value)); - - fclaw_global_destroy(glob); } } @@ -446,8 +435,6 @@ TEST_CASE("fclaw_context pack/unpack glob int and double without save") char buffer[fclaw_global_packsize(glob)]; CHECK_SC_ABORTED(fclaw_global_pack(glob, buffer)); - - fclaw_global_destroy(glob); } }