Advertisement
angel_devicente

phdf5write.f90

Jul 10th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PROGRAM phdf5write
  2.  
  3.   USE MPI
  4.   USE H5LT
  5.   USE timing
  6.  
  7.   IMPLICIT NONE
  8.  
  9.   INTEGER, PARAMETER :: minglobalsize = 100, maxglobalsize = 300, stepsize = 100  ! Size of the whole 3D domain (per side)
  10.                                                                                   ! Will do tests for all sizes from minglobalsize to maxglobalsize
  11.                                                                                   ! in steps of stepsize
  12.  
  13.   INTEGER, PARAMETER :: nblocks = 4                                               ! Number of blocks per dimension. with nblocks = 4 we end up
  14.                                                                                   ! with 64 blocks (4^3), so we will need to run the code with 64 processors
  15.                                                                                   ! !! Make sure that all the possible step are divisible by nblocks !!
  16.  
  17.   INTEGER, PARAMETER :: layersize = 24, nvar = 12                                 ! Variables controlling the size of the PML layer to be written.
  18.                                                                                   ! nvar is always the last dimension in the array datapml
  19.                                                                                   ! layersize is the first dimension for mode = 1, the second for mode = 2
  20.                                                                                   ! and the third for mode = 3
  21.                                                                                   !
  22.                                                                                   ! For example, when layersize=24 and nvar=24 and 3D size is 100, then
  23.                                                                                   ! the dimensions for PMLX will be 24x100x100x24
  24.                                      
  25.  
  26.  
  27. !===========================================================================================
  28.  
  29.  
  30.   DOUBLE PRECISION, DIMENSION(:,:,:,:), ALLOCATABLE  :: datapml
  31.   INTEGER :: error, proc_number, my_rank
  32.  
  33.   INTEGER :: size, mysize, temp,x,y,z,timerx,timery,timerz
  34.  
  35.   CALL timer_create("WRITINGPMLX",timerx)
  36.   CALL timer_create("WRITINGPMLY",timery)
  37.   CALL timer_create("WRITINGPMLZ",timerz)
  38.  
  39.   CALL MPI_INIT ( error )
  40.   CALL MPI_COMM_SIZE ( MPI_COMM_WORLD, proc_number, error )
  41.   CALL MPI_COMM_RANK ( MPI_COMM_WORLD, my_rank, error )
  42.  
  43.   DO size=minglobalsize,maxglobalsize,stepsize
  44.      IF (my_rank .EQ. 0) PRINT*, ""
  45.      IF (my_rank .EQ. 0) PRINT*, "===================", size, "====================="
  46.      IF (my_rank .EQ. 0) PRINT*, ""
  47.  
  48.      
  49.      CALL timer_reset(timerx)
  50.      CALL timer_reset(timery)
  51.      CALL timer_reset(timerz)
  52.      
  53.      mysize = size / nblocks
  54.      ALLOCATE(datapml(mysize,mysize,layersize,nvar))
  55.  
  56.      datapml = my_rank
  57.      CALL timer_start(timerx)
  58.      CALL write_data_pml(1)
  59.      CALL timer_stop(timerx)
  60.  
  61.      CALL timer_start(timery)
  62.      CALL write_data_pml(2)
  63.      CALL timer_stop(timery)
  64.  
  65.      CALL timer_start(timerz)
  66.      CALL write_data_pml(3)
  67.      CALL timer_stop(timerz)
  68.  
  69.      DEALLOCATE(datapml)
  70.  
  71.      IF (my_rank .EQ. 0) CALL timer_report(0)
  72.   END DO
  73.  
  74.   CALL MPI_Finalize (error)
  75.  
  76. CONTAINS
  77.  
  78.     SUBROUTINE write_data_pml(mode)
  79.       INTEGER :: mode
  80.  
  81.       CHARACTER(LEN=11) :: filename
  82.       CHARACTER(LEN=4) :: modetxt
  83.  
  84.       INTEGER(HID_T) :: plist_id                                               ! Property list identifier
  85.       INTEGER(HID_T) :: file_id                                                ! File identifier
  86.       INTEGER(HID_T) :: ddata                                                  ! Dataset identifier
  87.       INTEGER(HID_T) :: filespace                                              ! Dataspace identifier in file
  88.       INTEGER(HID_T) :: memspace                                               ! Dataspace identifier in memory
  89.       INTEGER(HSIZE_T), DIMENSION(4) :: dims,count
  90.       INTEGER(HSIZE_T), DIMENSION(4) :: offset
  91.       INTEGER     :: error  ! Error flag
  92.       INTEGER     :: info
  93.  
  94.       SELECT CASE (mode)
  95.       CASE (1)
  96.          modetxt = "PMLX"
  97.       CASE (2)
  98.          modetxt = "PMLY"
  99.       CASE(3)
  100.          modetxt = "PMLZ"
  101.       END SELECT
  102.  
  103.       IF (my_rank .EQ. 0) PRINT*, "===================", modetxt, "====================="
  104.  
  105.       CALL h5open_f (error)
  106.  
  107.       dims = (/ size, size, layersize,nvar /)
  108.       WRITE(filename,'(a4,i3,a3)'), modetxt, size, '.h5'
  109.            
  110.       ! Setup file access property list with parallel I/O access.
  111.       !==========================================================
  112.       CALL h5pcreate_f(H5P_FILE_ACCESS_F, plist_id, error)
  113.  
  114. !!$      call MPI_Info_create(info, error)
  115. !!$      call MPI_Info_set(info,"IBM_largeblock_io","true", error)
  116.  
  117.       CALL h5pset_fapl_mpio_f(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL, error)
  118.      
  119.       ! Create the file collectively.
  120.       ! =============================
  121.       CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error, access_prp = plist_id)
  122.      
  123.       ! Close propertly list
  124.       ! ====================
  125.       CALL h5pclose_f(plist_id, error)
  126.      
  127.       CALL h5screate_simple_f(4, dims, filespace, error)
  128.       CALL h5dcreate_f(file_id, "datapml",   H5T_NATIVE_DOUBLE, filespace, ddata, error)
  129.       CALL h5sclose_f(filespace, error)
  130.  
  131.  
  132.       ! Each process defines dataset in memory and writes it to the hyperslab in the file.
  133.       ! ==================================================================================
  134.       count = (/ 0,0,0,0 /)
  135.  
  136.       SELECT CASE(mode)
  137.       CASE(1)
  138.          IF (my_rank < nblocks*nblocks)               count = (/ mysize,mysize,layersize,nvar /)   ! X PML
  139.       CASE(2)
  140.          IF (MOD(my_rank,nblocks*nblocks) < nblocks)  count = (/ mysize,mysize,layersize,nvar /)   ! Y PML
  141.       CASE(3)
  142.          IF (MOD(my_rank,nblocks) .EQ. 0)             count = (/ mysize,mysize,layersize,nvar /)   ! Z PML
  143.       END SELECT
  144.  
  145.  
  146.  
  147.       offset = (/ 0,0,0,0 /)
  148.  
  149.       DO temp=0,nblocks*nblocks - 1  
  150.          x = temp / nblocks
  151.          y = MOD(temp,nblocks)
  152.          SELECT CASE(mode)
  153.          CASE(1)
  154.             IF (my_rank .EQ. temp) THEN                                                     ! Like a X PML layer
  155.                offset(1) = x * count(1)
  156.                offset(2) = y * count(2)
  157.                PRINT*, "rank, offs", my_rank, offset(1), offset(2)
  158.             END IF
  159.  
  160.          CASE(2)
  161.             IF (my_rank .EQ. temp/nblocks * (nblocks*nblocks) + MOD(temp,nblocks)) THEN      ! Like a Y PML layer
  162.                offset(1) = x * count(1)
  163.                offset(2) = y * count(2)
  164.                PRINT*, "rank, offs", my_rank, offset(1), offset(2)
  165.             END IF
  166.            
  167.          CASE(3)
  168.             IF (my_rank .EQ. temp * nblocks) THEN                                            ! Like a Z PML layer
  169.                offset(1) = x * count(1)
  170.                offset(2) = y * count(2)
  171.                PRINT*, "rank, offs", my_rank, offset(1), offset(2)
  172.             END IF
  173.          END SELECT
  174.       END DO
  175.  
  176.  
  177.       CALL h5screate_simple_f(4, count, memspace, error)
  178.       !
  179.       ! Select hyperslab in the file.
  180.       !
  181.       CALL h5dget_space_f(ddata, filespace, error)
  182.       CALL h5sselect_hyperslab_f (filespace, H5S_SELECT_SET_F, offset, count, error)
  183.       !
  184.       ! Create property list for collective dataset write
  185.       !
  186.       CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error)
  187.       CALL h5pset_dxpl_mpio_f(plist_id, H5FD_MPIO_COLLECTIVE_F, error)
  188.      
  189.       ! Do the actual writing
  190.       ! =====================
  191.       CALL h5dwrite_f(ddata,H5T_NATIVE_DOUBLE,datapml,dims,error,file_space_id=filespace,&
  192.            mem_space_id = memspace, xfer_prp = plist_id)
  193.      
  194.       ! Close dataspaces.
  195.       ! ================
  196.       CALL h5sclose_f(filespace, error)
  197.       CALL h5sclose_f(memspace, error)
  198.      
  199.       CALL h5dclose_f(ddata, error)      
  200.       CALL h5pclose_f(plist_id, error)
  201.  
  202.       CALL h5fclose_f(file_id, error)
  203.  
  204.     END SUBROUTINE write_data_pml
  205.  
  206.  
  207.   END PROGRAM phdf5write
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement