aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/LoadBalanceReal/test.F90
blob: ff87fc554b7f507da5e273a883ba242e2024019d (plain)
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
program test

  use carpet_boxtypes
  implicit none

  type(bbox), dimension(100) :: inboxes
  integer, dimension(3,2) :: obound_init =  reshape (source = (/ 1, 1, 1, 1, 1, 1 /), shape = (/ 3, 2 /))
  type(boundary) :: outbound
  integer :: nprocs, i, j, nregs, &
             mode
  type(ptr), dimension(:), allocatable :: sregions
  integer, dimension(:), allocatable :: proc_load
  real(wp) :: totcost, idealcost

  namelist /input/ nregs
  namelist /superregions/ inboxes, nprocs, ghostsize, alpha, limit_size

  open(unit=1,file='boxes.par',status='old',action='read')
  read(1, nml=input)
  close(1)

  open(unit=1,file='boxes.par',status='old',action='read')
  read(1, nml=superregions)
  close(1)

  mode = 2

! In mode 1 the processor decomposition is obtained for all integer values
! from 1 to nprocs and only the processor number and load imbalance is printed.
  if ( mode == 1) then 
    do j = 1, nprocs

      allocate ( sregions(nregs) )
      outbound%obound = obound_init

      do i = 1, nregs
        call create_sregion ( inboxes(i), outbound, i-1, sregions(i)%point )
      end do

      call SplitSuperRegions ( sregions, j )

      allocate ( proc_load(j) )

      proc_load = 0

      call calc_proc_load ( sregions, proc_load )
      totcost = sum ( proc_load )
      idealcost = totcost / j

      do i = 1, nregs
        call destroy_sregion ( sregions(i)%point )
      end do

      print*, j, 100*(maxval(proc_load) - idealcost)/idealcost

      deallocate ( sregions, proc_load )

    end do

! In mode 2 the processor decomposition is done for nprocs only but more datail
! including the full tree information is printed.
  else

    allocate ( sregions(nregs) )
    outbound%obound = obound_init

    do i = 1, nregs
      call create_sregion ( inboxes(i), outbound, i-1, sregions(i)%point )
    end do

    call SplitSuperRegions ( sregions, nprocs )

    do i = 1, nregs
      call print_tree ( sregions(i)%point )
    end do

    allocate ( proc_load(nprocs) )

    proc_load = 0

    call calc_proc_load ( sregions, proc_load )

    print*,'proc_load = ', proc_load 

    totcost = sum ( proc_load )
    print*,'total load = ', totcost

    idealcost = totcost / nprocs
    print*,'ideal load = ', idealcost
    print*,'max load = ', maxval ( proc_load )
    print*,'load_imbalance (%) = ', 100*(maxval(proc_load) - idealcost)/idealcost

    do i = 1, nregs
      call destroy_sregion ( sregions(i)%point )
    end do

    deallocate ( sregions, proc_load )

  end if
  
end program test