Date: 2021-03-03T22:25:33+00:00

Actual source code: adios2.c
petsc-3.14.5 2021-03-03
Report Typos and Errors

      1: #include <petsc/private/viewerimpl.h>
      2: #include <adios2_c.h>
      3: #include <petsc/private/vieweradios2impl.h>

      5: static PetscErrorCode PetscViewerSetFromOptions_ADIOS2(PetscOptionItems *PetscOptionsObject,PetscViewer v)
      6: {

     10:   PetscOptionsHead(PetscOptionsObject,"ADIOS2 PetscViewer Options");
     11:   PetscOptionsTail();
     12:   return(0);
     13: }

     15: static PetscErrorCode PetscViewerFileClose_ADIOS2(PetscViewer viewer)
     16: {
     17:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*)viewer->data;
     18:   PetscErrorCode     ierr;

     21:   switch (adios2->btype) {
     22:   case FILE_MODE_READ:
     23:     /* adios2_read_close(adios2->adios2_fp); */
     24:     break;
     25:   case FILE_MODE_APPEND:
     26:     break;
     27:   case FILE_MODE_WRITE:
     28:     /* adios2_close(adios2->adios2_handle); */
     29:     break;
     30:   default:
     31:     break;
     32:   }
     33:   PetscFree(adios2->filename);
     34:   return(0);
     35: }

     37: PetscErrorCode PetscViewerDestroy_ADIOS2(PetscViewer viewer)
     38: {
     39:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
     40:   PetscErrorCode     ierr;

     43:   PetscViewerFileClose_ADIOS2(viewer);
     44:   PetscFree(adios2);
     45:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);
     46:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);
     47:   PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);
     48:   return(0);
     49: }

     51: PetscErrorCode  PetscViewerFileSetMode_ADIOS2(PetscViewer viewer, PetscFileMode type)
     52: {
     53:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;

     57:   adios2->btype = type;
     58:   return(0);
     59: }

     61: PetscErrorCode  PetscViewerFileSetName_ADIOS2(PetscViewer viewer, const char name[])
     62: {
     63:   PetscViewer_ADIOS2 *adios2 = (PetscViewer_ADIOS2*) viewer->data;
     64:   PetscErrorCode     ierr;

     67:   PetscFree(adios2->filename);
     68:   PetscStrallocpy(name, &adios2->filename);
     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:   return(0);
     83: }

     85: static PetscErrorCode PetscViewerFileGetName_ADIOS2(PetscViewer viewer,const char **name)
     86: {
     87:   PetscViewer_ADIOS2 *vadios2 = (PetscViewer_ADIOS2*)viewer->data;

     90:   *name = vadios2->filename;
     91:   return(0);
     92: }

     94: /*MC
     95:    PETSCVIEWERADIOS2 - A viewer that writes to an ADIOS2 file

     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()

    103:   Level: beginner
    104: M*/

    106: PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS2(PetscViewer v)
    107: {
    108:   PetscViewer_ADIOS2 *adios2;
    109:   PetscErrorCode     ierr;

    112:   PetscNewLog(v,&adios2);

    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;

    122:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS2);
    123:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS2);
    124:   PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS2);
    125:   return(0);
    126: }

    128: /*@C
    129:    PetscViewerADIOS2Open - Opens a file for ADIOS2 input/output.

    131:    Collective

    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

    141:    Output Parameter:
    142: .  adios2v - PetscViewer for ADIOS2 input/output to use with the specified file

    144:    Level: beginner

    146:    Note:
    147:    This PetscViewer should be destroyed with PetscViewerDestroy().

    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: {

    159:   PetscViewerCreate(comm, adios2v);
    160:   PetscViewerSetType(*adios2v, PETSCVIEWERADIOS2);
    161:   PetscViewerFileSetMode(*adios2v, type);
    162:   PetscViewerFileSetName(*adios2v, name);
    163:   return(0);
    164: }