Exercise
We're now ready to take what we've learned about PnetCDF and see how to put it all together in a few example programs.
The starting point of the exercise is example-single-write.c. In this program, rank 0 gathers chunks of data from the rest of the ranks and writes a netCDF file. This example illustrates the use of various functions in the PnetCDF API. However, it leaves open some important questions:
Can we write the file in parallel? What is the performance difference?
You can experiment with this example, along with the rest of the codes provided, to answer these questions.
Follow the steps below to compile and run the codes. The Makefile and job.sh have been tested on TACC's Stampede3 and Frontera systems, as well as SDSC's Comet and Expanse supercomputers.
-
cat ReadMe.txt
- gives you instructions on how to load modules or install software to ensure that the required packages are available (as discussed in Setup earlier). -
make all
- builds the required executable as directed byMakefile
(be sure to execute the commandmv Makefile.txt Makefile
to remove the .txt extension). Note that there is a dependency on the PnetCDF library; again, please be sure that you have either loaded the proper module or installed the software as directed in step 1. -
sbatch job.sh
- runs the executables and produces output files under the$SCRATCH
directory. You should check the batch script first and edit it as necessary (for instance, to add your allocation ID). At the end of the job, the script deletes the output files. If you intend to keep the output files for further inspection or testing, please comment outrm -rf $WORKDIR
on the last line. You can then use netCDF'sncdump
utility (for example) to view the output files directly:ncdump $SCRATCH/pnetcdf/output.collective | less
Exercise files:
- ReadMe.txt
- Makefile.txt - use
mv
to rename toMakefile
- job.sh.txt - use
mv
to rename tojob.sh
- example-single-write.c
- example-coll-read.c
- example-coll-write.c