[cig-commits] [commit] rajesh-petsc, rajesh-petsc-schur: configure.ac now checks for the existence of PETSc libraries if --with-petsc=yes is specified. All PETSc related code is enclosed by USE_PETSC conditional compilation guards (0c79a2e)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Nov 5 19:03:09 PST 2014


Repository : https://github.com/geodynamics/citcoms

On branches: rajesh-petsc,rajesh-petsc-schur
Link       : https://github.com/geodynamics/citcoms/compare/464e1b32299b15819f93efd98d969cddb84dfe51...f97ae655a50bdbd6dac1923a3471ee4dae178fbd

>---------------------------------------------------------------

commit 0c79a2e64a9bb09c1747a39dfb64223769f738f7
Author: Rajesh Kommu <rajesh.kommu at gmail.com>
Date:   Thu Aug 21 13:30:40 2014 -0700

    configure.ac now checks for the existence of PETSc libraries if
    --with-petsc=yes is specified. All PETSc related code is enclosed by
    USE_PETSC conditional compilation guards


>---------------------------------------------------------------

0c79a2e64a9bb09c1747a39dfb64223769f738f7
 bin/Citcom.c             |  9 ++++++++-
 configure.ac             | 11 +++++++++++
 lib/Drive_solvers.c      |  5 +++++
 lib/Instructions.c       |  4 ++--
 lib/Petsc_citcoms.c      |  4 ++++
 lib/Stokes_flow_Incomp.c | 18 ++++++++++++++++--
 lib/global_defs.h        |  9 +++++++--
 lib/petsc_citcoms.h      |  4 ++++
 lib/prototypes.h         |  4 ----
 9 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/bin/Citcom.c b/bin/Citcom.c
index 4dd3e90..84fe2da 100644
--- a/bin/Citcom.c
+++ b/bin/Citcom.c
@@ -70,10 +70,13 @@ int main(argc,argv)
 
   struct All_variables *E;
   MPI_Comm world;
+#ifdef USE_PETSC
   PetscErrorCode ierr;
-
   ierr = PetscInitialize(&argc, &argv, NULL, NULL);
   CHKERRQ(ierr);
