Commit c3737c72 authored by Matthew Letter's avatar Matthew Letter
Browse files

Merge branch 'master' into increase-worklet-arguments

parents d9c51d65 84201902
......@@ -14,4 +14,4 @@ data/* filter=lfs diff=lfs merge=lfs -text
*.rst whitespace=tab-in-indent conflict-marker-size=79
*.txt whitespace=tab-in-indent
diy/** -format.clang-format -whitespace
vtkm/thirdparty/diy/vtkmdiy/** -format.clang-format -whitespace
......@@ -39,9 +39,7 @@ set(FILES_TO_CHECK
set(EXCEPTIONS
LICENSE.txt
README.txt
diy/include/diy
diy/LEGAL.txt
diy/LICENSE.txt
vtkm/thirdparty/diy/vtkmdiy
)
if (NOT VTKm_SOURCE_DIR)
......
......@@ -39,11 +39,21 @@ set(FILES_TO_CHECK
set(EXCEPTIONS
)
set(DIRECTORY_EXCEPTIONS
${VTKm_SOURCE_DIR}/vtkm/thirdparty/diy/vtkmdiy
)
if (NOT VTKm_SOURCE_DIR)
message(SEND_ERROR "VTKm_SOURCE_DIR not defined.")
endif (NOT VTKm_SOURCE_DIR)
function(check_directory directory parent_CMakeLists_contents)
foreach(exception IN LISTS DIRECTORY_EXCEPTIONS)
if(directory MATCHES "^${exception}$")
return()
endif()
endforeach(exception)
message("Checking directory ${directory}...")
get_filename_component(directory_name "${directory}" NAME)
......
......@@ -221,11 +221,6 @@ find_package(Pyexpander)
#-----------------------------------------------------------------------------
# Add subdirectories
if(VTKm_ENABLE_MPI)
# This `if` is temporary and will be removed once `diy` supports building
# without MPI.
add_subdirectory(diy)
endif()
add_subdirectory(vtkm)
#-----------------------------------------------------------------------------
......
......@@ -20,4 +20,7 @@
list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
".*warning: ignoring loop annotation.*"
)
".*diy.include.diy.*WShadow.*" # exclude `diy` shadow warnings.
".*diy.include.diy.*note: shadowed.*" # exclude `diy` shadow warnings.
".*diy.include.diy.storage.hpp.*Wunused-result.*" # this is a TODO in DIY.
)
......@@ -35,6 +35,11 @@ target_link_libraries(CosmoHaloFinder_SERIAL PRIVATE ${VTKm_LIBRARIES})
target_compile_options(CosmoHaloFinder_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
if(VTKm_CUDA_FOUND)
set(old_nvcc_flags ${CUDA_NVCC_FLAGS})
set(old_cxx_flags ${CMAKE_CXX_FLAGS})
vtkm_setup_nvcc_flags( old_nvcc_flags old_cxx_flags)
vtkm_disable_troublesome_thrust_warnings()
# Cuda compiles do not respect target_include_directories
cuda_include_directories(${VTKm_INCLUDE_DIRS})
......@@ -47,6 +52,9 @@ if(VTKm_CUDA_FOUND)
target_include_directories(CosmoHaloFinder_CUDA PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(CosmoHaloFinder_CUDA PRIVATE ${VTKm_LIBRARIES})
target_compile_options(CosmoHaloFinder_CUDA PRIVATE ${VTKm_COMPILE_OPTIONS})
set(CUDA_NVCC_FLAGS ${old_nvcc_flags})
set(CMAKE_CXX_FLAGS ${old_cxx_flags})
endif()
if(VTKm_TBB_FOUND)
......
......@@ -28,6 +28,12 @@ find_package(VTKm QUIET REQUIRED
if(VTKm_OSMesa_FOUND AND VTKm_Rendering_FOUND)
if(VTKm_CUDA_FOUND)
set(old_nvcc_flags ${CUDA_NVCC_FLAGS})
set(old_cxx_flags ${CMAKE_CXX_FLAGS})
vtkm_setup_nvcc_flags( old_nvcc_flags old_cxx_flags)
vtkm_disable_troublesome_thrust_warnings()
# Cuda compiles do not respect target_include_directories
cuda_include_directories(${VTKm_INCLUDE_DIRS})
cuda_add_executable(Demo Demo.cu)
......
......@@ -29,7 +29,16 @@ find_package(VTKm REQUIRED
)
if(VTKm_CUDA_FOUND)
set(old_nvcc_flags ${CUDA_NVCC_FLAGS})
set(old_cxx_flags ${CMAKE_CXX_FLAGS})
vtkm_setup_nvcc_flags( old_nvcc_flags old_cxx_flags)
vtkm_disable_troublesome_thrust_warnings()
cuda_add_executable(GameOfLife GameOfLife.cu LoadShaders.h)
set(CUDA_NVCC_FLAGS ${old_nvcc_flags})
set(CMAKE_CXX_FLAGS ${old_cxx_flags})
else()
add_executable(GameOfLife GameOfLife.cxx LoadShaders.h)
endif()
......
......@@ -45,6 +45,9 @@ struct Bounds
VTKM_EXEC_CONT
Bounds() {}
VTKM_EXEC_CONT
Bounds(const Bounds&) = default;
VTKM_EXEC_CONT
Bounds(const vtkm::Range& xRange, const vtkm::Range& yRange, const vtkm::Range& zRange)
: X(xRange)
......@@ -89,13 +92,7 @@ struct Bounds
}
VTKM_EXEC_CONT
const vtkm::Bounds& operator=(const vtkm::Bounds& src)
{
this->X = src.X;
this->Y = src.Y;
this->Z = src.Z;
return *this;
}
vtkm::Bounds& operator=(const vtkm::Bounds& src) = default;
/// \b Determine if the bounds are valid (i.e. has at least one valid point).
///
......
......@@ -67,6 +67,11 @@ vtkm_declare_headers(${headers})
#-----------------------------------------------------------------------------
#first add all the components vtkm that are shared between control and exec
if(VTKm_ENABLE_MPI)
# This `if` is temporary and will be removed once `diy` supports building
# without MPI.
add_subdirectory(thirdparty/diy)
endif()
add_subdirectory(testing)
add_subdirectory(internal)
......
......@@ -2347,7 +2347,12 @@ static inline VTKM_EXEC_CONT vtkm::Float32 RemainderQuotient(vtkm::Float32 numer
QType& quotient)
{
int iQuotient;
vtkm::Float32 result = std::remquo(numerator, denominator, &iQuotient);
#ifdef VTKM_CUDA
const vtkm::Float64 result =
VTKM_CUDA_MATH_FUNCTION_32(remquo)(numerator, denominator, &iQuotient);
#else
const vtkm::Float32 result = std::remquo(numerator, denominator, &iQuotient);
#endif
quotient = iQuotient;
return result;
}
......@@ -2357,7 +2362,12 @@ static inline VTKM_EXEC_CONT vtkm::Float64 RemainderQuotient(vtkm::Float64 numer
QType& quotient)
{
int iQuotient;
vtkm::Float64 result = std::remquo(numerator, denominator, &iQuotient);
#ifdef VTKM_CUDA
const vtkm::Float64 result =
VTKM_CUDA_MATH_FUNCTION_64(remquo)(numerator, denominator, &iQuotient);
#else
const vtkm::Float64 result = std::remquo(numerator, denominator, &iQuotient);
#endif
quotient = iQuotient;
return result;
}
......
......@@ -49,6 +49,9 @@ struct Range
{
}
VTKM_EXEC_CONT
Range(const Range&) = default;
template <typename T1, typename T2>
VTKM_EXEC_CONT Range(const T1& min, const T2& max)
: Min(static_cast<vtkm::Float64>(min))
......@@ -57,12 +60,7 @@ struct Range
}
VTKM_EXEC_CONT
const vtkm::Range& operator=(const vtkm::Range& src)
{
this->Min = src.Min;
this->Max = src.Max;
return *this;
}
vtkm::Range& operator=(const vtkm::Range& src) = default;
/// \b Determine if the range is valid (i.e. has at least one valid point).
///
......
......@@ -516,22 +516,6 @@ public:
VTKM_EXEC_CONT
bool operator!=(const DerivedClass& other) const { return !(this->operator==(other)); }
VTKM_EXEC_CONT
ComponentType Dot(const VecBaseCommon<ComponentType, DerivedClass>& other) const
{
// Why the static_cast here and below? Because * on small integers (char,
// short) promotes the result to a 32-bit int. After helpfully promoting
// the width of the result, some compilers then warn you about casting it
// back to the type you were expecting in the first place. The static_cast
// suppresses this warning.
ComponentType result = static_cast<ComponentType>(this->Component(0) * other.Component(0));
for (vtkm::IdComponent i = 1; i < this->NumComponents(); ++i)
{
result = static_cast<ComponentType>(result + this->Component(i) * other.Component(i));
}
return result;
}
#if (!(defined(VTKM_CUDA) && (__CUDACC_VER_MAJOR__ < 8)))
#if (defined(VTKM_GCC) || defined(VTKM_CLANG))
#pragma GCC diagnostic push
......@@ -1241,46 +1225,85 @@ VTKM_EXEC_CONT static inline vtkm::VecCConst<T> make_VecC(const T* array, vtkm::
return vtkm::VecCConst<T>(array, size);
}
// A pre-declaration of vtkm::Pair so that classes templated on them can refer
// to it. The actual implementation is in vtkm/Pair.h.
template <typename U, typename V>
struct Pair;
namespace detail
{
template <typename T>
struct DotType
{
//results when < 32bit can be float if somehow we are using float16/float8, otherwise is
// int32 or uint32 depending on if it signed or not.
using float_type = vtkm::Float32;
using integer_type =
typename std::conditional<std::is_signed<T>::value, vtkm::Int32, vtkm::UInt32>::type;
using promote_type =
typename std::conditional<std::is_integral<T>::value, integer_type, float_type>::type;
using type =
typename std::conditional<(sizeof(T) < sizeof(vtkm::Float32)), promote_type, T>::type;
};
template <typename T>
static inline VTKM_EXEC_CONT typename DotType<typename T::ComponentType>::type vec_dot(const T& a,
const T& b)
{
using U = typename DotType<typename T::ComponentType>::type;
U result = a[0] * b[0];
for (vtkm::IdComponent i = 1; i < a.GetNumberOfComponents(); ++i)
{
result = result + a[i] * b[i];
}
return result;
}
template <typename T, vtkm::IdComponent Size>
static inline VTKM_EXEC_CONT T dot(const vtkm::Vec<T, Size>& a, const vtkm::Vec<T, Size>& b)
static inline VTKM_EXEC_CONT typename DotType<T>::type vec_dot(const vtkm::Vec<T, Size>& a,
const vtkm::Vec<T, Size>& b)
{
T result = T(a[0] * b[0]);
using U = typename DotType<T>::type;
U result = a[0] * b[0];
for (vtkm::IdComponent i = 1; i < Size; ++i)
{
result = T(result + a[i] * b[i]);
result = result + a[i] * b[i];
}
return result;
}
}
template <typename T>
static inline VTKM_EXEC_CONT T dot(const vtkm::Vec<T, 2>& a, const vtkm::Vec<T, 2>& b)
static inline VTKM_EXEC_CONT auto dot(const T& a, const T& b) -> decltype(detail::vec_dot(a, b))
{
return T((a[0] * b[0]) + (a[1] * b[1]));
return detail::vec_dot(a, b);
}
template <typename T>
static inline VTKM_EXEC_CONT T dot(const vtkm::Vec<T, 3>& a, const vtkm::Vec<T, 3>& b)
static inline VTKM_EXEC_CONT typename detail::DotType<T>::type dot(const vtkm::Vec<T, 2>& a,
const vtkm::Vec<T, 2>& b)
{
return T((a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]));
return (a[0] * b[0]) + (a[1] * b[1]);
}
template <typename T>
static inline VTKM_EXEC_CONT T dot(const vtkm::Vec<T, 4>& a, const vtkm::Vec<T, 4>& b)
static inline VTKM_EXEC_CONT typename detail::DotType<T>::type dot(const vtkm::Vec<T, 3>& a,
const vtkm::Vec<T, 3>& b)
{
return T((a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]));
return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]);
}
template <typename T, typename VecType>
static inline VTKM_EXEC_CONT T dot(const vtkm::detail::VecBaseCommon<T, VecType>& a,
const vtkm::detail::VecBaseCommon<T, VecType>& b)
template <typename T>
static inline VTKM_EXEC_CONT typename detail::DotType<T>::type dot(const vtkm::Vec<T, 4>& a,
const vtkm::Vec<T, 4>& b)
{
return a.Dot(b);
return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]);
}
// Integer types of a width less than an integer get implicitly casted to
// an integer when doing a multiplication.
#define VTK_M_SCALAR_DOT(stype) \
static inline VTKM_EXEC_CONT detail::DotType<stype>::type dot(stype a, stype b) { return a * b; }
VTK_M_SCALAR_DOT(vtkm::Int8)
VTK_M_SCALAR_DOT(vtkm::UInt8)
VTK_M_SCALAR_DOT(vtkm::Int16)
VTK_M_SCALAR_DOT(vtkm::UInt16)
VTK_M_SCALAR_DOT(vtkm::Int32)
VTK_M_SCALAR_DOT(vtkm::UInt32)
VTK_M_SCALAR_DOT(vtkm::Int64)
VTK_M_SCALAR_DOT(vtkm::UInt64)
VTK_M_SCALAR_DOT(vtkm::Float32)
VTK_M_SCALAR_DOT(vtkm::Float64)
template <typename T, vtkm::IdComponent Size>
VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec<T, Size>& a)
......@@ -1340,22 +1363,10 @@ VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec<T, 4>& a)
return a[0] * a[1] * a[2] * a[3];
}
// Integer types of a width less than an integer get implicitly casted to
// an integer when doing a multiplication.
#define VTK_M_INTEGER_PROMOTION_SCALAR_DOT(type) \
static inline VTKM_EXEC_CONT type dot(type a, type b) { return static_cast<type>(a * b); }
VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::Int8)
VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::UInt8)
VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::Int16)
VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::UInt16)
#define VTK_M_SCALAR_DOT(type) \
static inline VTKM_EXEC_CONT type dot(type a, type b) { return a * b; }
VTK_M_SCALAR_DOT(vtkm::Int32)
VTK_M_SCALAR_DOT(vtkm::UInt32)
VTK_M_SCALAR_DOT(vtkm::Int64)
VTK_M_SCALAR_DOT(vtkm::UInt64)
VTK_M_SCALAR_DOT(vtkm::Float32)
VTK_M_SCALAR_DOT(vtkm::Float64)
// A pre-declaration of vtkm::Pair so that classes templated on them can refer
// to it. The actual implementation is in vtkm/Pair.h.
template <typename U, typename V>
struct Pair;
} // End of namespace vtkm
......
......@@ -80,8 +80,8 @@ struct MeasureCopySpeed
VTKM_CONT std::string Description() const
{
vtkm::UInt64 actualSize =
static_cast<vtkm::UInt64>(this->Source.GetNumberOfValues() * sizeof(ValueType));
vtkm::UInt64 actualSize = sizeof(ValueType);
actualSize *= static_cast<vtkm::UInt64>(this->Source.GetNumberOfValues());
std::ostringstream out;
out << "Copying " << HumanSize(this->NumBytes) << " (actual=" << HumanSize(actualSize)
<< ") of " << vtkm::testing::TypeName<ValueType>::Name() << "\n";
......
......@@ -108,7 +108,7 @@ struct BenchDevAlgoConfig
/// @note FixBytes and FixSizes are not mutually exclusive. If both are
/// specified, both will run.
bool TestArraySizeValues{ false };
vtkm::Id ArraySizeValues{ 1 << 21 };
vtkm::UInt64 ArraySizeValues{ 1 << 21 };
/// If true, operations like "Unique" will test with a wider range of unique
/// values (5%, 10%, 15%, 20%, 25%, 30%, 35%, 40%, 45%, 50%, 75%, 100%
......@@ -126,7 +126,7 @@ struct BenchDevAlgoConfig
{
return this->DoByteSizes
? static_cast<vtkm::Id>(this->ArraySizeBytes / static_cast<vtkm::UInt64>(sizeof(T)))
: this->ArraySizeValues;
: static_cast<vtkm::Id>(this->ArraySizeValues);
}
};
......@@ -291,8 +291,8 @@ private:
{
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "Copy " << arraySize << " values (" << HumanSize(arraySize * sizeof(Value))
<< ")";
description << "Copy " << arraySize << " values ("
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......@@ -337,8 +337,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "CopyIf on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ") with " << PERCENT_VALID
<< "% valid values";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
<< PERCENT_VALID << "% valid values";
return description.str();
}
};
......@@ -393,8 +393,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "LowerBounds on " << arraySize << " input values ("
<< "(" << HumanSize(arraySize * sizeof(Value)) << ") (" << PERCENT_VALUES
<< "% configuration)";
<< "(" << HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") ("
<< PERCENT_VALUES << "% configuration)";
return description.str();
}
};
......@@ -451,7 +451,7 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "Reduce on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ")";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......@@ -496,8 +496,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "ReduceByKey on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ") with " << N_KEYS << " ("
<< PERCENT_KEYS << "%) distinct vtkm::Id keys";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
<< N_KEYS << " (" << PERCENT_KEYS << "%) distinct vtkm::Id keys";
return description.str();
}
};
......@@ -543,7 +543,7 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "ScanInclusive on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ")";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......@@ -579,7 +579,7 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "ScanExclusive on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ")";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......@@ -621,7 +621,7 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "Sort on " << arraySize << " random values ("
<< HumanSize(arraySize * sizeof(Value)) << ")";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......@@ -674,8 +674,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "SortByKey on " << arraySize << " random values ("
<< HumanSize(arraySize * sizeof(Value)) << ") with " << N_KEYS << " ("
<< PERCENT_KEYS << "%) different vtkm::Id keys";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
<< N_KEYS << " (" << PERCENT_KEYS << "%) different vtkm::Id keys";
return description.str();
}
};
......@@ -731,7 +731,7 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "StableSortIndices::Sort on " << arraySize << " random values ("
<< HumanSize(arraySize * sizeof(Value)) << ")";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......@@ -775,8 +775,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "StableSortIndices::Unique on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ") with " << this->N_VALID << " ("
<< PERCENT_VALID << "%) valid values";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
<< this->N_VALID << " (" << PERCENT_VALID << "%) valid values";
return description.str();
}
};
......@@ -831,8 +831,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "Unique on " << arraySize << " values ("
<< HumanSize(arraySize * sizeof(Value)) << ") with " << N_VALID << " ("
<< PERCENT_VALID << "%) valid values";
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ") with "
<< N_VALID << " (" << PERCENT_VALID << "%) valid values";
return description.str();
}
};
......@@ -887,8 +887,8 @@ private:
vtkm::Id arraySize = Config.ComputeSize<Value>();
std::stringstream description;
description << "UpperBounds on " << arraySize << " input and " << N_VALS << " ("
<< PERCENT_VALS
<< "%) values (input array size: " << HumanSize(arraySize * sizeof(Value)) << ")";
<< PERCENT_VALS << "%) values (input array size: "
<< HumanSize(static_cast<vtkm::UInt64>(arraySize) * sizeof(Value)) << ")";
return description.str();
}
};
......
......@@ -107,7 +107,6 @@ VTKM_MAKE_BENCHMARK(RayTracing, BenchRayTracing);
int main(int, char* [])
{
using TestTypes = vtkm::ListTagBase<vtkm::Float32>;
VTKM_RUN_BENCHMARK(RayTracing, vtkm::ListTagBase<vtkm::Float32>());
return 0;
}
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/AssignerMultiBlock.h>
#if defined(VTKM_ENABLE_MPI)
// clang-format off
#include <vtkm/cont/EnvironmentTracker.h>
#include VTKM_DIY(diy/mpi.hpp)
// clang-format on
#include <algorithm> // std::lower_bound
#include <numeric> // std::iota
namespace vtkm
{
namespace cont
{
VTKM_CONT
AssignerMultiBlock::AssignerMultiBlock(const vtkm::cont::MultiBlock& mb)
: diy::Assigner(vtkm::cont::EnvironmentTracker::GetCommunicator().size(), 1)
, IScanBlockCounts()
{
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
const auto nblocks = mb.GetNumberOfBlocks();
vtkm::Id iscan;
diy::mpi::scan(comm, nblocks, iscan, std::plus<vtkm::Id>());
diy::mpi::all_gather(comm, iscan, this->IScanBlockCounts);
this->set_nblocks(static_cast<int>(this->IScanBlockCounts.back()));
}
VTKM_CONT
void AssignerMultiBlock::local_gids(int rank, std::vector<int>& gids) const
{
if (rank == 0)
{
assert(this->IScanBlockCounts.size() > 0);
gids.resize(this->IScanBlockCounts[rank]);
std::iota(gids.begin(), gids.end(), 0);
}
else if (rank > 0 && rank < static_cast<int>(this->IScanBlockCounts.size()))
{