Commits

Vijay Mahadevan  committed 2e4e7c0

Adding DMSetFromOptions_Moab to unify all options database retrieval from command line. Added appropriate storage fields in data-structures and made sure that they are universally used, consistently. Still need to figure out: how to propagate read options to DM before DMSetFromOptions is called.

  • Participants
  • Parent commits 7c33587

Comments (0)

Files changed (5)

File include/petsc-private/dmmbimpl.h

   ISLocalToGlobalMapping  ltog_map;
   VecScatter              ltog_sendrecv;
 
+  /* store options to customize DMMoab */
+  PetscInt                rw_dbglevel;
+  PetscBool               partition_by_rank;
+  char                    extra_read_options[PETSC_MAX_PATH_LEN];
+  char                    extra_write_options[PETSC_MAX_PATH_LEN];
+  MoabReadMode            read_mode;
+  MoabWriteMode           write_mode;
+
   PetscInt                numFields;
   const char              **fieldNames;
   PetscBool               icreatedinstance;               /* true if DM created moab instance internally, will destroy instance in DMDestroy */

File include/petscdmmoab.h

 #define MBERRV(mbif,rval) do{if(rval != moab::MB_SUCCESS) { std::string emsg; mbif->get_last_error(emsg); SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"MOAB ERROR (%i): %s",(PetscErrorCode)rval,emsg.c_str());} } while(0)
 #define MBERRVM(mbif,msg,rval) do{if(rval != moab::MB_SUCCESS) { std::string emsg; mbif->get_last_error(emsg); SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_LIB,"MOAB ERROR (%i): %s :: %s",(PetscErrorCode)rval,msg,emsg.c_str());} } while(0)
 
-#define MOAB_PARROPTS_READ_PART    "READ_PART"
-#define MOAB_PARROPTS_READ_DELETE  "READ_DELETE"
-#define MOAB_PARROPTS_BCAST_DELETE "BCAST_DELETE"
 
-#define MOAB_PARWOPTS_WRITE_PART "WRITE_PART"
-#define MOAB_PARWOPTS_WRITE_FORMAT "FORMAT"
-
-typedef const char* MoabReadMode;
-typedef const char* MoabWriteMode;
+/* define enums for options to read and write MOAB files in parallel */
+typedef enum {READ_PART,READ_DELETE,BCAST_DELETE} MoabReadMode;
+static const char *const MoabReadModes[] = {"READ_PART","READ_DELETE","BCAST_DELETE","MoabReadMode","",0};
+typedef enum {WRITE_PART,FORMAT} MoabWriteMode;
+static const char *const MoabWriteModes[] = {"WRITE_PART","FORMAT","MoabWriteMode","",0};
 
 PETSC_EXTERN PetscErrorCode DMMoabCreate(MPI_Comm comm, DM *moab);
 PETSC_EXTERN PetscErrorCode DMMoabCreateMoab(MPI_Comm comm, moab::Interface *mbiface, moab::ParallelComm *pcomm, moab::Tag *ltog_tag, moab::Range *range, DM *moab);

File src/dm/impls/moab/dmmbio.cxx

 
 #undef __FUNCT__
 #define __FUNCT__ "DMMoab_GetWriteOptions_Private"
