From 07c42e54371f3a510abde0dede5d40ebd52246ad Mon Sep 17 00:00:00 2001 From: Kyle Klenk <kyle.c.klenk@gmail.com> Date: Thu, 18 Aug 2022 17:37:44 +0000 Subject: [PATCH] added structure for variables and can pass arrays to fortran --- build/includes/gru_actor/gru_actor.hpp | 18 +++- .../gru_actor_subroutine_wrappers.hpp | 5 +- build/makefile | 16 ++-- build/source/actors/global/global.cpp | 19 ++++ build/source/actors/gru_actor/gru_actor.cpp | 31 +++++- build/source/actors/gru_actor/gru_actor.f90 | 89 ++++++++++++++++-- build/source/actors/job_actor/job_actor.cpp | 4 +- build/source/actors/job_actor/job_actor.f90 | 5 +- build/source/actors/job_actor/job_actor.mod | Bin 0 -> 169 bytes .../laugh_tests/celia1990/output/runinfo.txt | 2 +- 10 files changed, 161 insertions(+), 28 deletions(-) create mode 100644 build/source/actors/job_actor/job_actor.mod diff --git a/build/includes/gru_actor/gru_actor.hpp b/build/includes/gru_actor/gru_actor.hpp index 95c257c..fd9a7a6 100644 --- a/build/includes/gru_actor/gru_actor.hpp +++ b/build/includes/gru_actor/gru_actor.hpp @@ -3,6 +3,7 @@ #include "caf/all.hpp" #include "fortran_data_types.hpp" #include "timing_info.hpp" +#include "global.hpp" #include <vector> #include <array> #include <chrono> @@ -19,11 +20,18 @@ struct gru_state { int ref_gru; // The actual ID of the GRU we are int num_hrus; - int num_bpar_vars; // number of variables in the fortran structure for bpar_struct - int num_bvar_vars; // number of variables in the fortran structure for bvar_struct - int n_time_delay = 2000; // number of timesteps in the time delay historgram. - std::vector<double> bpar_struct; - std::vector<std::vector<double>> bvar_struct; + + + int num_bpar_vars; // number of variables in the fortran structure for bpar_struct + std::vector<double> bpar_struct; + std::vector<int> bpar_struct_var_type_list; // The types to the variable at each element in bpar_struct + + int num_bvar_vars; // number of variables in the fortran structure for bvar_struct + std::vector<std::vector<double>> bvar_struct; + std::vector<int> bvar_struct_var_type_list; + + int num_var_types; + std::vector<int> i_look_var_type_list; // The types to the variable at each element in bvar_struct }; behavior gru_actor(stateful_actor<gru_state>* self, int refGRU, int indxGRU, diff --git a/build/includes/gru_actor/gru_actor_subroutine_wrappers.hpp b/build/includes/gru_actor/gru_actor_subroutine_wrappers.hpp index 61fd5aa..5e103fa 100644 --- a/build/includes/gru_actor/gru_actor_subroutine_wrappers.hpp +++ b/build/includes/gru_actor/gru_actor_subroutine_wrappers.hpp @@ -2,6 +2,9 @@ extern "C" { - void getVarSizes(int* num_bpar_vars, int* num_bvar_vars); + void getVarSizes(int* num_var_types, int* num_bpar_vars, int* num_bvar_vars); + + void fillVarTypeLists(int* num_var_types, int* num_bpar_vars, int* num_bvar_vars, void* i_look_var_type_list, + void* bpar_struct_var_type_list, void* bvar_struct_var_type_list); } \ No newline at end of file diff --git a/build/makefile b/build/makefile index 1154336..826cb4b 100644 --- a/build/makefile +++ b/build/makefile @@ -14,16 +14,16 @@ ACTORS_LIBRARIES = -L/usr/lib -L/usr/local/lib -L/Summa-Actors/bin -lcaf_core -l # Production runs -FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors -FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors -FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors -FLAGS_ACTORS = -O3 -Wfatal-errors -std=c++17 +# FLAGS_NOAH = -O3 -ffree-form -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors +# FLAGS_COMM = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors +# FLAGS_SUMMA = -O3 -ffree-line-length-none -fmax-errors=0 -fPIC -Wfatal-errors +# FLAGS_ACTORS = -O3 -Wfatal-errors -std=c++17 # Debug runs -# FLAGS_NOAH = -g -O0 -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -fPIC -# FLAGS_COMM = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC -# FLAGS_SUMMA = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC -# FLAGS_ACTORS = -g -O0 -Wall -std=c++17 +FLAGS_NOAH = -g -O0 -ffree-form -ffree-line-length-none -fmax-errors=0 -fbacktrace -Wno-unused -Wno-unused-dummy-argument -fPIC +FLAGS_COMM = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC +FLAGS_SUMMA = -g -O0 -Wall -ffree-line-length-none -fmax-errors=0 -fbacktrace -fcheck=bounds -fPIC +FLAGS_ACTORS = -g -O0 -Wall -std=c++17 diff --git a/build/source/actors/global/global.cpp b/build/source/actors/global/global.cpp index dff7bf4..c906fd5 100644 --- a/build/source/actors/global/global.cpp +++ b/build/source/actors/global/global.cpp @@ -1,6 +1,25 @@ #include "global.hpp" #include <chrono> +struct iLookVarType { + // These values should be one index less than the Fortran structure + // This is so they align with C++ vectors that start at 0 + int scalarv = -9999; + int wLength = -9999; + int midSnow = -9999; + int midSoil = -9999; + int midToto = -9999; + int ifcSnow = -9999; + int ifcSoil = -9999; + int ifcToto = -9999; + int parSoil = -9999; + int routing = -9999; + int outstat = -9999; + int unknown = -9999; +}; + + + double calculateTime(std::chrono::time_point<std::chrono::system_clock> start, std::chrono::time_point<std::chrono::system_clock> end) { diff --git a/build/source/actors/gru_actor/gru_actor.cpp b/build/source/actors/gru_actor/gru_actor.cpp index 19d7c6a..23449a1 100644 --- a/build/source/actors/gru_actor/gru_actor.cpp +++ b/build/source/actors/gru_actor/gru_actor.cpp @@ -2,6 +2,7 @@ #include "gru_actor.hpp" #include "global.hpp" #include "message_atoms.hpp" +#include <vector> #include "gru_actor_subroutine_wrappers.hpp" namespace caf { @@ -18,14 +19,38 @@ behavior gru_actor(stateful_actor<gru_state>* self, int refGRU, int indxGRU, // [=](init_gru) { // Get the variable data length, we also need the type information - aout(self) << "init GRU"; + aout(self) << "init GRU \n"; + int integer_missing_value = -9999; - getVarSizes(&self->state.num_bpar_vars, + // Get the sizes we need for the lists from Fortran + getVarSizes(&self->state.num_var_types, + &self->state.num_bpar_vars, &self->state.num_bvar_vars); - + + aout(self) << "GRU: GOT VAR SIZES\n"; + aout(self) << "NUM VAR Type = " << self->state.num_var_types << "\n"; aout(self) << "NUM BPAR = " << self->state.num_bpar_vars << "\n"; aout(self) << "NUM BVAR = " << self->state.num_bvar_vars << "\n"; + for (int i = 0; i < self->state.num_var_types; i++) { + self->state.i_look_var_type_list.push_back(integer_missing_value); + } + for (int i = 0; i < self->state.num_bpar_vars; i++) { + self->state.bpar_struct_var_type_list.push_back(integer_missing_value); + } + for (int i = 0; i < self->state.num_bvar_vars; i++) { + self->state.bvar_struct_var_type_list.push_back(integer_missing_value); + } + + // Fill The lists with the values from the fortran lists + fillVarTypeLists(&self->state.num_var_types, + &self->state.num_bpar_vars, + &self->state.num_bvar_vars, + &self->state.i_look_var_type_list[0], + &self->state.bpar_struct_var_type_list[0], + &self->state.bvar_struct_var_type_list[0]); + + } diff --git a/build/source/actors/gru_actor/gru_actor.f90 b/build/source/actors/gru_actor/gru_actor.f90 index 791cdaa..fe4c0b4 100644 --- a/build/source/actors/gru_actor/gru_actor.f90 +++ b/build/source/actors/gru_actor/gru_actor.f90 @@ -2,29 +2,104 @@ !!! If lateral flows exits use the code module gru_actor USE,intrinsic :: iso_c_binding +USE nrtype implicit none ! public::run_gru public::getVarSizes -! public::run_gru_for_timestep() +public::fillvarTypeLists contains -subroutine getVarSizes(num_bpar_vars, & +subroutine getVarSizes(num_var_types, & + num_bpar_vars, & num_bvar_vars) bind(C,name="getVarSizes") - USE var_lookup,only:maxvarBpar, maxvarBvar + USE var_lookup,only:maxvarBpar, maxvarBvar, maxvarVarType implicit none + + integer(c_int), intent(out) :: num_var_types + integer(c_int), intent(out) :: num_bpar_vars + integer(c_int), intent(out) :: num_bvar_vars - integer(c_int), intent(out) :: num_bpar_vars - integer(c_int), intent(out) :: num_bvar_vars - - + num_var_types = maxvarVarType num_bpar_vars = maxvarBpar num_bvar_vars = maxvarBvar end subroutine getVarSizes +subroutine initVarType(num_var_types, & + i_look_var_type_list) bind(C, name="initVarType") + USE var_lookup,only:iLookVarType + implicit none + integer(c_int), intent(in) :: num_var_types + integer(c_int), intent(out), dimension(num_var_types) :: i_look_var_type_list + + i_look_var_type_list(1) = iLookVarType%scalarv + i_look_var_type_list(2) = iLookVarType%wLength + i_look_var_type_list(3) = iLookVarType%midSnow + i_look_var_type_list(4) = iLookVarType%midSoil + i_look_var_type_list(5) = iLookVarType%midToto + i_look_var_type_list(6) = iLookVarType%ifcSnow + i_look_var_type_list(7) = iLookVarType%ifcSoil + i_look_var_type_list(8) = iLookVarType%ifcToto + i_look_var_type_list(9) = iLookVarType%parSoil + i_look_var_type_list(10) = iLookVarType%routing + i_look_var_type_list(11) = iLookVarType%outstat + i_look_var_type_list(12) = iLookVarType%unknown + +end subroutine +subroutine fillVarTypeLists(num_var_types, & + num_bpar_vars, & + num_bvar_vars, & + i_look_var_type_list, & + bpar_struct_var_type_list, & + bvar_struct_var_type_list) bind(C, name="fillVarTypeLists") + + USE globalData,only:type_meta,bpar_meta,bvar_meta + USE var_lookup,only:iLookBVAR,iLookBPAR,iLookVarType + implicit none + integer(c_int), intent(in) :: num_var_types + integer(c_int), intent(in) :: num_bpar_vars + integer(c_int), intent(in) :: num_bvar_vars + integer(c_int), intent(out), dimension(num_var_types) :: i_look_var_type_list + integer(c_int), intent(out), dimension(num_bpar_vars) :: bpar_struct_var_type_list + integer(c_int), intent(out), dimension(num_bvar_vars) :: bvar_struct_var_type_list + + integer(i4b) :: i + + i_look_var_type_list(1) = iLookVarType%scalarv + i_look_var_type_list(2) = iLookVarType%wLength + i_look_var_type_list(3) = iLookVarType%midSnow + i_look_var_type_list(4) = iLookVarType%midSoil + i_look_var_type_list(5) = iLookVarType%midToto + i_look_var_type_list(6) = iLookVarType%ifcSnow + i_look_var_type_list(7) = iLookVarType%ifcSoil + i_look_var_type_list(8) = iLookVarType%ifcToto + i_look_var_type_list(9) = iLookVarType%parSoil + i_look_var_type_list(10) = iLookVarType%routing + i_look_var_type_list(11) = iLookVarType%outstat + i_look_var_type_list(12) = iLookVarType%unknown + + do i = 1, num_var_types + print*, "iLookVarType = ", i_look_var_type_list(i) + end do + + do i = 1, num_bpar_vars + bpar_struct_var_type_list(i) = bpar_meta(i)%varType + end do + + do i = 1, num_bvar_vars + bvar_struct_var_type_list(i) = bvar_meta(i)%varType + end do + + + + + + +end subroutine fillVarTypeLists + ! subroutine run_gru_for_timestep() diff --git a/build/source/actors/job_actor/job_actor.cpp b/build/source/actors/job_actor/job_actor.cpp index 8cbb5a9..4d17d17 100644 --- a/build/source/actors/job_actor/job_actor.cpp +++ b/build/source/actors/job_actor/job_actor.cpp @@ -49,8 +49,8 @@ behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU, // Print Settings aout(self) << "\nSETTINGS FOR JOB_ACTOR\n" << - "File Manager Path = " << self->state.fileManager << "\n" << - "outputCSV = " << self->state.outputCSV << "\n"; + "File Manager Path = " << self->state.fileManager << "\n" << + "outputCSV = " << self->state.outputCSV << "\n"; if (self->state.outputCSV) { aout(self) << "csvPath = " << self->state.csvPath << "\n"; } diff --git a/build/source/actors/job_actor/job_actor.f90 b/build/source/actors/job_actor/job_actor.f90 index 6f30c1a..6aad13f 100644 --- a/build/source/actors/job_actor/job_actor.f90 +++ b/build/source/actors/job_actor/job_actor.f90 @@ -1,3 +1,6 @@ module job_actor implicit none -public::init_veg_ \ No newline at end of file + + + +end module \ No newline at end of file diff --git a/build/source/actors/job_actor/job_actor.mod b/build/source/actors/job_actor/job_actor.mod new file mode 100644 index 0000000000000000000000000000000000000000..b366c2ffbdafde27829cd595569503d7d44a7a84 GIT binary patch literal 169 zcmV;a09OAWiwFP!0000019Nxt4+;r#^i#;qPbtkwRVYg>D$dN$Q&2ZFRaZzZN=+<D zO;JcI%Fk8E%1??<OfJbU(o3^6;L_00RG<dpf-y9?fJ`jdNI@NLvpOnUUBOU6L&MkK zCDg}NA=J;?&p+Hx*V8Y=)h`6j4G8jg=7Mryf(ix-1`u131i%o+2RaALhd9mv;aZSR XE|9a39b%whq{#&UD#(i$NdW)=WA#Ms literal 0 HcmV?d00001 diff --git a/utils/laugh_tests/celia1990/output/runinfo.txt b/utils/laugh_tests/celia1990/output/runinfo.txt index 345b15b..0b31f04 100644 --- a/utils/laugh_tests/celia1990/output/runinfo.txt +++ b/utils/laugh_tests/celia1990/output/runinfo.txt @@ -1 +1 @@ - Run start time on system: ccyy=2022 - mm=08 - dd=17 - hh=22 - mi=54 - ss=02.427 + Run start time on system: ccyy=2022 - mm=08 - dd=18 - hh=16 - mi=51 - ss=11.619 -- GitLab