14c02969dSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/ 24c02969dSBarry Smith #include <adios.h> 34c02969dSBarry Smith 4*a56f64adSBarry Smith int64_t Petsc_adios_group; 5*a56f64adSBarry Smith 64c02969dSBarry Smith typedef struct GroupList { 74c02969dSBarry Smith const char *name; 84c02969dSBarry Smith struct GroupList *next; 94c02969dSBarry Smith } GroupList; 104c02969dSBarry Smith 114c02969dSBarry Smith typedef struct { 124c02969dSBarry Smith char *filename; 134c02969dSBarry Smith PetscFileMode btype; 144c02969dSBarry Smith PetscInt timestep; 154c02969dSBarry Smith GroupList *groups; 16*a56f64adSBarry Smith int64_t adios_handle; 174c02969dSBarry Smith } PetscViewer_ADIOS; 184c02969dSBarry Smith 194c02969dSBarry Smith static PetscErrorCode PetscViewerSetFromOptions_ADIOS(PetscOptionItems *PetscOptionsObject,PetscViewer v) 204c02969dSBarry Smith { 214c02969dSBarry Smith PetscErrorCode ierr; 224c02969dSBarry Smith 234c02969dSBarry Smith PetscFunctionBegin; 244c02969dSBarry Smith ierr = PetscOptionsHead(PetscOptionsObject,"ADIOS PetscViewer Options");CHKERRQ(ierr); 254c02969dSBarry Smith ierr = PetscOptionsTail();CHKERRQ(ierr); 264c02969dSBarry Smith PetscFunctionReturn(0); 274c02969dSBarry Smith } 284c02969dSBarry Smith 294c02969dSBarry Smith static PetscErrorCode PetscViewerFileClose_ADIOS(PetscViewer viewer) 304c02969dSBarry Smith { 314c02969dSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*)viewer->data; 324c02969dSBarry Smith PetscErrorCode ierr; 334c02969dSBarry Smith 344c02969dSBarry Smith PetscFunctionBegin; 354c02969dSBarry Smith ierr = PetscFree(adios->filename);CHKERRQ(ierr); 364c02969dSBarry Smith PetscFunctionReturn(0); 374c02969dSBarry Smith } 384c02969dSBarry Smith 394c02969dSBarry Smith PetscErrorCode PetscViewerDestroy_ADIOS(PetscViewer viewer) 404c02969dSBarry Smith { 414c02969dSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data; 424c02969dSBarry Smith PetscErrorCode ierr; 434c02969dSBarry Smith 444c02969dSBarry Smith PetscFunctionBegin; 454c02969dSBarry Smith ierr = PetscViewerFileClose_ADIOS(viewer);CHKERRQ(ierr); 464c02969dSBarry Smith while (adios->groups) { 474c02969dSBarry Smith GroupList *tmp = adios->groups->next; 484c02969dSBarry Smith 494c02969dSBarry Smith ierr = PetscFree(adios->groups->name);CHKERRQ(ierr); 504c02969dSBarry Smith ierr = PetscFree(adios->groups);CHKERRQ(ierr); 514c02969dSBarry Smith adios->groups = tmp; 524c02969dSBarry Smith } 534c02969dSBarry Smith ierr = PetscFree(adios);CHKERRQ(ierr); 544c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",NULL);CHKERRQ(ierr); 554c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileGetName_C",NULL);CHKERRQ(ierr); 564c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",NULL);CHKERRQ(ierr); 574c02969dSBarry Smith PetscFunctionReturn(0); 584c02969dSBarry Smith } 594c02969dSBarry Smith 604c02969dSBarry Smith PetscErrorCode PetscViewerFileSetMode_ADIOS(PetscViewer viewer, PetscFileMode type) 614c02969dSBarry Smith { 624c02969dSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data; 634c02969dSBarry Smith 644c02969dSBarry Smith PetscFunctionBegin; 654c02969dSBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 664c02969dSBarry Smith adios->btype = type; 674c02969dSBarry Smith PetscFunctionReturn(0); 684c02969dSBarry Smith } 694c02969dSBarry Smith 704c02969dSBarry Smith PetscErrorCode PetscViewerFileSetName_ADIOS(PetscViewer viewer, const char name[]) 714c02969dSBarry Smith { 72*a56f64adSBarry Smith PetscViewer_ADIOS *adios = (PetscViewer_ADIOS*) viewer->data; 73*a56f64adSBarry Smith PetscErrorCode ierr; 74*a56f64adSBarry Smith 754c02969dSBarry Smith PetscFunctionBegin; 76*a56f64adSBarry Smith if (adios->filename) {ierr = PetscFree(adios->filename);CHKERRQ(ierr);} 77*a56f64adSBarry Smith ierr = PetscStrallocpy(name, &adios->filename);CHKERRQ(ierr); 78*a56f64adSBarry Smith /* Create or open the file collectively */ 79*a56f64adSBarry Smith switch (adios->btype) { 80*a56f64adSBarry Smith adios_open(&adios->adios_handle,"PETSc",adios->filename,"r",PetscObjectComm((PetscObject)viewer)); 81*a56f64adSBarry Smith case FILE_MODE_READ: 82*a56f64adSBarry Smith break; 83*a56f64adSBarry Smith case FILE_MODE_APPEND: 84*a56f64adSBarry Smith break; 85*a56f64adSBarry Smith case FILE_MODE_WRITE: 86*a56f64adSBarry Smith adios_open(&adios->adios_handle,"PETSc",adios->filename,"w",PetscObjectComm((PetscObject)viewer)); 87*a56f64adSBarry Smith break; 88*a56f64adSBarry Smith default: 89*a56f64adSBarry Smith SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER, "Must call PetscViewerFileSetMode() before PetscViewerFileSetName()"); 90*a56f64adSBarry Smith } 914c02969dSBarry Smith PetscFunctionReturn(0); 924c02969dSBarry Smith } 934c02969dSBarry Smith 944c02969dSBarry Smith static PetscErrorCode PetscViewerFileGetName_ADIOS(PetscViewer viewer,const char **name) 954c02969dSBarry Smith { 964c02969dSBarry Smith PetscViewer_ADIOS *vadios = (PetscViewer_ADIOS*)viewer->data; 974c02969dSBarry Smith 984c02969dSBarry Smith PetscFunctionBegin; 994c02969dSBarry Smith *name = vadios->filename; 1004c02969dSBarry Smith PetscFunctionReturn(0); 1014c02969dSBarry Smith } 1024c02969dSBarry Smith 1034c02969dSBarry Smith /*MC 1044c02969dSBarry Smith PETSCVIEWERADIOS - A viewer that writes to an ADIOS file 1054c02969dSBarry Smith 1064c02969dSBarry Smith 1074c02969dSBarry Smith .seealso: PetscViewerADIOSOpen(), PetscViewerStringSPrintf(), PetscViewerSocketOpen(), PetscViewerDrawOpen(), PETSCVIEWERSOCKET, 1084c02969dSBarry Smith PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, PETSCVIEWERDRAW, PETSCVIEWERSTRING, 1094c02969dSBarry Smith PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB, 1104c02969dSBarry Smith PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType() 1114c02969dSBarry Smith 1124c02969dSBarry Smith Level: beginner 1134c02969dSBarry Smith M*/ 1144c02969dSBarry Smith 1154c02969dSBarry Smith PETSC_EXTERN PetscErrorCode PetscViewerCreate_ADIOS(PetscViewer v) 1164c02969dSBarry Smith { 1174c02969dSBarry Smith PetscViewer_ADIOS *adios; 1184c02969dSBarry Smith PetscErrorCode ierr; 1194c02969dSBarry Smith 1204c02969dSBarry Smith PetscFunctionBegin; 1214c02969dSBarry Smith ierr = PetscNewLog(v,&adios);CHKERRQ(ierr); 1224c02969dSBarry Smith 1234c02969dSBarry Smith v->data = (void*) adios; 1244c02969dSBarry Smith v->ops->destroy = PetscViewerDestroy_ADIOS; 1254c02969dSBarry Smith v->ops->setfromoptions = PetscViewerSetFromOptions_ADIOS; 1264c02969dSBarry Smith v->ops->flush = 0; 1274c02969dSBarry Smith adios->btype = (PetscFileMode) -1; 1284c02969dSBarry Smith adios->filename = 0; 1294c02969dSBarry Smith adios->timestep = -1; 1304c02969dSBarry Smith adios->groups = NULL; 1314c02969dSBarry Smith 1324c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetName_C",PetscViewerFileSetName_ADIOS);CHKERRQ(ierr); 1334c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileGetName_C",PetscViewerFileGetName_ADIOS);CHKERRQ(ierr); 1344c02969dSBarry Smith ierr = PetscObjectComposeFunction((PetscObject)v,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_ADIOS);CHKERRQ(ierr); 1354c02969dSBarry Smith PetscFunctionReturn(0); 1364c02969dSBarry Smith } 1374c02969dSBarry Smith 1384c02969dSBarry Smith /*@C 1394c02969dSBarry Smith PetscViewerADIOSOpen - Opens a file for ADIOS input/output. 1404c02969dSBarry Smith 1414c02969dSBarry Smith Collective on MPI_Comm 1424c02969dSBarry Smith 1434c02969dSBarry Smith Input Parameters: 1444c02969dSBarry Smith + comm - MPI communicator 1454c02969dSBarry Smith . name - name of file 1464c02969dSBarry Smith - type - type of file 1474c02969dSBarry Smith $ FILE_MODE_WRITE - create new file for binary output 1484c02969dSBarry Smith $ FILE_MODE_READ - open existing file for binary input 1494c02969dSBarry Smith $ FILE_MODE_APPEND - open existing file for binary output 1504c02969dSBarry Smith 1514c02969dSBarry Smith Output Parameter: 1524c02969dSBarry Smith . adiosv - PetscViewer for ADIOS input/output to use with the specified file 1534c02969dSBarry Smith 1544c02969dSBarry Smith Level: beginner 1554c02969dSBarry Smith 1564c02969dSBarry Smith Note: 1574c02969dSBarry Smith This PetscViewer should be destroyed with PetscViewerDestroy(). 1584c02969dSBarry Smith 1594c02969dSBarry Smith Concepts: ADIOS files 1604c02969dSBarry Smith Concepts: PetscViewerADIOS^creating 1614c02969dSBarry Smith 162*a56f64adSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PetscViewerHDF5Open(), 163*a56f64adSBarry Smith VecView(), MatView(), VecLoad(), PetscViewerSetType(), PetscViewerFileSetMode(), PetscViewerFileSetName() 1644c02969dSBarry Smith MatLoad(), PetscFileMode, PetscViewer 1654c02969dSBarry Smith @*/ 1664c02969dSBarry Smith PetscErrorCode PetscViewerADIOSOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *adiosv) 1674c02969dSBarry Smith { 1684c02969dSBarry Smith PetscErrorCode ierr; 1694c02969dSBarry Smith 1704c02969dSBarry Smith PetscFunctionBegin; 1714c02969dSBarry Smith ierr = PetscViewerCreate(comm, adiosv);CHKERRQ(ierr); 1724c02969dSBarry Smith ierr = PetscViewerSetType(*adiosv, PETSCVIEWERADIOS);CHKERRQ(ierr); 1734c02969dSBarry Smith ierr = PetscViewerFileSetMode(*adiosv, type);CHKERRQ(ierr); 1744c02969dSBarry Smith ierr = PetscViewerFileSetName(*adiosv, name);CHKERRQ(ierr); 1754c02969dSBarry Smith PetscFunctionReturn(0); 1764c02969dSBarry Smith } 1774c02969dSBarry Smith 1784c02969dSBarry Smith /*@C 1794c02969dSBarry Smith PetscDataTypeToADIOSDataType - Converts the PETSc name of a datatype to its ADIOS name. 1804c02969dSBarry Smith 1814c02969dSBarry Smith Not collective 1824c02969dSBarry Smith 1834c02969dSBarry Smith Input Parameter: 1844c02969dSBarry Smith . ptype - the PETSc datatype name (for example PETSC_DOUBLE) 1854c02969dSBarry Smith 1864c02969dSBarry Smith Output Parameter: 1874c02969dSBarry Smith . mtype - the MPI datatype (for example MPI_DOUBLE, ...) 1884c02969dSBarry Smith 1894c02969dSBarry Smith Level: advanced 1904c02969dSBarry Smith 1914c02969dSBarry Smith Developer Notes: These have not been verified 1924c02969dSBarry Smith 1934c02969dSBarry Smith .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType() 1944c02969dSBarry Smith @*/ 1954c02969dSBarry Smith PetscErrorCode PetscDataTypeToADIOSDataType(PetscDataType ptype, enum ADIOS_DATATYPES *htype) 1964c02969dSBarry Smith { 1974c02969dSBarry Smith PetscFunctionBegin; 1984c02969dSBarry Smith if (ptype == PETSC_INT) 1994c02969dSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 2004c02969dSBarry Smith *htype = adios_long; 2014c02969dSBarry Smith #else 2024c02969dSBarry Smith *htype = adios_integer; 2034c02969dSBarry Smith #endif 2044c02969dSBarry Smith else if (ptype == PETSC_ENUM) *htype = adios_integer; 2054c02969dSBarry Smith else if (ptype == PETSC_DOUBLE) *htype = adios_double; 2064c02969dSBarry Smith else if (ptype == PETSC_LONG) *htype = adios_long; 2074c02969dSBarry Smith else if (ptype == PETSC_SHORT) *htype = adios_short; 2084c02969dSBarry Smith else if (ptype == PETSC_FLOAT) *htype = adios_real; 2094c02969dSBarry Smith else if (ptype == PETSC_CHAR) *htype = adios_string_array; 2104c02969dSBarry Smith else if (ptype == PETSC_STRING) *htype = adios_string; 2114c02969dSBarry Smith else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported PETSc datatype"); 2124c02969dSBarry Smith PetscFunctionReturn(0); 2134c02969dSBarry Smith } 2144c02969dSBarry Smith 2154c02969dSBarry Smith /*@C 2164c02969dSBarry Smith PetscADIOSDataTypeToPetscDataType - Finds the PETSc name of a datatype from its ADIOS name 2174c02969dSBarry Smith 2184c02969dSBarry Smith Not collective 2194c02969dSBarry Smith 2204c02969dSBarry Smith Input Parameter: 2214c02969dSBarry Smith . htype - the ADIOS datatype (for example H5T_NATIVE_DOUBLE, ...) 2224c02969dSBarry Smith 2234c02969dSBarry Smith Output Parameter: 2244c02969dSBarry Smith . ptype - the PETSc datatype name (for example PETSC_DOUBLE) 2254c02969dSBarry Smith 2264c02969dSBarry Smith Level: advanced 2274c02969dSBarry Smith 2284c02969dSBarry Smith Developer Notes: These have not been verified 2294c02969dSBarry Smith 2304c02969dSBarry Smith .seealso: PetscDataType, PetscADIOSDataTypeToPetscDataType() 2314c02969dSBarry Smith @*/ 2324c02969dSBarry Smith PetscErrorCode PetscADIOSDataTypeToPetscDataType(enum ADIOS_DATATYPES htype, PetscDataType *ptype) 2334c02969dSBarry Smith { 2344c02969dSBarry Smith PetscFunctionBegin; 2354c02969dSBarry Smith #if defined(PETSC_USE_64BIT_INDICES) 2364c02969dSBarry Smith if (htype == adios_integer) *ptype = PETSC_ENUM; 2374c02969dSBarry Smith else if (htype == adios_long) *ptype = PETSC_INT; 2384c02969dSBarry Smith #else 2394c02969dSBarry Smith if (htype == adios_integer) *ptype = PETSC_INT; 2404c02969dSBarry Smith #endif 2414c02969dSBarry Smith else if (htype == adios_double) *ptype = PETSC_DOUBLE; 2424c02969dSBarry Smith else if (htype == adios_long) *ptype = PETSC_LONG; 2434c02969dSBarry Smith else if (htype == adios_short) *ptype = PETSC_SHORT; 2444c02969dSBarry Smith else if (htype == adios_real) *ptype = PETSC_FLOAT; 2454c02969dSBarry Smith else if (htype == adios_string_array) *ptype = PETSC_CHAR; 2464c02969dSBarry Smith else if (htype == adios_string) *ptype = PETSC_STRING; 2474c02969dSBarry Smith else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported ADIOS datatype"); 2484c02969dSBarry Smith PetscFunctionReturn(0); 2494c02969dSBarry Smith } 250*a56f64adSBarry Smith 251