diff --git a/src/LA/system_solvers_split.cpp b/src/LA/system_solvers_split.cpp index dea6cf1195..d6a607e83f 100644 --- a/src/LA/system_solvers_split.cpp +++ b/src/LA/system_solvers_split.cpp @@ -1607,14 +1607,16 @@ void SplitSystemSolver::generateSplitPermutation(long nItems, IS *permutation) c std::size_t nElements = blockSize * nItems; // Create permutations - PetscInt *permutationStorage; - PetscMalloc(nElements * sizeof(PetscInt), &permutationStorage); - + PetscInt elementsGlobalOffset; #if BITPIT_ENABLE_MPI == 1 - long elementsGlobalOffset = blockSize * itemsGlobalOffset; - std::fill_n(permutationStorage, nElements, elementsGlobalOffset); + elementsGlobalOffset = static_cast(blockSize * itemsGlobalOffset); +#else + elementsGlobalOffset = 0; #endif + PetscInt *permutationStorage; + PetscMalloc(nElements * sizeof(PetscInt), &permutationStorage); + PetscInt *splitPermutationStorage = permutationStorage; for (int split = 0; split < nSplits; ++split) { int splitBlockSize = splitBlockSizes[split]; @@ -1623,7 +1625,7 @@ void SplitSystemSolver::generateSplitPermutation(long nItems, IS *permutation) c workspace.resize(nSplitElements); generateSplitIndexes(split, nItems, &workspace); for (std::size_t k = 0; k < nSplitElements; ++k) { - splitPermutationStorage[k] = static_cast(workspace[k]); + splitPermutationStorage[k] = elementsGlobalOffset + static_cast(workspace[k]); } splitPermutationStorage += nSplitElements;