diff --git a/Source/C/ProcessGrid_c.h b/Source/C/ProcessGrid_c.h index 71d6f8e4..67fba678 100644 --- a/Source/C/ProcessGrid_c.h +++ b/Source/C/ProcessGrid_c.h @@ -6,20 +6,30 @@ void ConstructGlobalProcessGrid_wrp(const int *world_comm, const int *process_columns, const int *process_slices, const bool *be_verbose); -void CopyProcessGrid_wrp(const int *ih_old_grid, int* ih_new_grid); +void ConstructGlobalProcessGridabr_wrp(const int *world_comm, + const int *process_slices, + const bool *be_verbose); +void CopyProcessGrid_wrp(const int *ih_old_grid, int *ih_new_grid); int GetGlobalMySlice_wrp(); int GetGlobalMyColumn_wrp(); int GetGlobalMyRow_wrp(); +int GetGlobalNumSlices_wrp(); +int GetGlobalNumColumns_wrp(); +int GetGlobalNumRows_wrp(); void DestructGlobalProcessGrid_wrp(); void ConstructProcessGrid_wrp(int *ih_grid, const int *world_comm, const int *process_rows, const int *process_columns, - const int *process_slices, - const bool *be_verbose); + const int *process_slices); +void ConstructProcessGridabr_wrp(int *ih_grid, const int *world_comm, + const int *process_slices); int GetMySlice_wrp(const int *ih_grid); int GetMyColumn_wrp(const int *ih_grid); int GetMyRow_wrp(const int *ih_grid); +int GetNumSlices_wrp(const int *ih_grid); +int GetNumColumns_wrp(const int *ih_grid); +int GetNumRows_wrp(const int *ih_grid); void DestructProcessGrid_wrp(int *ih_grid); #endif diff --git a/Source/CPlusPlus/ProcessGrid.cc b/Source/CPlusPlus/ProcessGrid.cc index 23e2f5dc..22942153 100644 --- a/Source/CPlusPlus/ProcessGrid.cc +++ b/Source/CPlusPlus/ProcessGrid.cc @@ -10,19 +10,30 @@ namespace NTPoly { //////////////////////////////////////////////////////////////////////////////// ProcessGrid::ProcessGrid(MPI_Comm world_comm, int process_rows, - int process_columns, int process_slices, - bool be_verbose) { + int process_columns, int process_slices) { MPI_Fint temp_comm = MPI_Comm_c2f(world_comm); ConstructProcessGrid_wrp(ih_this, &temp_comm, &process_rows, &process_columns, - &process_slices, &be_verbose); + &process_slices); } //////////////////////////////////////////////////////////////////////////////// ProcessGrid::ProcessGrid(int process_rows, int process_columns, - int process_slices, bool be_verbose) { + int process_slices) { MPI_Fint temp_comm = MPI_Comm_c2f(MPI_COMM_WORLD); ConstructProcessGrid_wrp(ih_this, &temp_comm, &process_rows, &process_columns, - &process_slices, &be_verbose); + &process_slices); +} + +//////////////////////////////////////////////////////////////////////////////// +ProcessGrid::ProcessGrid(MPI_Comm world_comm, int process_slices) { + MPI_Fint temp_comm = MPI_Comm_c2f(world_comm); + ConstructProcessGridabr_wrp(ih_this, &temp_comm, &process_slices); +} + +//////////////////////////////////////////////////////////////////////////////// +ProcessGrid::ProcessGrid(int process_slices) { + MPI_Fint temp_comm = MPI_Comm_c2f(MPI_COMM_WORLD); + ConstructProcessGridabr_wrp(ih_this, &temp_comm, &process_slices); } ////////////////////////////////////////////////////////////////////////////// @@ -39,6 +50,15 @@ int ProcessGrid::GetMyColumn() { return GetMyColumn_wrp(ih_this); } //////////////////////////////////////////////////////////////////////////////// int ProcessGrid::GetMyRow() { return GetMyRow_wrp(ih_this); } +//////////////////////////////////////////////////////////////////////////////// +int ProcessGrid::GetNumSlices() { return GetNumSlices_wrp(ih_this); } + +//////////////////////////////////////////////////////////////////////////////// +int ProcessGrid::GetNumColumns() { return GetNumColumns_wrp(ih_this); } + +//////////////////////////////////////////////////////////////////////////////// +int ProcessGrid::GetNumRows() { return GetNumRows_wrp(ih_this); } + //////////////////////////////////////////////////////////////////////////////// ProcessGrid::~ProcessGrid() { DestructProcessGrid_wrp(ih_this); } @@ -59,6 +79,19 @@ void ConstructGlobalProcessGrid(int process_rows, int process_columns, &process_slices, &be_verbose); } +//////////////////////////////////////////////////////////////////////////////// +void ConstructGlobalProcessGrid(MPI_Comm world_comm, int process_slices, + bool be_verbose) { + MPI_Fint temp_comm = MPI_Comm_c2f(world_comm); + ConstructGlobalProcessGridabr_wrp(&temp_comm, &process_slices, &be_verbose); +} + +//////////////////////////////////////////////////////////////////////////////// +void ConstructGlobalProcessGrid(int process_slices, bool be_verbose) { + MPI_Fint temp_comm = MPI_Comm_c2f(MPI_COMM_WORLD); + ConstructGlobalProcessGridabr_wrp(&temp_comm, &process_slices, &be_verbose); +} + //////////////////////////////////////////////////////////////////////////////// int GetGlobalMySlice() { return GetGlobalMySlice_wrp(); } @@ -68,6 +101,15 @@ int GetGlobalMyColumn() { return GetGlobalMyColumn_wrp(); } //////////////////////////////////////////////////////////////////////////////// int GetGlobalMyRow() { return GetGlobalMyRow_wrp(); } +//////////////////////////////////////////////////////////////////////////////// +int GetGlobalNumSlices() { return GetGlobalNumSlices_wrp(); } + +//////////////////////////////////////////////////////////////////////////////// +int GetGlobalNumColumns() { return GetGlobalNumColumns_wrp(); } + +//////////////////////////////////////////////////////////////////////////////// +int GetGlobalNumRows() { return GetGlobalNumRows_wrp(); } + //////////////////////////////////////////////////////////////////////////////// void DestructGlobalProcessGrid() { DestructGlobalProcessGrid_wrp(); } } // namespace NTPoly diff --git a/Source/CPlusPlus/ProcessGrid.h b/Source/CPlusPlus/ProcessGrid.h index d454f61b..f0646d1b 100644 --- a/Source/CPlusPlus/ProcessGrid.h +++ b/Source/CPlusPlus/ProcessGrid.h @@ -15,16 +15,21 @@ class ProcessGrid { //! \param[in] process_rows number of grid rows. //! \param[in] process_columns number of grid columns. //! \param[in] process_slices number of grid slices. - //! \param[in] be_verbose verbosity flag. ProcessGrid(MPI_Comm world_comm, int process_rows, int process_columns, - int process_slices, bool be_verbose = false); + int process_slices); //! Construct the process grid from comm world //! \param[in] process_rows number of grid rows. //! \param[in] process_columns number of grid columns. //! \param[in] process_slices number of grid slices. - //! \param[in] be_verbose verbosity flag. - ProcessGrid(int process_rows, int process_columns, int process_slices, - bool be_verbose = false); + ProcessGrid(int process_rows, int process_columns, int process_slices); + //! Construct the process grid. + //! \param[in] world_comm a communicator that every process in the grid is + //! a part of. + //! \param[in] process_rows number of grid rows. + ProcessGrid(MPI_Comm world_comm, int process_slices); + //! Construct the process grid from comm world + //! \param[in] process_slices number of grid slices. + ProcessGrid(int process_slices); //! Copy constructor. //!\param old_grid to copy from. ProcessGrid(const ProcessGrid &old_grid); @@ -36,6 +41,12 @@ class ProcessGrid { int GetMyColumn(); //! Get the row of the current process. int GetMyRow(); + //! Get the number of slices in this grid. + int GetNumSlices(); + //! Get the number of columns in this grid. + int GetNumColumns(); + //! Get the number of rows in this grid. + int GetNumRows(); public: //! Standard destructor @@ -65,12 +76,29 @@ void ConstructGlobalProcessGrid(MPI_Comm world_comm, int process_rows, //! \param[in] be_verbose verbosity flag. void ConstructGlobalProcessGrid(int process_rows, int process_columns, int process_slices, bool be_verbose = false); +//! Construct the global process grid. +//! \param[in] world_comm a communicator that every process in the grid is +//! a part of. +//! \param[in] process_slices number of grid slices. +//! \param[in] be_verbose verbosity flag. +void ConstructGlobalProcessGrid(MPI_Comm world_comm, int process_slices, + bool be_verbose = false); +//! Construct the global process grid from comm world +//! \param[in] process_slices number of grid slices. +//! \param[in] be_verbose verbosity flag. +void ConstructGlobalProcessGrid(int process_slices, bool be_verbose = false); //! Get the slice of the current process. int GetGlobalMySlice(); //! Get the column of the current process. int GetGlobalMyColumn(); //! Get the row of the current process. int GetGlobalMyRow(); +//! Get the number of process slices. +int GetGlobalNumSlices(); +//! Get the number of process columns. +int GetGlobalNumColumns(); +//! Get the number of process rows. +int GetGlobalNumRows(); //! Standard destructor void DestructGlobalProcessGrid(); } // namespace NTPoly diff --git a/Source/Fortran/ProcessGridModule.F90 b/Source/Fortran/ProcessGridModule.F90 index 84fd6733..11425b0d 100644 --- a/Source/Fortran/ProcessGridModule.F90 +++ b/Source/Fortran/ProcessGridModule.F90 @@ -71,6 +71,10 @@ MODULE ProcessGridModule MODULE PROCEDURE ConstructProcessGrid_full MODULE PROCEDURE ConstructProcessGrid_onlyslice END INTERFACE + INTERFACE ConstructNewProcessGrid + MODULE PROCEDURE ConstructNewProcessGrid_full + MODULE PROCEDURE ConstructNewProcessGrid_onlyslice + END INTERFACE CONTAINS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Setup the default process grid. SUBROUTINE ConstructProcessGrid_full(world_comm_, process_rows_, & @@ -132,9 +136,7 @@ SUBROUTINE ConstructProcessGrid_onlyslice(world_comm_, process_slices_in, & !! Local Data LOGICAL(kind=c_bool) :: be_verbose INTEGER :: process_rows, process_columns, process_slices - INTEGER :: slice_size, size_search INTEGER :: total_processors - INTEGER :: II INTEGER :: ierr !! Total processors @@ -153,17 +155,8 @@ SUBROUTINE ConstructProcessGrid_onlyslice(world_comm_, process_slices_in, & END IF !! Create a 3D grid - process_rows = 1 - process_columns = 1 - slice_size = total_processors/process_slices - size_search = FLOOR(SQRT(REAL(slice_size))) - DO II=size_search,1,-1 - IF (MOD(slice_size,II) .EQ. 0) THEN - process_rows = II - process_columns = slice_size/II - EXIT - END IF - END DO + CALL ComputeGridSize(total_processors, process_slices, process_rows, & + & process_columns) !! Now call the full setup CALL ConstructProcessGrid(world_comm_, process_rows, process_columns, & @@ -171,7 +164,7 @@ SUBROUTINE ConstructProcessGrid_onlyslice(world_comm_, process_slices_in, & END SUBROUTINE ConstructProcessGrid_onlyslice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Construct a process grid. - SUBROUTINE ConstructNewProcessGrid(grid, world_comm_, process_rows_, & + SUBROUTINE ConstructNewProcessGrid_full(grid, world_comm_, process_rows_, & & process_columns_, process_slices_) !> The grid to construct TYPE(ProcessGrid_t), INTENT(INOUT) :: grid @@ -289,7 +282,33 @@ SUBROUTINE ConstructNewProcessGrid(grid, world_comm_, process_rows_, & & grid%global_rank, grid%blocked_row_comm(II), ierr) END DO - END SUBROUTINE ConstructNewProcessGrid + END SUBROUTINE ConstructNewProcessGrid_full +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Setup a process grid specifying only the slices + SUBROUTINE ConstructNewProcessGrid_onlyslice(grid, world_comm_, & + & process_slices) + !> The grid to construct + TYPE(ProcessGrid_t), INTENT(INOUT) :: grid + !> A communicator that every process in the grid is a part of. + INTEGER(kind=c_int), INTENT(IN) :: world_comm_ + !> The number of grid slices. + INTEGER(kind=c_int), INTENT(IN) :: process_slices + !! Local Data + INTEGER :: process_rows, process_columns + INTEGER :: total_processors + INTEGER :: ierr + + !! Total processors + CALL MPI_COMM_SIZE(world_comm_, total_processors, ierr) + + !! Create a 3D grid + CALL ComputeGridSize(total_processors, process_slices, process_rows, & + & process_columns) + + !! Now call the full setup + CALL ConstructNewProcessGrid(grid, world_comm_, process_rows, & + & process_columns, process_slices) + END SUBROUTINE ConstructNewProcessGrid_onlyslice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Copy a process grid. !! Note that this makes a complete and independent copy of the process grid. @@ -563,5 +582,34 @@ FUNCTION GetMyRow(grid) RESULT(return_val) return_val = global_grid%my_row END IF END FUNCTION GetMyRow +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Sometimes we only want to specify a process grid's number of slices + !! and then automatically compute the right number of rows and columns. + SUBROUTINE ComputeGridSize(total_processors, set_slices, rows, columns) + !> Total processors in the grid + INTEGER, INTENT(IN) :: total_processors + !> Desired number of slices + INTEGER, INTENT(IN) :: set_slices + !> Computed number of rows + INTEGER, INTENT(OUT) :: rows + !> Computed number of columns + INTEGER, INTENT(OUT) :: columns + !! Local variables + INTEGER :: slice_size, size_search + INTEGER :: II + + rows = 1 + columns = 1 + slice_size = total_processors/set_slices + size_search = FLOOR(SQRT(REAL(slice_size))) + DO II=size_search,1,-1 + IF (MOD(slice_size,II) .EQ. 0) THEN + rows = II + columns = slice_size/II + EXIT + END IF + END DO + + END SUBROUTINE ComputeGridSize !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! END MODULE ProcessGridModule diff --git a/Source/Wrapper/ProcessGridModule_wrp.F90 b/Source/Wrapper/ProcessGridModule_wrp.F90 index 85d28739..c7611dc9 100644 --- a/Source/Wrapper/ProcessGridModule_wrp.F90 +++ b/Source/Wrapper/ProcessGridModule_wrp.F90 @@ -15,16 +15,24 @@ MODULE ProcessGridModule_wrp END TYPE ProcessGrid_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PUBLIC :: ConstructGlobalProcessGrid_wrp + PUBLIC :: ConstructGlobalProcessGridabr_wrp PUBLIC :: GetGlobalMySlice_wrp PUBLIC :: GetGlobalMyColumn_wrp PUBLIC :: GetGlobalMyRow_wrp + PUBLIC :: GetGlobalNumSlices_wrp + PUBLIC :: GetGlobalNumColumns_wrp + PUBLIC :: GetGlobalNumRows_wrp PUBLIC :: DestructGlobalProcessGrid_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PUBLIC :: ConstructProcessGrid_wrp + PUBLIC :: ConstructProcessGridabr_wrp PUBLIC :: CopyProcessGrid_wrp PUBLIC :: GetMySlice_wrp PUBLIC :: GetMyColumn_wrp PUBLIC :: GetMyRow_wrp + PUBLIC :: GetNumSlices_wrp + PUBLIC :: GetNumColumns_wrp + PUBLIC :: GetNumRows_wrp PUBLIC :: DestructProcessGrid_wrp CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Wrap the process grid construction routine. @@ -39,6 +47,15 @@ SUBROUTINE ConstructGlobalProcessGrid_wrp(world_comm_, process_rows_, & CALL ConstructProcessGrid(world_comm_, process_rows_, process_columns_, & & process_slices_, be_verbose) END SUBROUTINE ConstructGlobalProcessGrid_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Wrap the process grid construction routine. + SUBROUTINE ConstructGlobalProcessGridabr_wrp(world_comm_, process_slices_, & + & be_verbose) bind(c,name="ConstructGlobalProcessGridabr_wrp") + INTEGER(kind=c_int), INTENT(IN) :: world_comm_ + INTEGER(kind=c_int), INTENT(IN) :: process_slices_ + LOGICAL(kind=c_bool), INTENT(IN) :: be_verbose + CALL ConstructProcessGrid(world_comm_, process_slices_, be_verbose) + END SUBROUTINE ConstructGlobalProcessGridabr_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Get the slice of the current process. FUNCTION GetGlobalMySlice_wrp() RESULT(return_val) & @@ -61,6 +78,30 @@ FUNCTION GetGlobalMyRow_wrp() RESULT(return_val) & INTEGER(kind=c_int) :: return_val return_val = GetMyRow() END FUNCTION GetGlobalMyRow_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get the number of process slices. + FUNCTION GetGlobalNumSlices_wrp() RESULT(return_val) & + & bind(c,name="GetGlobalNumSlices_wrp") + !! Parameters + INTEGER(kind=c_int) :: return_val + return_val = global_grid%num_process_slices + END FUNCTION GetGlobalNumSlices_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get the number of process columns. + FUNCTION GetGlobalNumColumns_wrp() RESULT(return_val) & + & bind(c,name="GetGlobalNumColumns_wrp") + !! Parameters + INTEGER(kind=c_int) :: return_val + return_val = global_grid%num_process_columns + END FUNCTION GetGlobalNumColumns_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get the number of process rows. + FUNCTION GetGlobalNumRows_wrp() RESULT(return_val) & + & bind(c,name="GetGlobalNumRows_wrp") + !! Parameters + INTEGER(kind=c_int) :: return_val + return_val = global_grid%num_process_rows + END FUNCTION GetGlobalNumRows_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Wrap the process grid construction routine. SUBROUTINE DestructGlobalProcessGrid_wrp() & @@ -70,14 +111,13 @@ END SUBROUTINE DestructGlobalProcessGrid_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Construct a process grid. SUBROUTINE ConstructProcessGrid_wrp(ih_grid, world_comm_, process_rows_, & - & process_columns_, process_slices_, be_verbose) & + & process_columns_, process_slices_) & & bind(c,name="ConstructProcessGrid_wrp") INTEGER(kind=c_int), INTENT(INOUT) :: ih_grid(SIZE_wrp) INTEGER(kind=c_int), INTENT(IN) :: world_comm_ INTEGER(kind=c_int), INTENT(IN) :: process_rows_ INTEGER(kind=c_int), INTENT(IN) :: process_columns_ INTEGER(kind=c_int), INTENT(IN) :: process_slices_ - LOGICAL(kind=c_bool), INTENT(IN) :: be_verbose TYPE(ProcessGrid_wrp) :: h_grid ALLOCATE(h_grid%data) @@ -85,6 +125,19 @@ SUBROUTINE ConstructProcessGrid_wrp(ih_grid, world_comm_, process_rows_, & & process_columns_, process_slices_) ih_grid = TRANSFER(h_grid,ih_grid) END SUBROUTINE ConstructProcessGrid_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Construct a process grid. + SUBROUTINE ConstructProcessGridabr_wrp(ih_grid, world_comm_, process_slices_) & + & bind(c,name="ConstructProcessGridabr_wrp") + INTEGER(kind=c_int), INTENT(INOUT) :: ih_grid(SIZE_wrp) + INTEGER(kind=c_int), INTENT(IN) :: world_comm_ + INTEGER(kind=c_int), INTENT(IN) :: process_slices_ + TYPE(ProcessGrid_wrp) :: h_grid + + ALLOCATE(h_grid%data) + CALL ConstructNewProcessGrid(h_grid%data, world_comm_, process_slices_) + ih_grid = TRANSFER(h_grid,ih_grid) + END SUBROUTINE ConstructProcessGridabr_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Copy a process grid. SUBROUTINE CopyProcessGrid_wrp(ih_old_grid, ih_new_grid) & @@ -132,6 +185,39 @@ FUNCTION GetMyRow_wrp(ih_this) RESULT(return_val) bind(c,name="GetMyRow_wrp") h_this = TRANSFER(ih_this,h_this) return_val = GetMyRow(h_this%data) END FUNCTION GetMyRow_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get the number of slices in this grid. + FUNCTION GetNumSlices_wrp(ih_this) RESULT(return_val) & + & bind(c,name="GetNumSlices_wrp") + INTEGER(kind=c_int), INTENT(IN) :: ih_this(SIZE_wrp) + INTEGER(kind=c_int) :: return_val + TYPE(ProcessGrid_wrp) :: h_this + + h_this = TRANSFER(ih_this,h_this) + return_val = h_this%data%num_process_slices + END FUNCTION GetNumSlices_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get the number of columns in this grid. + FUNCTION GetNumColumns_wrp(ih_this) RESULT(return_val) & + & bind(c,name="GetNumColumns_wrp") + INTEGER(kind=c_int), INTENT(IN) :: ih_this(SIZE_wrp) + INTEGER(kind=c_int) :: return_val + TYPE(ProcessGrid_wrp) :: h_this + + h_this = TRANSFER(ih_this,h_this) + return_val = h_this%data%num_process_columns + END FUNCTION GetNumColumns_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get the number of rows in this grid. + FUNCTION GetNumRows_wrp(ih_this) RESULT(return_val) & + & bind(c,name="GetNumRows_wrp") + INTEGER(kind=c_int), INTENT(IN) :: ih_this(SIZE_wrp) + INTEGER(kind=c_int) :: return_val + TYPE(ProcessGrid_wrp) :: h_this + + h_this = TRANSFER(ih_this,h_this) + return_val = h_this%data%num_process_rows + END FUNCTION GetNumRows_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Destruct a distributed sparse matrix SUBROUTINE DestructProcessGrid_wrp(ih_this) & diff --git a/UnitTests/test_psmatrix.py b/UnitTests/test_psmatrix.py index c2d32d71..b75cf085 100644 --- a/UnitTests/test_psmatrix.py +++ b/UnitTests/test_psmatrix.py @@ -121,6 +121,24 @@ def check_result(self): global_norm = comm.bcast(normval, root=0) self.assertLessEqual(global_norm, THRESHOLD) + def test_grid(self): + '''Test the simplified process grid interface''' + self.assertEqual(self.process_rows, nt.GetGlobalNumRows()) + self.assertEqual(self.process_columns, nt.GetGlobalNumColumns()) + self.assertEqual(self.process_slices, nt.GetGlobalNumSlices()) + + self.assertEqual(self.process_rows, self.grid.GetNumRows()) + self.assertEqual(self.process_columns, self.grid.GetNumColumns()) + self.assertEqual(self.process_slices, self.grid.GetNumSlices()) + + total_procs = self.process_rows * self.process_columns * \ + self.process_slices + new_grid = nt.ProcessGrid(self.process_slices) + new_total_procs = new_grid.GetNumRows() * new_grid.GetNumColumns() * \ + new_grid.GetNumSlices() + self.assertEqual(total_procs, new_total_procs) + del new_grid + def test_read(self): '''Test our ability to read and write matrices.''' for param in self.parameters: