From 2c074ea012ea61ea50f6d2559b4eefd10ea3d90b Mon Sep 17 00:00:00 2001 From: Iskander Date: Sun, 10 Dec 2023 11:47:13 +0100 Subject: [PATCH 1/5] Added 4 stages --- src/LaMEMLib.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/LaMEMLib.cpp b/src/LaMEMLib.cpp index 4749742d..cd4cef60 100644 --- a/src/LaMEMLib.cpp +++ b/src/LaMEMLib.cpp @@ -613,6 +613,8 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) SNES snes; // PETSc nonlinear solver PetscInt restart; PetscLogDouble t; + PetscLogStage stages[4]; /* Create stages for PETSC profiling */ + PetscErrorCode ierr; PetscFunctionBeginUser; @@ -622,6 +624,12 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) ierr = PCStokesCreate(&pc, pm); CHKERRQ(ierr); ierr = NLSolCreate(&nl, pc, &snes); CHKERRQ(ierr); + /* Register names of the stages*/ + PetscCall(PetscLogStageRegister("Thermal solver", &stages[0])); + PetscCall(PetscLogStageRegister("SNES solve", &stages[1])); + PetscCall(PetscLogStageRegister("Advect markers", &stages[2])); + PetscCall(PetscLogStageRegister("I/O", &stages[3])); + //============== // INITIAL GUESS //============== @@ -649,17 +657,23 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) // initialize boundary constraint vectors ierr = BCApply(&lm->bc); CHKERRQ(ierr); + PetscCall(PetscLogStagePush(stages[0])); /* Start profiling stage*/ + // initialize temperature ierr = JacResInitTemp(&lm->jr); CHKERRQ(ierr); + PetscCall(PetscLogStagePop()); /* Stop profiling stage*/ // compute elastic parameters ierr = JacResGetI2Gdt(&lm->jr); CHKERRQ(ierr); // solve nonlinear equation system with SNES PetscTime(&t); + PetscCall(PetscLogStagePush(stages[1])); /* Start profiling stage*/ + ierr = SNESSolve(snes, NULL, lm->jr.gsol); CHKERRQ(ierr); + PetscCall(PetscLogStagePop()); /* Stop profiling stage*/ // print analyze convergence/divergence reason & iteration count ierr = SNESPrintConvergedReason(snes, t); CHKERRQ(ierr); @@ -686,6 +700,8 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) // MARKER & FREE SURFACE ADVECTION + EROSION //========================================== + PetscCall(PetscLogStagePush(stages[2])); /* Start profiling stage*/ + // calculate current time step ierr = ADVSelectTimeStep(&lm->actx, &restart); CHKERRQ(ierr); @@ -707,6 +723,8 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) // Advect Passive tracers ierr = ADVAdvectPassiveTracer(&lm->actx); CHKERRQ(ierr); + PetscCall(PetscLogStagePop()); /* Stop profiling stage*/ + // apply erosion to the free surface ierr = FreeSurfAppErosion(&lm->surf); CHKERRQ(ierr); @@ -725,10 +743,14 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) // update time stamp and counter ierr = TSSolStepForward(&lm->ts); CHKERRQ(ierr); - + + PetscCall(PetscLogStagePush(stages[3])); /* Start profiling stage*/ + // grid & marker output ierr = LaMEMLibSaveOutput(lm); CHKERRQ(ierr); + PetscCall(PetscLogStagePop()); /* Stop profiling stage*/ + // restart database ierr = LaMEMLibSaveRestart(lm); CHKERRQ(ierr); From 3688abaad002bf3cb4b79596a434f3233a26a5f8 Mon Sep 17 00:00:00 2001 From: Iskander Date: Fri, 15 Dec 2023 14:38:19 +0100 Subject: [PATCH 2/5] fixed for adjoint --- .settings/org.eclipse.cdt.core.prefs | 6 ++++++ src/LaMEM.cpp | 3 +-- src/LaMEM.h | 2 +- src/LaMEMLib.cpp | 7 +++---- src/LaMEMLib.h | 2 +- src/adjoint.cpp | 10 +++++----- src/objFunct.h | 2 ++ 7 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 .settings/org.eclipse.cdt.core.prefs diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 00000000..c8ec5df2 --- /dev/null +++ b/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,6 @@ +doxygen/doxygen_new_line_after_brief=true +doxygen/doxygen_use_brief_tag=false +doxygen/doxygen_use_javadoc_tags=true +doxygen/doxygen_use_pre_tag=false +doxygen/doxygen_use_structural_commands=false +eclipse.preferences.version=1 diff --git a/src/LaMEM.cpp b/src/LaMEM.cpp index 4b0f8b0e..78d35f5e 100644 --- a/src/LaMEM.cpp +++ b/src/LaMEM.cpp @@ -22,7 +22,6 @@ int main(int argc, char **argv) // Initialize PETSC ierr = PetscInitialize(&argc,&argv,(char *)0, help); CHKERRQ(ierr); - ModParam IOparam; char str[_str_len_]; @@ -45,7 +44,7 @@ int main(int argc, char **argv) if(IOparam.use == 0) { // Forward simulation - ierr = LaMEMLibMain(NULL); CHKERRQ(ierr); + ierr = LaMEMLibMain(NULL,IOparam.stages); CHKERRQ(ierr); } else { diff --git a/src/LaMEM.h b/src/LaMEM.h index c2ef21a0..a7f31905 100644 --- a/src/LaMEM.h +++ b/src/LaMEM.h @@ -189,7 +189,7 @@ typedef pair ipair; // LaMEM library main function -PetscErrorCode LaMEMLibMain(void *param); +PetscErrorCode LaMEMLibMain(void *param,PetscLogStage stages[4]); //----------------------------------------------------------------------------- #endif diff --git a/src/LaMEMLib.cpp b/src/LaMEMLib.cpp index cd4cef60..be35cdee 100644 --- a/src/LaMEMLib.cpp +++ b/src/LaMEMLib.cpp @@ -42,7 +42,7 @@ #include "passive_tracer.h" //--------------------------------------------------------------------------- -PetscErrorCode LaMEMLibMain(void *param) +PetscErrorCode LaMEMLibMain(void *param,PetscLogStage stages[4]) { LaMEMLib lm; RunMode mode; @@ -130,7 +130,7 @@ PetscErrorCode LaMEMLibMain(void *param) else if(mode == _NORMAL_ || mode == _RESTART_) { // solve coupled nonlinear equations - ierr = LaMEMLibSolve(&lm, param); CHKERRQ(ierr); + ierr = LaMEMLibSolve(&lm, param,stages); CHKERRQ(ierr); } // destroy library objects @@ -604,7 +604,7 @@ PetscErrorCode LaMEMLibSaveOutput(LaMEMLib *lm) PetscFunctionReturn(0); } //--------------------------------------------------------------------------- -PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) +PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param, PetscLogStage stages[4]) { PMat pm; // preconditioner matrix (to be removed!) PCStokes pc; // Stokes preconditioner (to be removed!) @@ -613,7 +613,6 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param) SNES snes; // PETSc nonlinear solver PetscInt restart; PetscLogDouble t; - PetscLogStage stages[4]; /* Create stages for PETSC profiling */ PetscErrorCode ierr; diff --git a/src/LaMEMLib.h b/src/LaMEMLib.h index 47ba5059..39fe340c 100644 --- a/src/LaMEMLib.h +++ b/src/LaMEMLib.h @@ -68,7 +68,7 @@ PetscErrorCode LaMEMLibSetLinks(LaMEMLib *lm); PetscErrorCode LaMEMLibSaveOutput(LaMEMLib *lm, PetscInt dirInd); -PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param); +PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param, PetscLogStage stages[4]); PetscErrorCode LaMEMLibDryRun(LaMEMLib *lm); diff --git a/src/adjoint.cpp b/src/adjoint.cpp index 67d11066..1dd1657e 100644 --- a/src/adjoint.cpp +++ b/src/adjoint.cpp @@ -984,7 +984,7 @@ PetscErrorCode LaMEMAdjointMain(ModParam *IOparam) // Only compute a forward model and the corresponding misfit IOparam->BruteForce_FD = PETSC_TRUE; // to return early w/out cmomputing FD gradients - ierr = LaMEMLibMain(IOparam); CHKERRQ(ierr); + ierr = LaMEMLibMain(IOparam,IOparam->stages); CHKERRQ(ierr); // Print overview of cost function & gradients ierr = PrintCostFunction(IOparam); CHKERRQ(ierr); @@ -1079,7 +1079,7 @@ PetscErrorCode LaMEMAdjointMain(ModParam *IOparam) else if(IOparam->use == _syntheticforwardrun_) { // call LaMEM main library function - ierr = LaMEMLibMain(IOparam); CHKERRQ(ierr); + ierr = LaMEMLibMain(IOparam,IOparam->stages); CHKERRQ(ierr); // Save output PetscViewer viewerVel; @@ -1212,7 +1212,7 @@ PetscErrorCode ComputeGradientsAndObjectiveFunction(Vec Parameters, PetscScalar // Adjoint gradients: Call LaMEM main library function once (computes gradients @ the end) IOparam->BruteForce_FD = PETSC_FALSE; - ierr = LaMEMLibMain(IOparam); CHKERRQ(ierr); + ierr = LaMEMLibMain(IOparam,IOparam->stages); CHKERRQ(ierr); // Print overview of cost function & gradients ierr = PrintCostFunction(IOparam); CHKERRQ(ierr); @@ -1827,7 +1827,7 @@ PetscErrorCode AdjointFiniteDifferenceGradients(ModParam *IOparam) if (FD_Adjoint){ // Call LaMEM - ierr = LaMEMLibMain(IOparam); CHKERRQ(ierr); // call LaMEM + ierr = LaMEMLibMain(IOparam,IOparam->stages); CHKERRQ(ierr); // call LaMEM Misfit_ref = IOparam->mfit; PetscPrintf(PETSC_COMM_WORLD,"| ************************************************************************ \n"); @@ -1863,7 +1863,7 @@ PetscErrorCode AdjointFiniteDifferenceGradients(ModParam *IOparam) ierr = CopyParameterToLaMEMCommandLine(IOparam, CurVal + Perturb, j); CHKERRQ(ierr); // Compute solution with updated parameter - ierr = LaMEMLibMain(IOparam); CHKERRQ(ierr); + ierr = LaMEMLibMain(IOparam,IOparam->stages); CHKERRQ(ierr); Misfit_pert = IOparam->mfit; // FD gradient diff --git a/src/objFunct.h b/src/objFunct.h index 1d00e79d..7f6df1d4 100644 --- a/src/objFunct.h +++ b/src/objFunct.h @@ -115,6 +115,8 @@ struct ModParam PetscScalar Avel_num[_MAX_OBS_]; // Numerically computed velocity at the comparison points PetscBool Apoint_on_proc[_MAX_OBS_]; // Is the observation point on the current processor or not (simplified printing)? char ScalLawFilename[_str_len_]; // Name of scaling law file + + PetscLogStage stages[4]; /* Create stages for PETSC profiling */ }; // observation type From b5fbbf1897c62c548d2f68dc970912cd794cd1f2 Mon Sep 17 00:00:00 2001 From: Iskander Date: Fri, 15 Dec 2023 15:09:08 +0100 Subject: [PATCH 3/5] deleted failing lines --- src/LaMEMLib.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/LaMEMLib.cpp b/src/LaMEMLib.cpp index be35cdee..8980f2e7 100644 --- a/src/LaMEMLib.cpp +++ b/src/LaMEMLib.cpp @@ -623,12 +623,6 @@ PetscErrorCode LaMEMLibSolve(LaMEMLib *lm, void *param, PetscLogStage stages[4]) ierr = PCStokesCreate(&pc, pm); CHKERRQ(ierr); ierr = NLSolCreate(&nl, pc, &snes); CHKERRQ(ierr); - /* Register names of the stages*/ - PetscCall(PetscLogStageRegister("Thermal solver", &stages[0])); - PetscCall(PetscLogStageRegister("SNES solve", &stages[1])); - PetscCall(PetscLogStageRegister("Advect markers", &stages[2])); - PetscCall(PetscLogStageRegister("I/O", &stages[3])); - //============== // INITIAL GUESS //============== From 2f9cc609264d88c015b5d81b6cb31c1ce79b2983 Mon Sep 17 00:00:00 2001 From: Iskander Date: Sat, 16 Dec 2023 22:32:16 +0100 Subject: [PATCH 4/5] updated version in Project.toml and deleted random eclipse folder --- .settings/org.eclipse.cdt.core.prefs | 6 ------ Project.toml | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 .settings/org.eclipse.cdt.core.prefs diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs deleted file mode 100644 index c8ec5df2..00000000 --- a/.settings/org.eclipse.cdt.core.prefs +++ /dev/null @@ -1,6 +0,0 @@ -doxygen/doxygen_new_line_after_brief=true -doxygen/doxygen_use_brief_tag=false -doxygen/doxygen_use_javadoc_tags=true -doxygen/doxygen_use_pre_tag=false -doxygen/doxygen_use_structural_commands=false -eclipse.preferences.version=1 diff --git a/Project.toml b/Project.toml index d7975f02..03504620 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LaMEM_C" uuid = "29b6043d-3311-4c16-b469-b02bf85cb680" authors = ["Anton Popov ", "Boris Kaus "] -version = "2.1.1" +version = "2.1.2" [deps] CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" From 415b361ecd71c3e6621c77dc174f96919bb26d44 Mon Sep 17 00:00:00 2001 From: Iskander Date: Sun, 17 Dec 2023 12:36:54 +0100 Subject: [PATCH 5/5] updated version number in lamemlib.cpp --- src/LaMEMLib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LaMEMLib.cpp b/src/LaMEMLib.cpp index 8980f2e7..78dbe3ef 100644 --- a/src/LaMEMLib.cpp +++ b/src/LaMEMLib.cpp @@ -60,7 +60,7 @@ PetscErrorCode LaMEMLibMain(void *param,PetscLogStage stages[4]) PetscPrintf(PETSC_COMM_WORLD,"-------------------------------------------------------------------------- \n"); PetscPrintf(PETSC_COMM_WORLD," Lithosphere and Mantle Evolution Model \n"); PetscPrintf(PETSC_COMM_WORLD," Compiled: Date: %s - Time: %s \n",__DATE__,__TIME__ ); - PetscPrintf(PETSC_COMM_WORLD," Version : 2.1.0 \n"); + PetscPrintf(PETSC_COMM_WORLD," Version : 2.1.2 \n"); PetscPrintf(PETSC_COMM_WORLD,"-------------------------------------------------------------------------- \n"); PetscPrintf(PETSC_COMM_WORLD," STAGGERED-GRID FINITE DIFFERENCE CANONICAL IMPLEMENTATION \n"); PetscPrintf(PETSC_COMM_WORLD,"-------------------------------------------------------------------------- \n");