"Fossies" - the Fresh Open Source Software Archive

Member "petsc-3.12.3/src/sys/classes/viewer/impls/adios/adios.c" (29 Sep 2019, 8326 Bytes) of package /linux/misc/petsc-3.12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "adios.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.11.4_vs_3.12.0.

    1 #include <petsc/private/viewerimpl.h>    /*I   "petscsys.h"   I*/
    2 #include <adios.h>
    3 #include <adios_read.h>
    4 
    5 #include <petsc/private/vieweradiosimpl.h>
    6 
    7 static PetscErrorCode PetscViewerSetFromOptions_ADIOS(PetscOptionItems *PetscOptionsObject,PetscViewer v)
    8 {
    9   PetscErrorCode ierr;
   10 
   11   PetscFunctionBegin;
   12   ierr = PetscOptionsHead(PetscOptionsObject,"ADIOS PetscViewer Options");CHKERRQ(ierr);
   13   ierr = PetscOptionsTail();CHKERRQ(ierr);
   14   PetscFunctionReturn(0);
   15 }
   16 
   17 static PetscErrorCode PetscViewerFileClose_ADIOS(PetscViewer viewer)
   18 {
   19   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*)viewer->data;
   20   PetscErrorCode    ierr;
   21 
   22   PetscFunctionBegin;
   23   switch (adios->btype) {
   24   case FILE_MODE_READ:
   25     ierr = adios_read_close(adios->adios_fp);CHKERRQ(ierr);
   26     break;
   27   case FILE_MODE_APPEND:
   28     break;
   29   case FILE_MODE_WRITE:
   30      ierr = adios_close(adios->adios_handle);CHKERRQ(ierr);
   31     break;
   32   default:
   33     break;
   34   }
   35   ierr = PetscFree(adios->filename);CHKERRQ(ierr);
   36   PetscFunctionReturn(0);
   37 }
   38 
   39 PetscErrorCode PetscViewerDestroy_ADIOS(PetscViewer viewer)
   40 {
   41   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data;
   42   PetscErrorCode    ierr;
   43 
   44   PetscFunctionBegin;
   45   ierr = PetscViewerFileClose_ADIOS(viewer);CHKERRQ(ierr);
   46   ierr = PetscFree(adios);CHKERRQ(ierr);
   47   ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);CHKERRQ(ierr);
   48   ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);CHKERRQ(ierr);
   49   ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);CHKERRQ(ierr);
   50   PetscFunctionReturn(0);
   51 }
   52 
   53 PetscErrorCode  PetscViewerFileSetMode_ADIOS(PetscViewer viewer, PetscFileMode type)
   54 {
   55   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data;
   56 
   57   PetscFunctionBegin;
   58   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
   59   adios->btype = type;
   60   PetscFunctionReturn(0);
   61 }
   62 
   63 PetscErrorCode  PetscViewerFileSetName_ADIOS(PetscViewer viewer, const char name[])
   64 {
   65   PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data;
   66   PetscErrorCode    ierr;
   67 
   68   PetscFunctionBegin;
   69   if (adios->filename) {ierr = PetscFree(adios->filename);CHKERRQ(ierr);}
   70   ierr = PetscStrallocpy(name, &adios->filename);CHKERRQ(ierr);
   71   /* Create or open the file collectively */
   72   switch (adios->btype) {
   73   case FILE_MODE_READ:
   74     adios->adios_fp = adios_read_open_file(adios->filename,ADIOS_READ_METHOD_BP,PetscObjectComm((PetscObject)viewer));
   75     break;
   76   case FILE_MODE_APPEND:
   77     break;
   78   case FILE_MODE_WRITE:
   79     adios_open(&adios->adios_handle,"PETSc",adios->filename,"w",PetscObjectComm((PetscObject)viewer));
   80     break;
   81   default:
   82     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER, "Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
   83   }
   84   PetscFunctionReturn(0);
   85 }
   86 
   87 static PetscErrorCode PetscViewerFileGetName_ADIOS(PetscViewer viewer,const char **name)
   88 {
   89   PetscViewer_ADIOS *vadios = (PetscViewer_ADIOS*)viewer->data;
   90 
   91   PetscFunctionBegin;
   92   *name = vadios->filename;
   93   PetscFunctionReturn(0);
   94 }
   95 
   96 /*MC
   97    PETSCVIEWERADIOS - A viewer that writes to an ADIOS file
   98 
   99 
  100 .seealso:  PetscViewerADIOSOpen(), PetscViewerStringSPrintf(), PetscViewerSocketOpen(), PetscViewerDrawOpen(), PETSCVIEWERSOCKET,
  101            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, PETSCVIEWERDRAW, PETSCVIEWERSTRING,
  102            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
  103            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()
  104 
  105   Level: beginner
  106 M*/
  107 
  108 PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS(PetscViewer v)
  109 {
  110   PetscViewer_ADIOS *adios;
  111   PetscErrorCode    ierr;
  112 
  113   PetscFunctionBegin;
  114   ierr = PetscNewLog(v,&adios);CHKERRQ(ierr);
  115 
  116   v->data                = (void*) adios;
  117   v->ops->destroy        = PetscViewerDestroy_ADIOS;
  118   v->ops->setfromoptions = PetscViewerSetFromOptions_ADIOS;
  119   v->ops->flush          = 0;
  120   adios->btype            = (PetscFileMode) -1;
  121   adios->filename         = 0;
  122   adios->timestep         = -1;
  123 
  124   ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS);CHKERRQ(ierr);
  125   ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS);CHKERRQ(ierr);
  126   ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS);CHKERRQ(ierr);
  127   PetscFunctionReturn(0);
  128 }
  129 
  130 /*@C
  131    PetscViewerADIOSOpen - Opens a file for ADIOS input/output.
  132 
  133    Collective
  134 
  135    Input Parameters:
  136 +  comm - MPI communicator
  137 .  name - name of file
  138 -  type - type of file
  139 $    FILE_MODE_WRITE - create new file for binary output
  140 $    FILE_MODE_READ - open existing file for binary input
  141 $    FILE_MODE_APPEND - open existing file for binary output
  142 
  143    Output Parameter:
  144 .  adiosv - PetscViewer for ADIOS input/output to use with the specified file
  145 
  146    Level: beginner
  147 
  148    Note:
  149    This PetscViewer should be destroyed with PetscViewerDestroy().
  150 
  151 
  152 .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerHDF5Open(),
  153           VecView(), MatView(), VecLoad(), PetscViewerSetType(), PetscViewerFileSetMode(), PetscViewerFileSetName()
  154           MatLoad(), PetscFileMode, PetscViewer
  155 @*/
  156 PetscErrorCode  PetscViewerADIOSOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adiosv)
  157 {
  158   PetscErrorCode ierr;
  159 
  160   PetscFunctionBegin;
  161   ierr = PetscViewerCreate(comm, adiosv);CHKERRQ(ierr);
  162   ierr = PetscViewerSetType(*adiosv, PETSCVIEWERADIOS);CHKERRQ(ierr);
  163   ierr = PetscViewerFileSetMode(*adiosv, type);CHKERRQ(ierr);
  164   ierr = PetscViewerFileSetName(*adiosv, name);CHKERRQ(ierr);
  165   PetscFunctionReturn(0);
  166 }
  167 
  168 /*@C
  169   PetscDataTypeToADIOSDataType - Converts the PETSc name of a datatype to its ADIOS name.
  170 
  171   Not collective
  172 
  173   Input Parameter:
  174 . ptype - the PETSc datatype name (for example PETSC_DOUBLE)
  175 
  176   Output Parameter:
  177 . mtype - the MPI datatype (for example MPI_DOUBLE, ...)
  178 
  179   Level: advanced
  180 
  181   Developer Notes: These have not been verified
  182 
  183 .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType()
  184 @*/
  185 PetscErrorCode PetscDataTypeToADIOSDataType(PetscDataType ptype, enum ADIOS_DATATYPES *htype)
  186 {
  187   PetscFunctionBegin;
  188   if (ptype == PETSC_INT)
  189 #if defined(PETSC_USE_64BIT_INDICES)
  190                                        *htype = adios_long;
  191 #else
  192                                        *htype = adios_integer;
  193 #endif
  194   else if (ptype == PETSC_ENUM)        *htype = adios_integer;
  195   else if (ptype == PETSC_DOUBLE)      *htype = adios_double;
  196   else if (ptype == PETSC_LONG)        *htype = adios_long;
  197   else if (ptype == PETSC_SHORT)       *htype = adios_short;
  198   else if (ptype == PETSC_FLOAT)       *htype = adios_real;
  199   else if (ptype == PETSC_CHAR)        *htype = adios_string_array;
  200   else if (ptype == PETSC_STRING)      *htype = adios_string;
  201   else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported PETSc datatype");
  202   PetscFunctionReturn(0);
  203 }
  204 
  205 /*@C
  206   PetscADIOSDataTypeToPetscDataType - Finds the PETSc name of a datatype from its ADIOS name
  207 
  208   Not collective
  209 
  210   Input Parameter:
  211 . htype - the ADIOS datatype (for example H5T_NATIVE_DOUBLE, ...)
  212 
  213   Output Parameter:
  214 . ptype - the PETSc datatype name (for example PETSC_DOUBLE)
  215 
  216   Level: advanced
  217 
  218   Developer Notes: These have not been verified
  219 
  220 .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType()
  221 @*/
  222 PetscErrorCode PetscADIOSDataTypeToPetscDataType(enum ADIOS_DATATYPES htype, PetscDataType *ptype)
  223 {
  224   PetscFunctionBegin;
  225 #if defined(PETSC_USE_64BIT_INDICES)
  226   if      (htype == adios_integer)     *ptype = PETSC_ENUM;
  227   else if (htype == adios_long)        *ptype = PETSC_INT;
  228 #else
  229   if      (htype == adios_integer)     *ptype = PETSC_INT;
  230 #endif
  231   else if (htype == adios_double)      *ptype = PETSC_DOUBLE;
  232   else if (htype == adios_long)        *ptype = PETSC_LONG;
  233   else if (htype == adios_short)       *ptype = PETSC_SHORT;
  234   else if (htype == adios_real)        *ptype = PETSC_FLOAT;
  235   else if (htype == adios_string_array) *ptype = PETSC_CHAR;
  236   else if (htype == adios_string)       *ptype = PETSC_STRING;
  237   else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported ADIOS datatype");
  238   PetscFunctionReturn(0);
  239 }
  240