diff --git a/components/omega/src/base/Decomp.cpp b/components/omega/src/base/Decomp.cpp index 9a705b0bb7a1..24326ba7cfef 100644 --- a/components/omega/src/base/Decomp.cpp +++ b/components/omega/src/base/Decomp.cpp @@ -425,29 +425,37 @@ Decomp::Decomp( // Close file Err = IO::closeFile(FileID); - // Use the mesh adjacency information to create a partition of cells - switch (Method) { // branch depending on method chosen + // In the case of single task avoid calling a full partitioning routine and + // just set the needed variables directly. This is done because some METIS + // functions can raise SIGFPE when numparts == 1 due to division by zero + // See: https://github.com/KarypisLab/METIS/issues/67 + if (NumTasks == 1) { + partCellsSingleTask(); + } else { + // Use the mesh adjacency information to create a partition of cells + switch (Method) { // branch depending on method chosen - //--------------------------------------------------------------------------- - // ParMetis KWay method - case PartMethodMetisKWay: { + //--------------------------------------------------------------------------- + // ParMetis KWay method + case PartMethodMetisKWay: { - Err = partCellsKWay(InEnv, CellsOnCellInit); - if (Err != 0) { - LOG_CRITICAL("Decomp: Error partitioning cells KWay"); - return; - } - break; - } // end case MethodKWay + Err = partCellsKWay(InEnv, CellsOnCellInit); + if (Err != 0) { + LOG_CRITICAL("Decomp: Error partitioning cells KWay"); + return; + } + break; + } // end case MethodKWay - //--------------------------------------------------------------------------- - // Unknown partitioning method + //--------------------------------------------------------------------------- + // Unknown partitioning method - default: - LOG_CRITICAL("Decomp: Unknown or unsupported decomposition method"); - return; + default: + LOG_CRITICAL("Decomp: Unknown or unsupported decomposition method"); + return; - } // End switch on Method + } // End switch on Method + } //--------------------------------------------------------------------------- @@ -766,6 +774,32 @@ Decomp *Decomp::get(const std::string Name ///< [in] Name of environment } // end get Decomposition +//------------------------------------------------------------------------------ +// Trivially partition cells in the case of single task +// It sets the NCells sizes (NCellsOwned, +// NCellsHalo array, NCellsAll and NCellsSize) and the final CellID +// and CellLoc arrays +void Decomp::partCellsSingleTask() { + + NCellsOwned = NCellsGlobal; + + NCellsHaloH = HostArray1DI4("NCellsHalo", HaloWidth); + for (int Halo = 0; Halo < HaloWidth; ++Halo) { + NCellsHaloH(Halo) = NCellsGlobal; + } + + NCellsAll = NCellsGlobal; + NCellsSize = NCellsGlobal + 1; + + CellIDH = HostArray1DI4("CellID", NCellsSize); + CellLocH = HostArray2DI4("CellLoc", NCellsSize, 2); + for (int Cell = 0; Cell < NCellsAll; ++Cell) { + CellIDH(Cell) = Cell + 1; + CellLocH(Cell, 0) = 0; + CellLocH(Cell, 1) = Cell; + } +} // end function partCellsSingleTask + //------------------------------------------------------------------------------ // Partition the cells using the Metis/ParMetis KWay method // After this partitioning, the decomposition class member CellID and diff --git a/components/omega/src/base/Decomp.h b/components/omega/src/base/Decomp.h index c3b662e00442..f968ccd1dc80 100644 --- a/components/omega/src/base/Decomp.h +++ b/components/omega/src/base/Decomp.h @@ -75,6 +75,12 @@ class Decomp { const std::vector &CellsOnCellInit ///< [in] cell nbrs in init dstrb ); + /// Trivially partition cells in the case of single task + /// It sets the NCells sizes (NCellsOwned, + /// NCellsHalo array, NCellsAll and NCellsSize) and the final CellID + /// and CellLoc arrays + void partCellsSingleTask(); + /// Partition the edges given the cell partition and edge connectivity /// The first cell ID associated with an edge in the CellsOnEdge array /// is assumed to own the edge. The inputs are the edge-cell connectivity diff --git a/components/omega/test/CMakeLists.txt b/components/omega/test/CMakeLists.txt index 011193e55b06..00606d486c17 100644 --- a/components/omega/test/CMakeLists.txt +++ b/components/omega/test/CMakeLists.txt @@ -80,13 +80,24 @@ add_omega_test( "-n;8" ) -############# -# Decomp test -############# +########################## +# Decomp test using 1 task +########################## + +add_omega_test( + DECOMP_NTASK1_TEST + testDecompNTask1.exe + base/DecompTest.cpp + "-n;1" +) + +########################### +# Decomp test using 8 tasks +########################### add_omega_test( - DECOMP_TEST - testDecomp.exe + DECOMP_NTASK8_TEST + testDecompNTask8.exe base/DecompTest.cpp "-n;8" )