"Fossies" - the Fresh Open Source Software Archive

Member "petsc-3.12.3/src/sys/classes/viewer/impls/adios2/adios2.c" (29 Sep 2019, 5849 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 "adios2.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 <adios2_c.h>
    3 #include <petsc/private/vieweradios2impl.h>
    4 
    5 static PetscErrorCode PetscViewerSetFromOptions_ADIOS2(PetscOptionItems *PetscOptionsObject,PetscViewer v)
    6 {
    7   PetscErrorCode ierr;
    8 
    9   PetscFunctionBegin;
   10   ierr = PetscOptionsHead(PetscOptionsObject,"ADIOS2 PetscViewer Options");CHKERRQ(ierr);
   11   ierr = PetscOptionsTail();CHKERRQ(ierr);
   12   PetscFunctionReturn(0);
   13 }
   14 
   15 static PetscErrorCode PetscViewerFileClose_ADIOS2(PetscViewer viewer)
   16 {
   17   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*)viewer->data;
   18   PetscErrorCode     ierr;
   19 
   20   PetscFunctionBegin;
   21   switch (adios2->btype) {
   22   case FILE_MODE_READ:
   23     /* ierr = adios2_read_close(adios2->adios2_fp);CHKERRQ(ierr); */
   24     break;
   25   case FILE_MODE_APPEND:
   26     break;
   27   case FILE_MODE_WRITE:
   28     /* ierr = adios2_close(adios2->adios2_handle);CHKERRQ(ierr); */
   29     break;
   30   default:
   31     break;
   32   }
   33   ierr = PetscFree(adios2->filename);CHKERRQ(ierr);
   34   PetscFunctionReturn(0);
   35 }
   36 
   37 PetscErrorCode PetscViewerDestroy_ADIOS2(PetscViewer viewer)
   38 {
   39   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
   40   PetscErrorCode     ierr;
   41 
   42   PetscFunctionBegin;
   43   ierr = PetscViewerFileClose_ADIOS2(viewer);CHKERRQ(ierr);
   44   ierr = PetscFree(adios2);CHKERRQ(ierr);
   45   ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);CHKERRQ(ierr);
   46   ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);CHKERRQ(ierr);
   47   ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);CHKERRQ(ierr);
   48   PetscFunctionReturn(0);
   49 }
   50 
   51 PetscErrorCode  PetscViewerFileSetMode_ADIOS2(PetscViewer viewer, PetscFileMode type)
   52 {
   53   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
   54 
   55   PetscFunctionBegin;
   56   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
   57   adios2->btype = type;
   58   PetscFunctionReturn(0);
   59 }
   60 
   61 PetscErrorCode  PetscViewerFileSetName_ADIOS2(PetscViewer viewer, const char name[])
   62 {
   63   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
   64   PetscErrorCode     ierr;
   65 
   66   PetscFunctionBegin;
   67   ierr = PetscFree(adios2->filename);CHKERRQ(ierr);
   68   ierr = PetscStrallocpy(name, &adios2->filename);CHKERRQ(ierr);
   69   /* Create or open the file collectively */
   70   switch (adios2->btype) {
   71   case FILE_MODE_READ:
   72     /* adios2->adios2_fp = adios2_read_open_file(adios2->filename,ADIOS2_READ_METHOD_BP,PetscObjectComm((PetscObject)viewer)); */
   73     break;
   74   case FILE_MODE_APPEND:
   75     break;
   76   case FILE_MODE_WRITE:
   77     /* adios2_open(&adios2->adios2_handle,"PETSc",adios2->filename,"w",PetscObjectComm((PetscObject)viewer)); */
   78     break;
   79   default:
   80     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER, "Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
   81   }
   82   PetscFunctionReturn(0);
   83 }
   84 
   85 static PetscErrorCode PetscViewerFileGetName_ADIOS2(PetscViewer viewer,const char **name)
   86 {
   87   PetscViewer_ADIOS2 *vadios2 = (PetscViewer_ADIOS2*)viewer->data;
   88 
   89   PetscFunctionBegin;
   90   *name = vadios2->filename;
   91   PetscFunctionReturn(0);
   92 }
   93 
   94 /*MC
   95    PETSCVIEWERADIOS2 - A viewer that writes to an ADIOS2 file
   96 
   97 
   98 .seealso:  PetscViewerADIOS2Open(), PetscViewerStringSPrintf(), PetscViewerSocketOpen(), PetscViewerDrawOpen(), PETSCVIEWERSOCKET,
   99            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, PETSCVIEWERDRAW, PETSCVIEWERSTRING,
  100            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
  101            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()
  102 
  103   Level: beginner
  104 M*/
  105 
  106 PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS2(PetscViewer v)
  107 {
  108   PetscViewer_ADIOS2 *adios2;
  109   PetscErrorCode     ierr;
  110 
  111   PetscFunctionBegin;
  112   ierr = PetscNewLog(v,&adios2);CHKERRQ(ierr);
  113 
  114   v->data                = (void*) adios2;
  115   v->ops->destroy        = PetscViewerDestroy_ADIOS2;
  116   v->ops->setfromoptions = PetscViewerSetFromOptions_ADIOS2;
  117   v->ops->flush          = 0;
  118   adios2->btype            = (PetscFileMode) -1;
  119   adios2->filename         = 0;
  120   adios2->timestep         = -1;
  121 
  122   ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS2);CHKERRQ(ierr);
  123   ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS2);CHKERRQ(ierr);
  124   ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS2);CHKERRQ(ierr);
  125   PetscFunctionReturn(0);
  126 }
  127 
  128 /*@C
  129    PetscViewerADIOS2Open - Opens a file for ADIOS2 input/output.
  130 
  131    Collective
  132 
  133    Input Parameters:
  134 +  comm - MPI communicator
  135 .  name - name of file
  136 -  type - type of file
  137 $    FILE_MODE_WRITE - create new file for binary output
  138 $    FILE_MODE_READ - open existing file for binary input
  139 $    FILE_MODE_APPEND - open existing file for binary output
  140 
  141    Output Parameter:
  142 .  adios2v - PetscViewer for ADIOS2 input/output to use with the specified file
  143 
  144    Level: beginner
  145 
  146    Note:
  147    This PetscViewer should be destroyed with PetscViewerDestroy().
  148 
  149 
  150 .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerHDF5Open(),
  151           VecView(), MatView(), VecLoad(), PetscViewerSetType(), PetscViewerFileSetMode(), PetscViewerFileSetName()
  152           MatLoad(), PetscFileMode, PetscViewer
  153 @*/
  154 PetscErrorCode  PetscViewerADIOS2Open(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adios2v)
  155 {
  156   PetscErrorCode ierr;
  157 
  158   PetscFunctionBegin;
  159   ierr = PetscViewerCreate(comm, adios2v);CHKERRQ(ierr);
  160   ierr = PetscViewerSetType(*adios2v, PETSCVIEWERADIOS2);CHKERRQ(ierr);
  161   ierr = PetscViewerFileSetMode(*adios2v, type);CHKERRQ(ierr);
  162   ierr = PetscViewerFileSetName(*adios2v, name);CHKERRQ(ierr);
  163   PetscFunctionReturn(0);
  164 }