+#else
+  MPI_Init(&argc, &argv); /* added here to allow command-line input */
+#endif
 
   if (argc < 2)   {
     fprintf(stderr,"Usage: %s PARAMETERFILE\n", argv[0]);
@@ -85,7 +88,11 @@ int main(argc,argv)
   /* this section reads input, allocates memory, and set some initial values;
    * replaced by CitcomS.Controller.initialize() and
    * CitcomS.Solver.initialize() in Pyre. */
+#ifdef USE_PETSC
   world = PETSC_COMM_WORLD;
+#else
+  world = MPI_COMM_WORLD;
+#endif
   E = citcom_init(&world); /* allocate global E and do initializaion here */
 
   /* define common aliases for full/regional functions */
diff --git a/configure.ac b/configure.ac
index 4193fb5..6b3e9c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,12 @@ AM_INIT_AUTOMAKE([foreign])
 # 'configure' options
 AC_ARG_VAR(PYTHON, [Python interpreter])
 AC_ARG_VAR(PYTHONPATH, [Python module search path])
+AC_ARG_WITH([petsc],
+    [AC_HELP_STRING([--with-petsc],
+        [use PETSc library @<:@default=no@:>@])],
+    [want_petsc="$withval"],
+    [want_petsc=no])
+AM_CONDITIONAL([COND_PETSC], [test "$want_petsc" = yes])
 AC_ARG_WITH([pyre],
     [AC_HELP_STRING([--with-pyre],
         [build Pyre modules @<:@default=no@:>@])],
@@ -74,6 +80,10 @@ AC_PROG_CXX([mpicxx mpic++ mpiCC hcp mpCC mpxlC mpxlC_r cmpic++ g++ c++ gpp aCC
 # Checking a system header here so that CPP is always defined
 AC_CHECK_HEADERS([malloc.h])
 
+if test "$want_petsc" = yes; then
+  CIT_PATH_PETSC(3.5.1,[CPPFLAGS="-DUSE_PETSC $CPPFLAGS"],[AC_MSG_ERROR([PETSc Library not found])])
+fi
+
 if test "$want_pyre" = yes; then
     # Check for Python.
     AM_PATH_PYTHON([2.3])
@@ -270,6 +280,7 @@ echo -e "\t with-pyre: " $want_pyre
 echo -e "\t with-exchanger: " $want_exchanger
 echo -e "\t with-hdf5: " $want_hdf5
 echo -e "\t with-ggrd: " $want_ggrd
+echo -e "\t with-petsc: " $want_petsc
 echo
 
 dnl end of configure.ac
diff --git a/lib/Drive_solvers.c b/lib/Drive_solvers.c
index 89fcc32..d85b1e5 100644
--- a/lib/Drive_solvers.c
+++ b/lib/Drive_solvers.c
@@ -30,7 +30,10 @@
 #include "element_definitions.h"
 #include "global_defs.h"
 #include "drive_solvers.h"
+
+#ifdef USE_PETSC
 #include "petsc_citcoms.h"
+#endif
 
 double global_vdot();
 double vnorm_nonnewt();
@@ -52,6 +55,7 @@ void general_stokes_solver_setup(struct All_variables *E)
       for (m=1;m<=E->sphere.caps_per_proc;m++)
 	E->elt_k[i][m]=(struct EK *)malloc((E->lmesh.NEL[i]+1)*sizeof(struct EK));
 
+#ifdef USE_PETSC
   /*
    * PETSc related initialization
    */
@@ -149,6 +153,7 @@ void general_stokes_solver_setup(struct All_variables *E)
   /************************************************************
    * End PETSc Initialization
    ************************************************************/
+#endif
 }
 
 void general_stokes_solver(struct All_variables *E)
diff --git a/lib/Instructions.c b/lib/Instructions.c
index a9b2f53..1c0c811 100644
--- a/lib/Instructions.c
+++ b/lib/Instructions.c
@@ -777,14 +777,14 @@ void read_initial_settings(struct All_variables *E)
 				   the tracer input */
 
   (E->problem_settings)(E);
-
+#ifdef USE_PETSC
   /* PETSc related flags */
   input_boolean("use_petsc",&E->control.use_petsc,"on",m);
   input_boolean("petsc_linear",&E->control.petsc_linear,"on",m);
   input_boolean("petsc_nonlinear",&E->control.petsc_nonlinear,"off",m);
   input_boolean("petsc_schur",&E->control.petsc_schur,"off",m);
   input_float("petsc_uzawa_tol", &E->control.petsc_uzawa_tol, "1e-6", m);
-
+#endif
   check_settings_consistency(E);
   return;
 }
diff --git a/lib/Petsc_citcoms.c b/lib/Petsc_citcoms.c
index 5bc8746..871400d 100644
--- a/lib/Petsc_citcoms.c
+++ b/lib/Petsc_citcoms.c
@@ -1,3 +1,5 @@
+#ifdef USE_PETSC
+
 #include "global_defs.h"
 #include "element_definitions.h"
 #include "petsc_citcoms.h"
@@ -308,3 +310,5 @@ PetscErrorCode MatShellMult_div_rho_u( Mat DC, Vec U, Vec DU )
   ierr = VecRestoreArray(DU, &DUData); CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
+
+#endif /* USE_PETSC */
diff --git a/lib/Stokes_flow_Incomp.c b/lib/Stokes_flow_Incomp.c
index ec2225e..3acae42 100644
--- a/lib/Stokes_flow_Incomp.c
+++ b/lib/Stokes_flow_Incomp.c
@@ -34,9 +34,12 @@
 #include <sys/types.h>
 #include "element_definitions.h"
 #include "global_defs.h"
-#include "petsc_citcoms.h"
 #include <stdlib.h>
 
+#ifdef USE_PETSC
+#include "petsc_citcoms.h"
+#endif
+
 void myerror(struct All_variables *,char *);
 
 static void solve_Ahat_p_fhat(struct All_variables *E,
@@ -52,6 +55,7 @@ static void solve_Ahat_p_fhat_iterCG(struct All_variables *E,
                                       double **V, double **P, double **F,
                                       double imp, int *steps_max);
 
+#ifdef USE_PETSC
 static PetscErrorCode solve_Ahat_p_fhat_PETSc_Schur(struct All_variables *E,
     double **V, double **P, double **F, double imp, int *steps_max);
 
@@ -60,6 +64,7 @@ static PetscErrorCode solve_Ahat_p_fhat_CG_PETSc(struct All_variables *E,
 
 static PetscErrorCode solve_Ahat_p_fhat_BiCG_PETSc(struct All_variables *E,
     double **V, double **P, double **F, double imp, int *steps_max);
+#endif
 
 static void initial_vel_residual(struct All_variables *E,
                                  double **V, double **P, double **F,
@@ -174,6 +179,7 @@ static void solve_Ahat_p_fhat(struct All_variables *E,
                                double **V, double **P, double **F,
                                double imp, int *steps_max)
 {
+#ifdef USE_PETSC
   if(E->control.use_petsc)
   {
     if(E->control.petsc_schur) // use Schur complement reduction
@@ -197,6 +203,7 @@ static void solve_Ahat_p_fhat(struct All_variables *E,
   }
   else                         // the original non-PETSc CitcomS code
   {
+#endif 
     if(E->control.inv_gruneisen == 0)
         solve_Ahat_p_fhat_CG(E, V, P, F, imp, steps_max);
     else {
@@ -207,9 +214,12 @@ static void solve_Ahat_p_fhat(struct All_variables *E,
         else
             myerror(E, "Error: unknown Uzawa iteration\n");
     }
+#ifdef USE_PETSC
   }
+#endif
 }
 
+#ifdef USE_PETSC
 static PetscErrorCode solve_Ahat_p_fhat_PETSc_Schur(struct All_variables *E,
   double **V, double **P, double **F, double imp, int *steps_max)
 {
@@ -327,6 +337,7 @@ static PetscErrorCode solve_Ahat_p_fhat_PETSc_Schur(struct All_variables *E,
 
   PetscFunctionReturn(0);
 }
+#endif
 
 /* Solve incompressible Stokes flow using
  * conjugate gradient (CG) iterations
@@ -597,6 +608,7 @@ static void solve_Ahat_p_fhat_CG(struct All_variables *E,
     return;
 }
 
+#ifdef USE_PETSC
 /*
  * Implementation of the Conjugate Gradient Uzawa algorithm using PETSc
  * Vec, Mat and KSPSolve
@@ -1093,6 +1105,7 @@ static PetscErrorCode solve_Ahat_p_fhat_BiCG_PETSc( struct All_variables *E,
 
   PetscFunctionReturn(0);
 }
+#endif /* USE_PETSC */
 
 /* Solve compressible Stokes flow using
  * bi-conjugate gradient stablized (BiCG-stab) iterations
@@ -1436,10 +1449,11 @@ static void solve_Ahat_p_fhat_iterCG(struct All_variables *E,
             for(i=0;i<neq;i++) old_v[m][i] = V[m][i];
             for(i=1;i<=npno;i++) old_p[m][i] = P[m][i];
         }
-
+#ifdef USE_PETSC
         if(E->control.use_petsc)
           solve_Ahat_p_fhat_CG_PETSc(E, V, P, F, imp, &cycles);
         else
+#endif
           solve_Ahat_p_fhat_CG(E, V, P, F, imp, &cycles);
 
 
diff --git a/lib/global_defs.h b/lib/global_defs.h
index 6087f60..1b2abae 100644
--- a/lib/global_defs.h
+++ b/lib/global_defs.h
@@ -44,9 +44,11 @@ to functions across the whole filespace of CITCOM.
 #include <stdio.h>
 #include <stdlib.h>
 #include <mpi.h>
+
+#ifdef USE_PETSC
 #include <petscksp.h>
 #include <petscsnes.h>
-
+#endif
 
 
 #ifdef USE_HDF5
@@ -558,13 +560,14 @@ struct CONTROL {
 
     int print_convergence;
     int sdepv_print_convergence;
-
+#ifdef USE_PETSC
     /* PETSc flags */
     int use_petsc;
     int petsc_linear;
     int petsc_nonlinear;
     int petsc_schur;
     float petsc_uzawa_tol;
+#endif
 };
 
 
@@ -752,6 +755,7 @@ struct All_variables {
 #include "viscosity_descriptions.h"
 #include "advection.h"
 
+#ifdef USE_PETSC
     /* PETSc related data structures */
     Mat   K, G, D, DC;
     KSP   ksp;
@@ -760,6 +764,7 @@ struct All_variables {
     Vec   PVec, NPVec, UVec, FVec;
     struct MatMultShell mtx_del2_u, mtx_grad_p, mtx_div_u, mtx_div_rho_u;
     struct MultiGrid_PC pcshell_ctx;
+#endif
 
     FILE *fp;
     FILE *fptime;
diff --git a/lib/petsc_citcoms.h b/lib/petsc_citcoms.h
index a90233b..73ff3ed 100644
--- a/lib/petsc_citcoms.h
+++ b/lib/petsc_citcoms.h
@@ -2,6 +2,8 @@
 #ifndef __CitcomS__PETSc__h__
 #define __CitcomS__PETSc__h__
 
+#ifdef USE_PETSC
+
 #include <petscksp.h>
 
 #ifdef __cplusplus
@@ -29,4 +31,6 @@ PetscErrorCode MatShellMult_div_rho_u( Mat D, Vec U, Vec DU );
 }
 #endif
 
+#endif /* USE_PETSC */
+
 #endif // __CitcomS__PETSc__h__
diff --git a/lib/prototypes.h b/lib/prototypes.h
index c7aeaec..a2006ea 100644
--- a/lib/prototypes.h
+++ b/lib/prototypes.h
@@ -263,15 +263,12 @@ void get_prem(double, double *, double *, double *);
 void compute_seismic_model(struct All_variables *, double *, double *, double *);
 /* Nodal_mesh.c */
 void v_from_vector(struct All_variables *);
-//PetscErrorCode v_from_vector_petsc(struct All_variables *);
 void assign_v_to_vector(struct All_variables *);
 void v_from_vector_pseudo_surf(struct All_variables *);
-//PetscErrorCode v_from_vector_pseudo_surf_petsc(struct All_variables *);
 void velo_from_element(struct All_variables *, float [4][9], int, int, int);
 void velo_from_element_d(struct All_variables *, double [4][9], int, int, int);
 
 void p_to_nodes(struct All_variables *, double **, float **, int);
-//PetscErrorCode p_to_nodes_petsc(struct All_variables *, Vec, Vec, int);
 
 void visc_from_gint_to_nodes(struct All_variables *, float **, float **, int);
 void visc_from_nodes_to_gint(struct All_variables *, float **, float **, int);
@@ -492,7 +489,6 @@ void get_angle_sphere_cap(double [4][5], double [6]);
 double get_angle(double [4], double [4]);
 /* Stokes_flow_Incomp.c */
 void solve_constrained_flow_iterative(struct All_variables *);
-//PetscErrorCode solve_constrained_flow_iterative_petsc(struct All_variables *);
 /* Topo_gravity.c */
 void get_STD_topo(struct All_variables *, float **, float **, float **, float **, int);
 void get_STD_freesurf(struct All_variables *, float **);



More information about the CIG-COMMITS mailing list