7272from mpi4py import MPI
7373import pnetcdf
7474
75- def parse_help ():
76- help_flag = "-h" in sys .argv or "--help" in sys .argv
77- if help_flag and rank == 0 :
78- help_text = (
79- "Usage: {} [-h] | [-q] [file_name]\n "
80- " [-h] Print help\n "
81- " [-q] Quiet mode (reports when fail)\n "
82- " [-k format] file format: 1 for CDF-1, 2 for CDF-2, 5 for CDF-5\n "
83- " [filename] (Optional) output netCDF file name\n "
84- ).format (sys .argv [0 ])
85- print (help_text )
86- return help_flag
87-
8875def pnetcdf_io (filename , file_format ):
8976 NY = 5
9077 NX = 5
@@ -124,9 +111,9 @@ def pnetcdf_io(filename, file_format):
124111 array_of_subsizes = np .array ([NZ , NY ])
125112 array_of_start = np .array ([ghost_len , ghost_len ])
126113
127- subarray = MPI .INT .Create_subarray (array_of_sizes , \
128- array_of_subsizes , \
129- array_of_start , \
114+ subarray = MPI .INT .Create_subarray (array_of_sizes ,
115+ array_of_subsizes ,
116+ array_of_start ,
130117 order = MPI .ORDER_C )
131118 subarray .Commit ()
132119
@@ -139,12 +126,13 @@ def pnetcdf_io(filename, file_format):
139126 count = np .array ([NZ , NY ])
140127
141128 # calling a blocking flexible API using put_var_all()
142- var_zy .put_var_all (buf_zy , start = start , \
143- count = count , \
144- bufcount = 1 , \
129+ var_zy .put_var_all (buf_zy , start = start ,
130+ count = count ,
131+ bufcount = 1 ,
145132 buftype = subarray )
146133
147134
135+ # check if write buffer's contents are altered (should not be).
148136 for i in range (buffer_len ):
149137 if buf_zy [i ] != rank :
150138 print (f"Error at line { sys ._getframe ().f_lineno } in { __file__ } : put buffer[{ i } ] is altered" )
@@ -158,7 +146,7 @@ def pnetcdf_io(filename, file_format):
158146 bufcount = 1 ,
159147 buftype = subarray )
160148
161- # check contents of the get buffer
149+ # check whether contents of the get buffer are expected
162150 for i in range (array_of_sizes [0 ]):
163151 for j in range (array_of_sizes [1 ]):
164152 index = i * array_of_sizes [1 ] + j
@@ -200,7 +188,7 @@ def pnetcdf_io(filename, file_format):
200188 status = [None ]
201189 f .wait_all (1 , [req_id ], status = status )
202190
203- # check request error msg for each unsuccessful requests
191+ # check request error for each unsuccessful requests
204192 if pnetcdf .strerrno (status [0 ]) != "NC_NOERR" :
205193 print (f"Error on request { i } :" , pnetcdf .strerror (status [0 ]))
206194
@@ -216,11 +204,11 @@ def pnetcdf_io(filename, file_format):
216204 # commit posted pending nonblocking requests
217205 f .wait_all (1 , [req_id ], status = status )
218206
219- # check request error msg for each unsuccessful requests
207+ # check request error for each unsuccessful requests
220208 if pnetcdf .strerrno (status [0 ]) != "NC_NOERR" :
221209 print (f"Error on request { i } :" , pnetcdf .strerror (status [0 ]))
222210
223- # check the contents of iget buffer
211+ # check the contents of read buffer
224212 for i in range (array_of_sizes [0 ]):
225213 for j in range (array_of_sizes [1 ]):
226214 index = i * array_of_sizes [1 ] + j
@@ -236,6 +224,19 @@ def pnetcdf_io(filename, file_format):
236224 f .close ()
237225
238226
227+ def parse_help ():
228+ help_flag = "-h" in sys .argv or "--help" in sys .argv
229+ if help_flag and rank == 0 :
230+ help_text = (
231+ "Usage: {} [-h] | [-q] [file_name]\n "
232+ " [-h] Print help\n "
233+ " [-q] Quiet mode (reports when fail)\n "
234+ " [-k format] file format: 1 for CDF-1, 2 for CDF-2, 5 for CDF-5\n "
235+ " [filename] (Optional) output netCDF file name\n "
236+ ).format (sys .argv [0 ])
237+ print (help_text )
238+ return help_flag
239+
239240if __name__ == "__main__" :
240241 comm = MPI .COMM_WORLD
241242 rank = comm .Get_rank ()
0 commit comments