lib/io/writer.cc
/**
 ********************************************************************************************************************************************
 * \brief   Function to write restart file in HDF5 format in parallel
 *
 *          It opens the restart file in the output folder and all the processors write in parallel into the file.
 *          Unlike solution writing, the data is not interpolated and is written as is.
 *          The restart file is overwritten with each call to this function.
 *
 * \param   time is a real value containing the time to be added as metadata to the restart file
 ********************************************************************************************************************************************
 */
\brief   Function to write restart file in HDF5 format in parallel
It opens the restart file in the output folder and all the processors write in parallel into the file.
Unlike solution writing, the data is not interpolated and is written as is.
The restart file is overwritten with each call to this function.

\param   time is a real value containing the time to be added as metadata to the restart file
\ brief Function to write restart file in HDF5 format in parallel It opens the restart file in the output folder and all the processors write in parallel into the file . Unlike solution writing the data is not interpolated and is written as is . The restart file is overwritten with each call to this function . \ param time is a real value containing the time to be added as metadata to the restart file
void writer::writeRestart(real time) {
    hid_t plist_id;
    hid_t fileHandle;
    hid_t dataSet;
    herr_t status;
    plist_id = H5Pcreate(H5P_FILE_ACCESS);
    H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);
    fileHandle = H5Fcreate("output/restartFile.h5", H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
    H5Pclose(plist_id);
    hid_t timeDSpace = H5Screate(H5S_SCALAR);
    dataSet = H5Dcreate2(fileHandle, "Time", H5T_NATIVE_REAL, timeDSpace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    status = H5Dwrite(dataSet, H5T_NATIVE_REAL, timeDSpace, timeDSpace, H5P_DEFAULT, &time);
    H5Dclose(dataSet);
    H5Sclose(timeDSpace);
    plist_id = H5Pcreate(H5P_DATASET_XFER);
    H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
    for (unsigned int i=0; i < wFields.size(); i++) {
#ifdef PLANAR
        fieldData.resize(blitz::TinyVector<int, 2>(localSize[i](0), localSize[i](2)));
#else
        fieldData.resize(localSize[i]);
#endif
        copyData(wFields[i]);
        dataSet = H5Dcreate2(fileHandle, wFields[i].fieldName.c_str(), H5T_NATIVE_REAL, targetDSpace[i], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        status = H5Dwrite(dataSet, H5T_NATIVE_REAL, sourceDSpace[i], targetDSpace[i], plist_id, fieldData.dataFirst());
        if (status) {
            if (mesh.rankData.rank == 0) {
                std::cout << "Error in writing output to HDF file. Aborting" << std::endl;
            }
            MPI_Finalize();
            exit(0);
        }
        H5Dclose(dataSet);
    }
    H5Pclose(plist_id);
    H5Fclose(fileHandle);
}
void writer :: writeRestart ( real time ) { hid_t plist_id ; hid_t fileHandle ; hid_t dataSet ; herr_t status ; plist_id = H5Pcreate ( H5P_FILE_ACCESS ) ; H5Pset_fapl_mpio ( plist_id , MPI_COMM_WORLD , MPI_INFO_NULL ) ; fileHandle = H5Fcreate ( " " , H5F_ACC_TRUNC , H5P_DEFAULT , plist_id ) ; H5Pclose ( plist_id ) ; hid_t timeDSpace = H5Screate ( H5S_SCALAR ) ; dataSet = H5Dcreate2 ( fileHandle , " " , H5T_NATIVE_REAL , timeDSpace , H5P_DEFAULT , H5P_DEFAULT , H5P_DEFAULT ) ; status = H5Dwrite ( dataSet , H5T_NATIVE_REAL , timeDSpace , timeDSpace , H5P_DEFAULT , & time ) ; H5Dclose ( dataSet ) ; H5Sclose ( timeDSpace ) ; plist_id = H5Pcreate ( H5P_DATASET_XFER ) ; H5Pset_dxpl_mpio ( plist_id , H5FD_MPIO_COLLECTIVE ) ; for ( unsigned int i = 0 ; i < wFields . size ( ) ; i ++ ) { #ifdef PLANAR fieldData . resize ( blitz :: TinyVector < int , 2 > ( localSize [ i ] ( 0 ) , localSize [ i ] ( 2 ) ) ) ; #else fieldData . resize ( localSize [ i ] ) ; #endif copyData ( wFields [ i ] ) ; dataSet = H5Dcreate2 ( fileHandle , wFields [ i ] . fieldName . c_str ( ) , H5T_NATIVE_REAL , targetDSpace [ i ] , H5P_DEFAULT , H5P_DEFAULT , H5P_DEFAULT ) ; status = H5Dwrite ( dataSet , H5T_NATIVE_REAL , sourceDSpace [ i ] , targetDSpace [ i ] , plist_id , fieldData . dataFirst ( ) ) ; if ( status ) { if ( mesh . rankData . rank == 0 ) { std :: cout << " " << std :: endl ; } MPI_Finalize ( ) ; exit ( 0 ) ; } H5Dclose ( dataSet ) ; } H5Pclose ( plist_id ) ; H5Fclose ( fileHandle ) ; }
\brief   Function to write restart file in HDF5 format in parallel
          It opens the restart file in the output folder and all the processors write in parallel into the file.
\ brief Function to write restart file in HDF5 format in parallel It opens the restart file in the output folder and all the processors write in parallel into the file .
// Create a property list for collectively opening a file by all processors // First create a file handle with the path to the output file // Close the property list for later reuse // Add the scalar value of time to the restart file // Close dataset for future use and dataspace for clearing resources // Create a property list to use collective data write //Write data // Create the dataset *for the file*, linking it to the file handle. // Correspondingly, it will use the *core* dataspace, as only the core has to be written excluding the pads // Write the dataset. Most important thing to note is that the 3rd and 4th arguments represent the *source* and *destination* dataspaces. // The source here is the sourceDSpace pointing to the memory buffer. Note that its view has been adjusted using hyperslab. // The destination is the targetDSpace. Though the targetDSpace is smaller than the sourceDSpace, // only the appropriate hyperslab within the sourceDSpace is transferred to the destination. // Close dataset for reuse // CLOSE/RELEASE RESOURCES