Skip to content

Commit 8f8f08f

Browse files
authored
Merge pull request #50 from wkliao/start_count
use starts and counts only in varn APIs
2 parents b21b7d4 + ad454c5 commit 8f8f08f

File tree

10 files changed

+134
-133
lines changed

10 files changed

+134
-133
lines changed

examples/collective_write.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ def pnetcdf_io(filename, file_format, length):
6060
print("Number of variables = ", NUM_VARS)
6161
print("Number of dimensions = ", NDIMS)
6262

63-
starts = np.zeros(NDIMS, dtype=np.int32)
64-
counts = np.zeros(NDIMS, dtype=np.int32)
63+
start = np.zeros(NDIMS, dtype=np.int32)
64+
count = np.zeros(NDIMS, dtype=np.int32)
6565
gsizes = np.zeros(NDIMS, dtype=np.int32)
6666
buf = []
6767

6868
# calculate local subarray access pattern
6969
psizes = MPI.Compute_dims(nprocs, NDIMS)
70-
starts[0] = rank % psizes[0]
71-
starts[1] = (rank // psizes[1]) % psizes[1]
72-
starts[2] = (rank // (psizes[0] * psizes[1])) % psizes[2]
70+
start[0] = rank % psizes[0]
71+
start[1] = (rank // psizes[1]) % psizes[1]
72+
start[2] = (rank // (psizes[0] * psizes[1])) % psizes[2]
7373

7474
bufsize = 1
7575
for i in range(NDIMS):
7676
gsizes[i] = length * psizes[i]
77-
starts[i] *= length
78-
counts[i] = length
77+
start[i] *= length
78+
count[i] = length
7979
bufsize *= length
8080

8181
# Allocate buffer and initialize with non-zero numbers
@@ -111,7 +111,7 @@ def pnetcdf_io(filename, file_format, length):
111111

112112
# Collectively write one variable at a time
113113
for i in range(NUM_VARS):
114-
vars[i].put_var_all(buf[i], start = starts, count = counts)
114+
vars[i].put_var_all(buf[i], start = start, count = count)
115115

116116
# Close the file
117117
f.close()

examples/fill_mode.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,34 +107,34 @@ def pnetcdf_io(filename):
107107
f.enddef()
108108

109109
# set subarray access pattern
110-
starts = np.array([0, NX * rank])
111-
counts = np.array([NY, NX])
110+
start = np.array([0, NX * rank])
111+
count = np.array([NY, NX])
112112

113113
# allocate user buffer
114114
buf = np.array([[rank] * NX] * NY).astype('i4')
115115

116116
# do not write the variable in full
117-
counts[1] -= 1
118-
fix_var.put_var_all(buf, start = starts, count = counts)
117+
count[1] -= 1
118+
fix_var.put_var_all(buf, start = start, count = count)
119119

120120
# check fill value
121121
no_fill, fill_value = fix_var.inq_fill()
122122
assert(no_fill == 0)
123123
assert(fill_value == pnetcdf.NC_FILL_INT)
124124

125125
# fill the 1st record of the record variable
126-
counts[0] = 1
127-
rec_var.fill_rec(starts[0])
126+
count[0] = 1
127+
rec_var.fill_rec(start[0])
128128

129129
# write to the 1st record
130-
rec_var.put_var_all(buf, start = starts, count = counts)
130+
rec_var.put_var_all(buf, start = start, count = count)
131131

132132
# fill the 2nd record of the record variable
133-
starts[0] = 1
134-
rec_var.fill_rec(starts[0])
133+
start[0] = 1
134+
rec_var.fill_rec(start[0])
135135

136136
# write to the 2nd record
137-
rec_var.put_var_all(buf, start = starts, count = counts)
137+
rec_var.put_var_all(buf, start = start, count = count)
138138

139139
# close file
140140
f.close()

examples/flexible_api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ def pnetcdf_io(filename, file_format):
122122
# create an MPI derived datatype to exclude ghost cells
123123
array_of_sizes = np.array([NZ + 2 * ghost_len, NY + 2 * ghost_len])
124124
array_of_subsizes = np.array([NZ, NY])
125-
array_of_starts = np.array([ghost_len, ghost_len])
125+
array_of_start = np.array([ghost_len, ghost_len])
126126

127127
subarray = MPI.INT.Create_subarray(array_of_sizes, \
128128
array_of_subsizes, \
129-
array_of_starts, \
129+
array_of_start, \
130130
order=MPI.ORDER_C)
131131
subarray.Commit()
132132

@@ -135,12 +135,12 @@ def pnetcdf_io(filename, file_format):
135135
buf_zy = np.full(buffer_len, rank, dtype=np.int32)
136136

137137
# set the subarray access pattern
138-
starts = np.array([NZ * rank, 0])
139-
counts = np.array([NZ, NY])
138+
start = np.array([NZ * rank, 0])
139+
count = np.array([NZ, NY])
140140

141141
# calling a blocking flexible API using put_var_all()
142-
var_zy.put_var_all(buf_zy, start = starts, \
143-
count = counts, \
142+
var_zy.put_var_all(buf_zy, start = start, \
143+
count = count, \
144144
bufcount = 1, \
145145
buftype = subarray)
146146

@@ -153,8 +153,8 @@ def pnetcdf_io(filename, file_format):
153153
buf_zy.fill(-1)
154154

155155
# read using flexible API
156-
var_zy.get_var_all(buf_zy, start = starts,
157-
count = counts,
156+
var_zy.get_var_all(buf_zy, start = start,
157+
count = count,
158158
bufcount = 1,
159159
buftype = subarray)
160160

@@ -177,22 +177,22 @@ def pnetcdf_io(filename, file_format):
177177
# var_yx is partitioned along X dimension
178178
array_of_sizes = np.array([NY + 2 * ghost_len, NX + 2 * ghost_len])
179179
array_of_subsizes = np.array([NY, NX])
180-
array_of_starts = np.array([ghost_len, ghost_len])
180+
array_of_start = np.array([ghost_len, ghost_len])
181181
subarray = MPI.DOUBLE.Create_subarray(array_of_sizes,
182182
array_of_subsizes,
183-
array_of_starts,
183+
array_of_start,
184184
order=MPI.ORDER_C)
185185
subarray.Commit()
186186

187187
# initialize write user buffer
188188
buffer_len = (NY + 2 * ghost_len) * (NX + 2 * ghost_len)
189189
buf_yx = np.full(buffer_len, rank, dtype=np.float64)
190-
starts = np.array([0, NX * rank])
191-
counts = np.array([NY, NX])
190+
start = np.array([0, NX * rank])
191+
count = np.array([NY, NX])
192192

193193
# calling a blocking flexible write API
194-
req_id = var_yx.iput_var(buf_yx, start = starts,
195-
count = counts,
194+
req_id = var_yx.iput_var(buf_yx, start = start,
195+
count = count,
196196
bufcount = 1,
197197
buftype = subarray)
198198

@@ -208,8 +208,8 @@ def pnetcdf_io(filename, file_format):
208208
buf_yx.fill(-1)
209209

210210
# calling a blocking flexible read API
211-
req_id = var_yx.iget_var(buf_yx, start = starts,
212-
count = counts,
211+
req_id = var_yx.iget_var(buf_yx, start = start,
212+
count = count,
213213
bufcount = 1,
214214
buftype=subarray)
215215

examples/get_vara.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def pnetcdf_io(filename, file_format):
101101
# set access pattern for reading subarray
102102
local_ny = global_ny
103103
local_nx = global_nx // nprocs
104-
starts = [0, local_nx * rank]
105-
counts = [local_ny, local_nx]
104+
start = [0, local_nx * rank]
105+
count = [local_ny, local_nx]
106106

107107
# Read a subarray in collective mode
108-
r_buf = np.empty(tuple(counts), v.dtype)
109-
v.get_var_all(r_buf, start = starts, count = counts)
108+
r_buf = np.empty(tuple(count), v.dtype)
109+
v.get_var_all(r_buf, start = start, count = count)
110110

111111
# close the file
112112
f.close()

examples/ghost_cell.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def parse_help():
8383

8484
def pnetcdf_io(filename, file_format, length):
8585

86-
counts = [length, length + 1]
86+
count = [length, length + 1]
8787
psizes = MPI.Compute_dims(nprocs, 2)
8888

8989
if verbose and rank == 0:
@@ -104,24 +104,24 @@ def pnetcdf_io(filename, file_format, length):
104104
print("rank {}: dim rank= {} {}".format(rank, local_rank[0], local_rank[1]))
105105

106106
# set subarray access pattern
107-
counts = np.array([length, length + 1], dtype=np.int64)
108-
starts = np.array([local_rank[0] * counts[0], local_rank[1] * counts[1]],
107+
count = np.array([length, length + 1], dtype=np.int64)
108+
start = np.array([local_rank[0] * count[0], local_rank[1] * count[1]],
109109
dtype=np.int64)
110110
if verbose:
111-
print("starts= {} {} counts= {} {}".format(starts[0], starts[1], counts[0], counts[1]))
111+
print("start= {} {} count= {} {}".format(start[0], start[1], count[0], count[1]))
112112

113113
# allocate and initialize buffer with ghost cells on both ends of each dim
114114
nghosts = 2
115-
bufsize = (counts[0] + 2 * nghosts) * (counts[1] + 2 * nghosts)
115+
bufsize = (count[0] + 2 * nghosts) * (count[1] + 2 * nghosts)
116116
buf = np.empty(bufsize, dtype=np.int32)
117-
for i in range(counts[0] + 2 * nghosts):
118-
for j in range(counts[1] + 2 * nghosts):
119-
if nghosts <= i < counts[0] + nghosts and \
120-
nghosts <= j < counts[1] + nghosts:
121-
buf[i * (counts[1] + 2 * nghosts) + j] = rank
117+
for i in range(count[0] + 2 * nghosts):
118+
for j in range(count[1] + 2 * nghosts):
119+
if nghosts <= i < count[0] + nghosts and \
120+
nghosts <= j < count[1] + nghosts:
121+
buf[i * (count[1] + 2 * nghosts) + j] = rank
122122
else:
123123
# set values of all ghost cells to -8
124-
buf[i * (counts[1] + 2 * nghosts) + j] = -8
124+
buf[i * (count[1] + 2 * nghosts) + j] = -8
125125

126126
# Create the file
127127
f = pnetcdf.File(filename = filename,
@@ -143,11 +143,11 @@ def pnetcdf_io(filename, file_format, length):
143143
# set imap pattern for local buffer
144144
imap = np.zeros(2, dtype=np.int64)
145145
imap[1] = 1
146-
imap[0] = counts[1] + 2 * nghosts
147-
buf_ptr = buf[nghosts * (counts[1] + 2 * nghosts + 1):]
146+
imap[0] = count[1] + 2 * nghosts
147+
buf_ptr = buf[nghosts * (count[1] + 2 * nghosts + 1):]
148148

149149
# Write data to the variable
150-
var.put_var_all(buf_ptr, start = starts, count = counts, imap = imap)
150+
var.put_var_all(buf_ptr, start = start, count = count, imap = imap)
151151

152152
# Close the file
153153
f.close()

examples/nonblocking_write.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ def pnetcdf_io(filename, length):
5959
print("Number of dimensions = ", NDIMS)
6060

6161
# set up subarray access pattern
62-
starts = np.zeros(NDIMS, dtype=np.int32)
63-
counts = np.zeros(NDIMS, dtype=np.int32)
62+
start = np.zeros(NDIMS, dtype=np.int32)
63+
count = np.zeros(NDIMS, dtype=np.int32)
6464
gsizes = np.zeros(NDIMS, dtype=np.int32)
6565
buf = []
6666

6767
psizes = MPI.Compute_dims(nprocs, NDIMS)
68-
starts[0] = rank % psizes[0]
69-
starts[1] = (rank // psizes[1]) % psizes[1]
70-
starts[2] = (rank // (psizes[0] * psizes[1])) % psizes[2]
68+
start[0] = rank % psizes[0]
69+
start[1] = (rank // psizes[1]) % psizes[1]
70+
start[2] = (rank // (psizes[0] * psizes[1])) % psizes[2]
7171

7272
bufsize = 1
7373
for i in range(NDIMS):
7474
gsizes[i] = length * psizes[i]
75-
starts[i] *= length
76-
counts[i] = length
75+
start[i] *= length
76+
count[i] = length
7777
bufsize *= length
7878

7979
# Allocate buffer and initialize with non-zero numbers
@@ -107,7 +107,7 @@ def pnetcdf_io(filename, length):
107107
# Write one variable at a time, using iput APIs
108108
reqs = []
109109
for i in range(NUM_VARS):
110-
req_id = vars[i].iput_var(buf[i], start = starts, count = counts)
110+
req_id = vars[i].iput_var(buf[i], start = start, count = count)
111111
reqs.append(req_id)
112112

113113
# commit posted noblocking requests
@@ -126,7 +126,7 @@ def pnetcdf_io(filename, length):
126126
# Write one variable at a time, using bput APIs
127127
reqs = []
128128
for i in range(NUM_VARS):
129-
req_id = vars[i].bput_var(buf[i], start = starts, count = counts)
129+
req_id = vars[i].bput_var(buf[i], start = start, count = count)
130130
reqs.append(req_id)
131131
# can safely change contents or free up the buf[i] here
132132

examples/nonblocking_write_def.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ def pnetcdf_io(file_name, length):
6060
print("Number of dimensions = ", NDIMS)
6161

6262
# set subarray access pattern
63-
starts = np.zeros(NDIMS, dtype=np.int32)
64-
counts = np.zeros(NDIMS, dtype=np.int32)
63+
start = np.zeros(NDIMS, dtype=np.int32)
64+
count = np.zeros(NDIMS, dtype=np.int32)
6565
gsizes = np.zeros(NDIMS, dtype=np.int32)
6666
buf = []
6767

6868
psizes = MPI.Compute_dims(nprocs, NDIMS)
69-
starts[0] = rank % psizes[0]
70-
starts[1] = (rank // psizes[1]) % psizes[1]
71-
starts[2] = (rank // (psizes[0] * psizes[1])) % psizes[2]
69+
start[0] = rank % psizes[0]
70+
start[1] = (rank // psizes[1]) % psizes[1]
71+
start[2] = (rank // (psizes[0] * psizes[1])) % psizes[2]
7272

7373
bufsize = 1
7474
for i in range(NDIMS):
7575
gsizes[i] = length * psizes[i]
76-
starts[i] *= length
77-
counts[i] = length
76+
start[i] *= length
77+
count[i] = length
7878
bufsize *= length
7979

8080
# Allocate buffer and initialize with non-zero numbers
@@ -104,7 +104,7 @@ def pnetcdf_io(file_name, length):
104104

105105
# Write one variable at a time
106106
for i in range(NUM_VARS):
107-
vars[i].iput_var(buf[i], start = starts, count = counts)
107+
vars[i].iput_var(buf[i], start = start, count = count)
108108

109109
# exit define mode and enter data mode
110110
f.enddef()
@@ -120,7 +120,7 @@ def pnetcdf_io(file_name, length):
120120
# call bput for writing to one variable at a time
121121
reqs = []
122122
for i in range(NUM_VARS):
123-
req_id = vars[i].bput_var(buf[i], start = starts, count = counts)
123+
req_id = vars[i].bput_var(buf[i], start = start, count = count)
124124
reqs.append(req_id)
125125
# can safely change contents or free up the buf[i] here
126126

examples/put_vara.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def pnetcdf_io(filename, file_format):
7575
NX = 4
7676
global_ny = NY
7777
global_nx = NX * nprocs
78-
starts = [0, NX * rank]
79-
counts = [NY, NX]
78+
start = [0, NX * rank]
79+
count = [NY, NX]
8080

8181
if verbose and rank == 0:
8282
print("Y dimension size = ", NY)
@@ -125,7 +125,8 @@ def pnetcdf_io(filename, file_format):
125125
buf = np.zeros(shape = (NY, NX), dtype = "i4") + rank
126126

127127
# Write data to the variable
128-
var.put_var_all(buf, start = starts, count = counts)
128+
# var.put_var_all(buf, start = starts, count = counts)
129+
var[0:NY, NX*rank:NX*rank+NX] = buf
129130

130131
# Close the file
131132
f.close()

0 commit comments

Comments
 (0)