54 <<
"Perform -= on self: clears all bits" <<
nl;
71 const label thisExtent = (this->
find_last()+1);
72 const label thatExtent = (other.
find_last()+1);
75 if (label common =
std::min(thisExtent, thatExtent); common > 0)
85 for (label blocki = 0; blocki < nblocks; ++blocki)
104 <<
"Perform &= on self: ignore" <<
nl;
114 else if (other.none())
126 const label thisExtent = (this->find_last()+1);
127 const label thatExtent = (other.find_last()+1);
130 if (label common =
std::min(thisExtent, thatExtent); common > 0)
132 nblocks = num_blocks(common);
135 if (thatExtent < thisExtent)
138 const auto origSize = size();
146 const auto&
rhs = other.blocks_;
148 for (label blocki = 0; blocki < nblocks; ++blocki)
150 blocks_[blocki] &=
rhs[blocki];
167 <<
"Perform |= on self: ignore" <<
nl;
172 else if (other.none())
183 const label thisExtent = (this->find_last()+1);
184 const label thatExtent = (other.find_last()+1);
187 if (label common =
std::max(thisExtent, thatExtent); common > 0)
189 nblocks = num_blocks(common);
192 if (size() < thatExtent)
201 const auto&
rhs = other.blocks_;
203 for (label blocki = 0; blocki < nblocks; ++blocki)
205 blocks_[blocki] |=
rhs[blocki];
222 <<
"Perform ^= on self: clears all bits" <<
nl;
228 else if (other.none())
239 const label thisExtent = (this->find_last()+1);
240 const label thatExtent = (other.find_last()+1);
243 if (label common =
std::max(thisExtent, thatExtent); common > 0)
245 nblocks = num_blocks(common);
248 if (size() < thatExtent)
257 const auto&
rhs = other.blocks_;
259 for (label blocki = 0; blocki < nblocks; ++blocki)
261 blocks_[blocki] ^=
rhs[blocki];
283 const label len = addr.
size();
285 for (label i = 0; i < len; ++i)
297 const label len =
range.size();
299 for (label i = 0; i < len; ++i)
328 unsigned bitIdx = 0u;
329 auto* packed = blocks_.data();
332 for (
const auto b :
bools)
336 *packed |= (1u << bitIdx);
350 if (size() && other.size())
352 const label nblocks = num_blocks(
std::min(size(), other.size()));
353 const auto&
rhs = other.blocks_;
355 for (label blocki = 0; blocki < nblocks; ++blocki)
357 if (
bool(blocks_[blocki] &
rhs[blocki]))
370 labelRange slice(
range);
382 if (slice.end_value() >= size())
385 resize(slice.begin_value(),
false);
386 resize(slice.end_value(),
true);
397 unsigned int bblock = slice.begin_value() / elem_per_block;
398 unsigned int bmask = slice.begin_value() % elem_per_block;
401 unsigned int eblock = slice.end_value() / elem_per_block;
402 unsigned int emask = slice.end_value() % elem_per_block;
405 if (bmask) bmask = mask_lower(bmask);
406 if (emask) emask = mask_lower(emask);
408 if (bblock == eblock)
416 blocks_[bblock] |= (emask^bmask);
424 blocks_[bblock] |= (~bmask);
429 for (
unsigned blocki = bblock; blocki < eblock; ++blocki)
431 blocks_[blocki] = (~0u);
438 blocks_[eblock] |= (emask);
447 const labelRange slice =
range.subset0(size());
456 if (slice.end_value() >= size())
459 const label orig = size();
461 resize(slice.begin_value(),
false);
474 unsigned int bblock = slice.begin_value() / elem_per_block;
475 unsigned int bmask = slice.begin_value() % elem_per_block;
478 unsigned int eblock = slice.end_value() / elem_per_block;
479 unsigned int emask = slice.end_value() % elem_per_block;
482 if (bmask) bmask = mask_lower(bmask);
483 if (emask) emask = mask_lower(emask);
485 if (bblock == eblock)
494 blocks_[bblock] &= (~(emask^bmask));
502 blocks_[bblock] &= (bmask);
507 for (
unsigned blocki = bblock; blocki < eblock; ++blocki)
509 blocks_[blocki] = (0u);
516 blocks_[eblock] &= (~emask);
525 const label total =
any() ?
count() : 0;
537 const label nblocks = num_blocks(size());
538 for (label blocki = 0; blocki < nblocks; ++blocki)
540 unsigned int blockval = blocks_[blocki];
544 for (label
pos = (blocki * elem_per_block); blockval; ++
pos)
553 if (nItem == total)
break;
563 List<bool> output(size(),
false);
567 const label nblocks = num_blocks(size());
568 for (label blocki = 0; blocki < nblocks; ++blocki)
570 label
pos = (blocki * elem_per_block);
574 unsigned int blockval = blocks_[blocki];
605 if (communicator < 0)
620 int64_t sizing[2] = { 0, 0 };
625 sizing[0] =
static_cast<int64_t
>(find_last()+1);
626 sizing[1] =
static_cast<int64_t
>(size());
639 nblocks = num_blocks(sizing[0]);
651 if (communicator < 0)
668 int64_t common(find_last()+1);
672 nblocks = num_blocks(common);
677 const auto origSize = size();
689 nblocks = this->num_blocks();
694 UPstream::mpiAllReduce<UPstream::opCodes::op_bit_and>
706 if (communicator < 0)
725 static_cast<int64_t
>(find_last()+1),
726 static_cast<int64_t>(size())
731 nblocks = num_blocks(sizing[0]);
735 if (size() < sizing[1])
750 nblocks = this->num_blocks();
755 UPstream::mpiAllReduce<UPstream::opCodes::op_bit_or>
767 if (communicator < 0)
779 allValues.set(0, localValue);
798 allValues.assign(
bools);
812 if (communicator < 0)
void reduceOr(int communicator=-1, bool syncSizes=true)
Inplace bit_or parallel reduction.
void size(const label n)
Older name for setAddressableSize.
bitSet & orEq(const bitSet &other)
The set logical OR.
void set(const bitSet &bitset)
Set specified bits from another bitset.
bool any(const UList< bool > &bools)
True if any entries are 'true'.
bool none(const UList< bool > &bools)
True if no entries are 'true'.
patchWriters resize(patchIds.size())
void resize(const label len)
Adjust allocated size of list.
label find_last() const
Locate the last bit set.
static bitSet gatherValues(bool localValue, int communicator=-1)
Gather individual values into bitSet locations.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
A range or interval of labels defined by a start and a size.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
T * data() noexcept
Return pointer to the underlying array serving as data storage.
List< bool > values() const
Return the bitset values as a boolList.
static int myProcNo(label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
void broadcast(int communicator=-1, int root=0)
Broadcast the contents.
bitSet & minusEq(const bitSet &other)
The set difference.
static void mpiAllReduce_max(T values[], int count, const int communicator=UPstream::worldComm)
MPI Allreduce max.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
static void mpiAllReduce_min(T values[], int count, const int communicator=UPstream::worldComm)
MPI Allreduce min.
bitSet & xorEq(const bitSet &other)
The set logical XOR.
static void mpiGather(const Type *sendData, Type *recvData, int count, const int communicator=UPstream::worldComm)
Receive identically-sized (contiguous) data from all ranks.
Macros for easy insertion into run-time selection tables.
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
block_type * data() noexcept
A pointer to the raw storage.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dimensionedScalar pos(const dimensionedScalar &ds)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
bitSet & unset(const bitSet &other)
Unset (subtract) the bits specified in the other bitset, which is a set difference corresponds to the...
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
static bool broadcast(Type *buffer, std::streamsize count, const int communicator, const int root=UPstream::masterNo())
Broadcast buffer contents (contiguous types) to all ranks (default: from rank=0). The sizes must matc...
#define FOAM_UNLIKELY(cond)
static bitSet allGather(bool localValue, int communicator=-1)
Allgather individual values into bitSet locations.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
constexpr bitSet() noexcept
Default construct an empty, zero-sized bitSet.
List< bool > bools(const labelHashSet &locations)
Transform the on locations to a boolList, with true for each non-negative location and false for all ...
bitSet & andEq(const bitSet &other)
The set logical AND.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
labelList toc() const
The indices of the on bits as a sorted labelList.
static bool is_parallel(label communicator=worldComm)
True if parallel algorithm or exchange is required.
static label nProcs(label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
triangles reserve(surf.size())
void assign(const UList< bool > &bools)
Copy assign all entries from a list of bools.
bool intersects(const bitSet &other) const
True if any bits in the other bitset intersect (are the same).
static bool master(label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
block_container blocks_
The blocks of raw data.
static constexpr label num_blocks(label numElem) noexcept
Calculate the number of blocks required to _address_ the requested number of elements.
void reset()
Clear all bits but do not adjust the addressable size.
static constexpr unsigned elem_per_block
The number of elements stored per data block.
List< label > labelList
A List of labels.
label num_blocks() const noexcept
The number of internal storage blocks.
unsigned int get(const label i) const
Get value at specified index. A no-op and returns 0 for out-of-range positions (safely/silently ignor...
void reduceAnd(int communicator=-1, bool syncSizes=true)
Inplace bit_and parallel reduction.
bool none() const
True if no bits in this bitset are set.
bitSet bitset(const labelHashSet &locations)
Transform the on locations to a bitSet.
#define InfoInFunction
Report an information message using Foam::Info.