NEP 2.7.0
NetCDF Extension Pack
Loading...
Searching...
No Matches
Functions/Subroutines
f_square16_par.f90 File Reference

Parallel NetCDF-4 I/O with MPI using a 2x2 rank decomposition (Fortran) More...

Functions/Subroutines

program f_square16_par
 
subroutine handle_err (err, rank)
 

Detailed Description

Parallel NetCDF-4 I/O with MPI using a 2x2 rank decomposition (Fortran)

Fortran equivalent of square16_par.c, showing how to use NetCDF-4 parallel I/O with MPI from Fortran 90. Four MPI ranks cooperate to write a single 16x16 integer array, each contributing an 8x8 quadrant filled with its own rank number.

The program demonstrates the fundamental parallel I/O pattern: open a file collectively, define the full dataset shape once, then have each rank write only its local portion using hyperslab selections (start/count). After writing, it performs a parallel read-back to verify correctness.

Learning Objectives:

Key Concepts:

Rank Layout (2×2 grid):

col 0-7 col 8-15
+----------+----------+
| rank 0 | rank 1 | rows 0-7
+----------+----------+
| rank 2 | rank 3 | rows 8-15
+----------+----------+

Prerequisites:

Related Examples:

Compilation:

mpif90 -o f_square16_par f_square16_par.f90 -lnetcdff -lnetcdf
program f_square16_par
Definition f_square16_par.f90:85

Usage:

mpirun -n 4 ./f_square16_par

Expected Output:

parallel i/o write and read-back successful. file: f_square16_par.nc
Note
Companion code for "The NetCDF Developer's Handbook: The Authoritative Guide to Writing High-Performance Programs for Scientific Data Management, Second Edition" (https://www.amazon.com/dp/B0H7Q1Z75L)
Author
Edward Hartnett, Intelligent Data Design, Inc.
Date
June 3, 2026

Function/Subroutine Documentation

◆ f_square16_par()

program f_square16_par

◆ handle_err()

subroutine f_square16_par::handle_err ( integer, intent(in)  err,
integer, intent(in)  rank 
)