9
integer i, j, gdim, type
10
integer gdims(NDIM+1), gwidth(NDIM+1)
11
integer pdims(NDIM+1), mcnt, mapc(5000)
12
integer g_fg, g_fld, g_bc, ptr_fg, ptr_fld, ptr_bc
13
integer ld_fg(NDIM+1), ld_fld(NDIM+1), ld_bc(NDIM)
14
integer heap, stack, me, nproc
16
#include "mafdecls.fh"
19
c Initialize a message passing library
25
c Initialize global arrays
32
if (ga_uses_ma()) then
33
heap = (size(1)+2)*(size(2)+2)*34/nproc
39
if (.not.ma_init(MT_DBL, stack, heap))
40
+ call ga_error("ma init failed", -1)
43
c initialize global arrays
52
c evaluate distribution of processors
55
call factor(nproc,gdim,pdims)
59
mapc(mcnt) = ((dble(j)/dble(pdims(i)))*dble(gdims(i)))+1
64
mapc(mcnt) = ((dble(i)/dble(pdims(1)))*dble(NDIM))+1
68
mapc(mcnt) = ((dble(i)/dble(pdims(2)))*dble(NDIM))+1
72
c Create global arrays. Start by creating array for LB distribution
73
c functions. The last dimension runs over the distribution function
74
c indices. The first 9 elements are the actual distribution elements,
75
c the next 9 indices are the equilibrium distribution elements,
76
c and the last 9 elements are temporary storage space used for doing
77
c the streaming updates.
85
if (.not.nga_create_ghosts_irreg(type, gdim, gdims, gwidth,
86
+ "lb_dist", mapc, pdims, g_fg))
87
+ call ga_error("g_fg init failed",me)
89
c Create global array to hold density, momentum, pressure,
90
c and relaxation parameters. These are stored at each point
91
c and indexed by the last indice as density, p_x, p_y,
100
if (.not.nga_create_ghosts_irreg(type, gdim, gdims, gwidth,
101
+ "fields", mapc, pdims, g_fld))
102
+ call ga_error("g_fld init failed",me)
104
c Create global array to hold boundary condition data.
108
if (.not.nga_create_ghosts_irreg(type, gdim, gdims, gwidth,
109
+ "bc_mask", mapc, pdims, g_bc))
110
+ call ga_error("g_bc init failed",me)
112
c Find pointers to global array data
114
call nga_access_ghosts(g_fg,dims_fg,ptr_fg,ld_fg)
115
call nga_access_ghosts(g_fld,dims_fld,ptr_fld,ld_fld)
116
call nga_access_ghosts(g_bc,dims_bc,ptr_bc,ld_bc)
121
c Call routine to run main simulation
123
call boltzmann(g_fg, dbl_mb(ptr_fg), ld_fg(1), ld_fg(2),
124
+ g_fld, dbl_mb(ptr_fld), ld_fld(1), ld_fld(2),
125
+ g_bc, int_mb(ptr_bc), ld_bc(1))
127
c Close out calculation
134
subroutine factor(p,ndim,dims)
136
integer i,j,p,ndim,dims(*),imin,mdim
137
integer ip,ifac,pmax,prime(1000)
146
c factor p completely
147
c first, find all prime numbers less than or equal to p
152
if (mod(i,prime(j)).eq.0) go to 100
159
c find all prime factors of p
163
200 if (mod(ip,prime(i)).eq.0) then
171
c determine dimensions of processor grid
175
c find dimension with minimum value
180
if (dims(j).lt.imin) then
185
dims(mdim) = dims(mdim)*fac(i)