File: posix_method.F90

package info (click to toggle)
adios 1.13.1-31
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,692 kB
  • sloc: ansic: 133,236; f90: 8,791; sh: 7,779; python: 7,648; xml: 3,793; makefile: 2,996; cpp: 2,340; java: 626; sed: 16; perl: 8
file content (106 lines) | stat: -rw-r--r-- 3,592 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
!  
!  ADIOS is freely available under the terms of the BSD license described
!  in the COPYING file in the top level directory of this source distribution.
!
!  Copyright (c) 2008 - 2009.  UT-BATTELLE, LLC. All rights reserved.
!

!/*************************************************************/
!/*      Test of writing of simple arrays in ADIOS with POSIX method         */
!/*                                                           */
!/*     Similar example is examples/Fortran/arrays/arrays_write.c     */
!/*************************************************************/
program posix_method
    use adios_write_mod
    implicit none
    include 'mpif.h'

    character(len=30)   :: filename = "posix_method.bp"
    integer             :: i, j, ierr
    integer             :: rank, size, comm

    ! ADIOS variables declarations for matching gwrite_temperature.fh 
    integer                 :: adios_err
    integer*8               :: adios_groupsize, adios_totalsize
    integer*8               :: adios_handle, adios_buf_size

    ! variables to write out 
    integer, parameter      :: NX = 10, NY = 100
    integer                 :: NXin, NYin
    real*8                  :: t(NX,NY), tin(NX,NY)
    integer                 :: p(NX), pin(NX)

    call MPI_Init (ierr)
    call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
    call MPI_Comm_rank (comm, rank, ierr)
    call MPI_Comm_size (comm, size, ierr)

    do j = 1,NY 
        do i = 1,NX
            t(i,j) = rank*NX*NY + (j-1)*NX + i-1
        enddo     
    enddo

    do i = 1,NX
        p(i) = rank*NX + i
    enddo

    call adios_init ("posix_method.xml", comm, adios_err);


    ! Write data out
    call adios_open (adios_handle, "posix_method", filename, "w", comm, adios_err);
#include "gwrite_posix_method.fh"
    call adios_close (adios_handle, adios_err)


    ! Read data in
    call adios_open (adios_handle, "posix_method", filename, "r", comm, adios_err);

    ! First read in the scalars to calculate the size of the arrays
    adios_buf_size = 4
    call adios_read (adios_handle, "NX", NXin, adios_buf_size, adios_err)
    adios_buf_size = 4
    call adios_read (adios_handle, "NY", NYin, adios_buf_size, adios_err)
    call adios_close (adios_handle, adios_err)

    if (NX /= NXin) then
        write (0, '("Error: NX=",i0," read from file != NX=",i0," written to file.")') NXin, NX
        call exit(1)
    endif
    if (NY /= NYin) then
        write (0, '("Error: NY=",i0," read from file != NY=",i0," written to file.")') NYin, NY
        call exit(1)
    endif

    ! Read the arrays
    call adios_open (adios_handle, "posix_method", filename, "r", comm, adios_err);
    call adios_group_size (adios_handle, adios_groupsize, adios_totalsize, adios_err)
    adios_buf_size = 8 * (NX) * (NY)
    call adios_read (adios_handle, "var_double_2Darray", tin, adios_buf_size, adios_err)
    adios_buf_size = 4 * (NX)
    call adios_read (adios_handle, "var_int_1Darray", pin, adios_buf_size, adios_err)
    call adios_close (adios_handle, adios_err)

    
    ! Check input against output
    do i = 1,NX
        if (p(i)-pin(i) .ge. 0.000001) then
            write (0,'("Error: p read from file != p written to file.")')
            call exit(1)
        endif
    enddo
    do j = 1,NY 
        do i = 1,NX
            if (t(i,j)-tin(i,j) .ge. 0.000001 ) then
                write (0,'("Error: t read from file != t written to file.")')
                call exit(1)
            endif
        enddo     
    enddo

    call adios_finalize (0, adios_err);
    call MPI_Finalize (ierr);

end program