-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf65b9a
commit deb6950
Showing
4 changed files
with
64 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,16 @@ | ||
# for example run as: | ||
# $HOME/.julia/packages/MPI/z2owj/bin/mpiexecjl -n 4 julia test_mpi_netcdf.jl | ||
|
||
using MPIPreferences | ||
using MPI | ||
using NCDatasets | ||
using Test | ||
using NCDatasets | ||
|
||
mpiexec = realpath(joinpath(dirname(pathof(MPI)),"..","bin","mpiexecjl")) | ||
|
||
#println("mpiexec ",mpiexec) | ||
|
||
print("$mpiexec -n 4 julia test_mpi.jl") | ||
|
||
MPI.Init() | ||
|
||
mpi_comm = MPI.COMM_WORLD | ||
mpi_comm_size = MPI.Comm_size(mpi_comm) | ||
mpi_rank = MPI.Comm_rank(mpi_comm) | ||
|
||
# need to be the same file for all processes | ||
path = "/tmp/test-mpi.nc" | ||
i = mpi_rank + 1 | ||
|
||
|
||
ds = NCDataset(mpi_comm,path,"c") | ||
|
||
defDim(ds,"lon",10) | ||
defDim(ds,"lat",mpi_comm_size) | ||
ncv = defVar(ds,"temp",Float32,("lon","lat")) | ||
|
||
# see | ||
# https://web.archive.org/web/20240414204638/https://docs.unidata.ucar.edu/netcdf-c/current/parallel_io.html | ||
NCDatasets.access(ncv.var,:collective) | ||
|
||
|
||
print("rank $(mpi_rank) writing to netCDF variable\n") | ||
ncv[:,i] .= mpi_rank | ||
|
||
ncv.attrib["units"] = "degree Celsius" | ||
ds.attrib["comment"] = "MPI test" | ||
close(ds) | ||
|
||
|
||
ds = NCDataset(mpi_comm,path,"r") | ||
ncv = ds["temp"] | ||
|
||
@test size(ncv) == (10,mpi_comm_size) | ||
print("rank $(mpi_rank) reading from netCDF variable\n") | ||
nprocs = 4 | ||
testdir = @__DIR__ | ||
prog = joinpath(testdir, "test_mpi_script.jl") | ||
fn = tempname() | ||
|
||
@test all(==(mpi_rank),ncv[:,i]) | ||
@test ncv.attrib["units"] == "degree Celsius" | ||
@test ds.attrib["comment"] == "MPI test" | ||
run(`$(mpiexec()) -n $nprocs $(Base.julia_cmd()) --startup-file=no $prog $fn`) | ||
# run with raise an error if prog fails | ||
|
||
ds = NCDataset(fn) | ||
@test ds.dim["lat"] == nprocs | ||
@test ds["temp"][:,:] == repeat((0:(nprocs-1))',inner=(10,1)) | ||
close(ds) | ||
|
||
MPI.Finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# for example run as: | ||
# $HOME/.julia/packages/MPI/z2owj/bin/mpiexecjl -n 4 julia test_mpi_script.jl | ||
|
||
using MPI | ||
using NCDatasets | ||
using Test | ||
|
||
MPI.Init() | ||
|
||
mpi_comm = MPI.COMM_WORLD | ||
mpi_comm_size = MPI.Comm_size(mpi_comm) | ||
mpi_rank = MPI.Comm_rank(mpi_comm) | ||
|
||
# need to be the same file for all processes | ||
path = ARGS[1] | ||
i = mpi_rank + 1 | ||
|
||
ds = NCDataset(mpi_comm,path,"c") | ||
|
||
defDim(ds,"lon",10) | ||
defDim(ds,"lat",mpi_comm_size) | ||
ncv = defVar(ds,"temp",Float32,("lon","lat")) | ||
|
||
# see | ||
# https://web.archive.org/web/20240414204638/https://docs.unidata.ucar.edu/netcdf-c/current/parallel_io.html | ||
NCDatasets.access(ncv.var,:collective) | ||
|
||
|
||
@debug("rank $(mpi_rank) writing to netCDF variable") | ||
ncv[:,i] .= mpi_rank | ||
|
||
ncv.attrib["units"] = "degree Celsius" | ||
ds.attrib["comment"] = "MPI test" | ||
close(ds) | ||
|
||
|
||
ds = NCDataset(mpi_comm,path,"r") | ||
ncv = ds["temp"] | ||
|
||
@test size(ncv) == (10,mpi_comm_size) | ||
@debug("rank $(mpi_rank) reading from netCDF variable") | ||
|
||
@test all(==(mpi_rank),ncv[:,i]) | ||
@test ncv.attrib["units"] == "degree Celsius" | ||
@test ds.attrib["comment"] == "MPI test" | ||
|
||
close(ds) | ||
|
||
MPI.Finalize() |