-static PetscErrorCode DMMoab_GetWriteOptions_Private(PetscInt fsetid, PetscInt numproc, PetscInt dim, MoabWriteMode mode, PetscInt dbglevel, const char* extra_opts, const char** write_opts)
+static PetscErrorCode DMMoab_GetWriteOptions_Private(PetscInt fsetid, PetscInt numproc, PetscInt dim, MoabWriteMode mode, PetscInt dbglevel, const char* dm_opts, const char* extra_opts, const char** write_opts)
 {
   std::ostringstream str;
 
 
   // do parallel read unless only one processor
   if (numproc > 1) {
-    str << "PARALLEL=" << mode << ";";
+    str << "PARALLEL=" << MoabWriteModes[mode] << ";";
     if (fsetid>=0) str << "PARALLEL_COMM=" << fsetid << ";";
   }
 
+  if (strlen(dm_opts)) {
+    str << dm_opts << ";";
+  }
+
   if (dbglevel)
     str << "CPUTIME;DEBUG_IO=" << dbglevel << ";";
 
 @*/
 PetscErrorCode DMMoabOutput(DM dm,const char* filename,const char* usrwriteopts)
 {
-  DM_Moab        *dmmoab;
-  PetscInt       dbglevel=0;
-  const char *writeopts;
-
-  PetscErrorCode ierr;
+  DM_Moab         *dmmoab;
+  const char      *writeopts;
+  PetscErrorCode  ierr;
   moab::ErrorCode merr;
 
   PetscFunctionBegin;
   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
   dmmoab = (DM_Moab*)(dm)->data;
 
-  PetscBarrier((PetscObject)dm);
-
-  /* TODO: Use command-line options to control by_rank, verbosity, MoabReadMode and extra options */
-  ierr  = PetscOptionsBegin(PETSC_COMM_WORLD, "", "Options for reading/writing MOAB based meshes from file", "DMMoab");
-  ierr  = PetscOptionsInt("-dmmb_rw_dbg", "The verbosity level for reading and writing MOAB meshes", "dmmbutil.cxx", dbglevel, &dbglevel, NULL);CHKERRQ(ierr);
-  ierr  = PetscOptionsEnd();
-
   /* add mesh loading options specific to the DM */
-  ierr = DMMoab_GetWriteOptions_Private(dmmoab->pcomm->get_id(), dmmoab->pcomm->size(), dmmoab->dim, MOAB_PARWOPTS_WRITE_PART, dbglevel, usrwriteopts, &writeopts);CHKERRQ(ierr);
+  ierr = DMMoab_GetWriteOptions_Private(dmmoab->pcomm->get_id(), dmmoab->pcomm->size(), dmmoab->dim, dmmoab->write_mode,
+                                          dmmoab->rw_dbglevel, dmmoab->extra_write_options, usrwriteopts, &writeopts);CHKERRQ(ierr);
   PetscInfo2(dm, "Writing file %s with options: %s\n",filename,writeopts);
 
   /* output file, using parallel write */

File src/dm/impls/moab/dmmbutil.cxx

 
 #undef __FUNCT__
 #define __FUNCT__ "DMMoab_GetReadOptions_Private"
-PetscErrorCode DMMoab_GetReadOptions_Private(PetscBool by_rank, PetscInt numproc, PetscInt dim, MoabReadMode mode, PetscInt dbglevel, const char* extra_opts, const char** read_opts)
+PetscErrorCode DMMoab_GetReadOptions_Private(PetscBool by_rank, PetscInt numproc, PetscInt dim, MoabReadMode mode, PetscInt dbglevel, const char* dm_opts, const char* extra_opts, const char** read_opts)
 {
   std::ostringstream str;
 
   PetscFunctionBegin;
   /* do parallel read unless using only one processor */
   if (numproc > 1) {
-    str << "PARALLEL=" << mode << ";PARTITION=PARALLEL_PARTITION;PARTITION_DISTRIBUTE;";
+    str << "PARALLEL=" << MoabReadModes[mode] << ";PARTITION=PARALLEL_PARTITION;PARTITION_DISTRIBUTE;";
     str << "PARALLEL_RESOLVE_SHARED_ENTS;PARALLEL_GHOSTS=" << dim << ".0.1;";
     if (by_rank)
       str << "PARTITION_BY_RANK;";
   }
 
+  if (strlen(dm_opts)) {
+    str << dm_opts << ";";
+  }
+
   if (dbglevel) {
     str << "CPUTIME;DEBUG_IO=" << dbglevel << ";";
     if (numproc>1)
 PetscErrorCode DMMoabLoadFromFile(MPI_Comm comm,PetscInt dim,const char* filename, const char* usrreadopts, DM *dm)
 {
   moab::ErrorCode merr;
-  PetscInt        nprocs,dbglevel=0;
-  PetscBool       part_by_rank=PETSC_FALSE;
+  PetscInt        nprocs;
   DM_Moab        *dmmoab;
   moab::Interface *mbiface;
   moab::ParallelComm *pcomm;
   /* create a file set to associate all entities in current mesh */
   merr = dmmoab->mbiface->create_meshset(moab::MESHSET_SET, dmmoab->fileset);MBERR("Creating file set failed", merr);
 
-  /* TODO: Use command-line options to control by_rank, verbosity, MoabReadMode and extra options */
-  ierr  = PetscOptionsBegin(PETSC_COMM_WORLD, "", "Options for reading/writing MOAB based meshes from file", "DMMoab");
-  ierr  = PetscOptionsInt("-dmmb_rw_dbg", "The verbosity level for reading and writing MOAB meshes", "dmmbutil.cxx", dbglevel, &dbglevel, NULL);CHKERRQ(ierr);
-  ierr  = PetscOptionsBool("-dmmb_part_by_rank", "Use partition by rank when reading MOAB meshes from file", "dmmbutil.cxx", part_by_rank, &part_by_rank, NULL);CHKERRQ(ierr);
-  ierr  = PetscOptionsEnd();
-
   /* add mesh loading options specific to the DM */
-  ierr = DMMoab_GetReadOptions_Private(part_by_rank, nprocs, dim, MOAB_PARROPTS_READ_PART, dbglevel, usrreadopts, &readopts);CHKERRQ(ierr);
+  ierr = DMMoab_GetReadOptions_Private(dmmoab->partition_by_rank, nprocs, dim, dmmoab->read_mode,
+                                        dmmoab->rw_dbglevel, dmmoab->extra_read_options, usrreadopts, &readopts);CHKERRQ(ierr);
 
   PetscInfo2(*dm, "Reading file %s with options: %s\n",filename,readopts);
 

File src/dm/impls/moab/dmmoab.cxx

   /* do the remaining initializations for DMMoab */
   dmmoab->bs = 1;
   dmmoab->numFields = 1;
+  dmmoab->rw_dbglevel = 0;
+  dmmoab->partition_by_rank = PETSC_FALSE;
+  dmmoab->extra_read_options[0] = '\0';
+  dmmoab->extra_write_options[0] = '\0';
+  dmmoab->read_mode = READ_PART;
+  dmmoab->write_mode = WRITE_PART;
 
   /* set global ID tag handle */
   if (ltog_tag && *ltog_tag) {
 
 
 #undef __FUNCT__
+#define __FUNCT__ "DMSetFromOptions_Moab"
+PETSC_EXTERN PetscErrorCode DMSetFromOptions_Moab(DM dm)
+{
+  PetscErrorCode ierr;
+  DM_Moab        *dmmoab = (DM_Moab*)dm->data;
+
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
+  ierr = PetscOptionsHead("DMMoab Options");CHKERRQ(ierr);
+  ierr  = PetscOptionsInt("-dm_moab_rw_dbg", "The verbosity level for reading and writing MOAB meshes", "DMView", dmmoab->rw_dbglevel, &dmmoab->rw_dbglevel, NULL);CHKERRQ(ierr);
+  ierr  = PetscOptionsBool("-dm_moab_partiton_by_rank", "Use partition by rank when reading MOAB meshes from file", "DMView", dmmoab->partition_by_rank, &dmmoab->partition_by_rank, NULL);CHKERRQ(ierr);
+  /* TODO: typically, the read options are needed before a DM is completely created and available in which case, the options wont be available ?? */
+  ierr  = PetscOptionsString("-dm_moab_read_opts", "Extra options to enable MOAB reader to load DM from file", "DMView", dmmoab->extra_read_options, dmmoab->extra_read_options, PETSC_MAX_PATH_LEN, NULL);CHKERRQ(ierr);
+  ierr  = PetscOptionsString("-dm_moab_write_opts", "Extra options to enable MOAB writer to serialize DM to file", "DMView", dmmoab->extra_write_options, dmmoab->extra_write_options, PETSC_MAX_PATH_LEN, NULL);CHKERRQ(ierr);
+  ierr  = PetscOptionsEnum("-dm_moab_read_mode", "MOAB parallel read mode", "DMView", MoabReadModes, (PetscEnum)dmmoab->read_mode, (PetscEnum*)&dmmoab->read_mode, NULL);CHKERRQ(ierr);
+  ierr  = PetscOptionsEnum("-dm_moab_write_mode", "MOAB parallel write mode", "DMView", MoabWriteModes, (PetscEnum)dmmoab->write_mode, (PetscEnum*)&dmmoab->write_mode, NULL);CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+
+
+#undef __FUNCT__
 #define __FUNCT__ "DMSetUp_Moab"
 PETSC_EXTERN PetscErrorCode DMSetUp_Moab(DM dm)
 {
   dm->ops->creatematrix             = DMCreateMatrix_Moab;
   dm->ops->setup                    = DMSetUp_Moab;
   dm->ops->destroy                  = DMDestroy_Moab;
+  dm->ops->setfromoptions           = DMSetFromOptions_Moab;
   dm->ops->globaltolocalbegin       = DMGlobalToLocalBegin_Moab;
   dm->ops->globaltolocalend         = DMGlobalToLocalEnd_Moab;
   dm->ops->localtoglobalbegin       = DMLocalToGlobalBegin_Moab;