nextsimhub / domain_decomp

Domain decomposition tool for the nextSIM-DG next-generation sea ice model.
Apache License 2.0
1 stars 0 forks source link

Transpose input to match changing on indices in nextsimdg #26

Closed TomMelt closed 9 months ago

TomMelt commented 10 months ago

After PR https://github.com/nextsimhub/nextsimdg/pull/373 domain_decomp produces incorrect meta data when x and y dims were switched (for rectangular shaped grids) -- even when supplying --dim0 y and --dim1 x options.

E.g. when running the testRectGrid_MPI test from nextsimdg we have a rectangular grid of dimensions:

$ ncdump RectGrid_test.nc
netcdf RectGrid_test {
[...]
group: data {
  dimensions:
    x = 25 ;
    y = 15 ;
    z = 1 ;
  variables:
    double cice(y, x) ;
        cice:missing_value = -2.03703597633449e+90 ;
[...]

However if we run decomp we get the following meta data (notice that globalX, globalY and other related dimensions are the wrong way round).

$ mpirun -n 2 ./decomp --grid RectGrid_test.nc --dim0 y --dim1 x && ncdump partition_metadata_2.nc
Partitioning total time: 8.8619e-05 (secs)
Partitioning Statistics:
[...]
 STATS DETAIL count:  min 180  max 195  avg 187.500000  imbal 1.040000
 STATS DETAIL wdim = 0; no detail available
$ ncdump partition_metadata_2.nc
netcdf partition_metadata_2 {
dimensions:
    globalX = 15 ;
    globalY = 25 ;
[...]
  data:
   global_x = 0, 0 ;
   global_y = 0, 12 ;
   local_extent_x = 15, 15 ;
   local_extent_y = 12, 13 ;
  } // group bounding_boxes
[...]
}

This PR fixes the issue and the correct meta data is produced.

$ mpirun -n 2 ./decomp --grid RectGrid_test.nc && ncdump partition_metadata_2.nc
[...]
netcdf partition_metadata_2 {
dimensions:
    globalX = 25 ;
    globalY = 15 ;
[...]
   global_x = 0, 12 ;
   global_y = 0, 0 ;
   local_extent_x = 12, 13 ;
   local_extent_y = 15, 15 ;
  } // group bounding_boxes
[...]
}

Notice I have omitted the --dim0 and --dim1 flags.

This "fix" has been implemented by transposing the input data when it is read-in from the netcdf file specified by --grid.

This was the simplest way to get everything working without breaking the tests, the library or the stand-alone binary.

Whilst this works for now I think a proper solution should be found because I think it could be confusing in future.

Unfortunately I think we need to switch everything else -- instead of the input i.e., dim0 <-> dim1, x <-> y etc.

This is not as trivial as I first thought however as there are many places where this needs to be carefully checked.

timspainNERSC commented 9 months ago

I haven't even looked at the code yet, but I think we had the same problem in the nextsim-DG test with the MacOS test failing to extract correctly into homebrew/cask. I will try to find a) if I am indeed remembering correctly and then b) what the solution was.

timspainNERSC commented 9 months ago

I haven't even looked at the code yet, but I think we had the same problem in the nextsim-DG test with the MacOS test failing to extract correctly into homebrew/cask. I will try to find a) if I am indeed remembering correctly and then b) what the solution was.

Solved with commit e59851e.