Class MsgBruteForce

Nested Relationships

Nested Types

Class Documentation

class MsgBruteForce

Brute force messaging functionality

Every agent accesses all messages This technique is expensive, and other techniques are preferable if operating with more than 1000 messages.

Public Types

typedef MsgNone::size_type size_type

Common size type

class CUDAModelHandler : public MsgSpecialisationHandler

Blank handler, brute force requires no index or special allocations Only stores the length on device

Public Functions

inline explicit CUDAModelHandler(CUDAMessage &a)

Constructor Allocates memory on device for message list length

Parameters

a – Parent CUDAMessage, used to access message settings, data ptrs etc

inline ~CUDAModelHandler()

Destructor. Should free any local host memory (device memory cannot be freed in destructors)

virtual void init(CUDAScatter &scatter, const unsigned int &streamId) override

Allocates memory for the constructed index. Sets data asthough message list is empty

Parameters
  • scatter – Scatter instance and scan arrays to be used (CUDASimulation::singletons->scatter)

  • streamId – The stream index to use for accessing stream specific resources such as scan compaction arrays and buffers

virtual void buildIndex(CUDAScatter &scatter, const unsigned int &streamId, const cudaStream_t &stream) override

Updates the length of the messagelist stored on device

Parameters
  • scatter – Scatter instance and scan arrays to be used (CUDASimulation::singletons->scatter)

  • streamId – The stream index to use for accessing stream specific resources such as scan compaction arrays and buffers

  • stream – CUDA stream to be used for async CUDA operations

virtual void allocateMetaDataDevicePtr() override

Allocates memory for the constructed index. The memory allocation is checked by build index.

virtual void freeMetaDataDevicePtr() override

Releases memory for the constructed index.

inline virtual const void *getMetaDataDevicePtr() const override

Returns a pointer to the metadata struct, this is required for reading the message data

struct Data

This is the internal data store for MessageDescription Users should only access that data stored within via an instance of MessageDescription

Subclassed by MsgArray2D::Data, MsgArray3D::Data, MsgArray::Data, MsgBucket::Data, MsgSpatial2D::Data

Public Functions

virtual ~Data()
bool operator==(const Data &rhs) const

Equality operator, checks whether MessageData hierarchies are functionally the same

Note

Instead compare pointers if you wish to check that they are the same instance

Returns

True when messages are the same

bool operator!=(const Data &rhs) const

Equality operator, checks whether MessageData hierarchies are functionally different

Note

Instead compare pointers if you wish to check that they are not the same instance

Returns

True when messages are not the same

Data(const Data &other) = delete

Default copy constructor, not implemented

virtual std::unique_ptr<MsgSpecialisationHandler> getSpecialisationHander(CUDAMessage &owner) const
virtual std::type_index getType() const

Used internally to validate that the corresponding Msg type is attached via the agent function shim.

Returns

The std::type_index of the Msg type which must be used.

Public Members

VariableMap variables

Holds all of the message’s variable definitions

std::unique_ptr<Description> description

Description class which provides convenient accessors

std::string name

Name of the message, used to refer to the message in many functions

unsigned int optional_outputs

The number of functions that have optional output of this message type This value is modified by AgentFunctionDescription

Protected Functions

virtual Data *clone(const std::shared_ptr<const ModelData> &newParent)
Data(const std::shared_ptr<const ModelData>&, const Data &other)

Copy constructor This is unsafe, should only be used internally, use clone() instead

Data(const std::shared_ptr<const ModelData>&, const std::string &message_name)

Normal constructor, only to be called by ModelDescription

Friends

friend class ModelDescription
friend struct ModelData
class Description

Within the model hierarchy, this class represents the definition of an message for a FLAMEGPU model This class is used to configure external elements of messages, such as variables Base-class, represents brute-force messages Can be extended by more advanced message descriptors

See

MessageData The internal data store for this class

See

ModelDescription::newMessage(const std::string&) For creating instances of this class

Subclassed by MsgArray2D::Description, MsgArray3D::Description, MsgArray::Description, MsgBucket::Description, MsgSpatial2D::Description, MsgSpatial3D::Description

Public Functions

bool operator==(const Description &rhs) const

Equality operator, checks whether MessageDescription hierarchies are functionally the same

Note

Instead compare pointers if you wish to check that they are the same instance

Returns

True when messages are the same

bool operator!=(const Description &rhs) const

Equality operator, checks whether MessageDescription hierarchies are functionally different

Note

Instead compare pointers if you wish to check that they are not the same instance

Returns

True when messages are not the same

template<typename T>
void newVariable(const std::string &variable_name)

Adds a new variable to the message

Template implementation

Parameters

variable_name – Name of the variable

Template Parameters

T – Type of the message variable, this must be an arithmetic type

Throws

InvalidMessageVar – If a variable already exists within the message with the same name

std::string getName() const

Const Accessors

Returns

The message’s name

const std::type_index &getVariableType(const std::string &variable_name) const
Parameters

variable_name – Name used to refer to the desired variable

Throws

InvalidAgentVar – If a variable with the name does not exist within the message

Returns

The type of the named variable

size_t getVariableSize(const std::string &variable_name) const
Parameters

variable_name – Name used to refer to the desired variable

Throws

InvalidAgentVar – If a variable with the name does not exist within the message

Returns

The size of the named variable’s type

size_type getVariablesCount() const
Returns

The total number of variables within the message

bool hasVariable(const std::string &variable_name) const
Parameters

variable_name – Name of the variable to check

Returns

True when a variable with the specified name exists within the message

Protected Functions

Description(const std::shared_ptr<const ModelData> &_model, Data *const data)

Constructors

Description(const Description &other_message) = delete

Default copy constructor, not implemented

Description(Description &&other_message) noexcept = delete

Default move constructor, not implemented

Description &operator=(const Description &other_message) = delete

Default copy assignment, not implemented

Description &operator=(Description &&other_message) noexcept = delete

Default move assignment, not implemented

Protected Attributes

const std::weak_ptr<const ModelData> model

Root of the model hierarchy

Data *const message

The class which stores all of the message’s data.

class In

This class is accessible via DeviceAPI.message_in if MsgBruteForce is specified in FLAMEGPU_AGENT_FUNCTION It gives access to functionality for reading brute force messages

Public Functions

__device__ inline In(Curve::NamespaceHash agentfn_hash, Curve::NamespaceHash msg_hash, const void *metadata)

Constructer Initialises member variables

Parameters
  • agentfn_hash – Added to msg_hash to produce combined_hash

  • msg_hash – Added to agentfn_hash to produce combined_hash

  • metadata – Reinterpreted as type MsgBruteForce::MetaData to extract length

__device__ inline size_type size(void) const

Returns the number of elements in the message list.

__device__ inline iterator begin(void) const

Returns an iterator to the start of the message list

__device__ inline iterator end(void) const

Returns an iterator to the position beyond the end of the message list

class iterator

Stock iterator for iterating MsgBruteForce::In::Message objects

Public Functions

__device__ inline iterator(const In &parent, size_type index)

Constructor This iterator is constructed by MsgBruteForce::begin()

See

MsgBruteForce::begin()

__device__ inline iterator &operator++()

Moves to the next message

__device__ inline bool operator==(const iterator &rhs) const

Equality operator Compares message

__device__ inline bool operator!=(const iterator &rhs) const

Inequality operator Compares message

__device__ inline Message &operator*()

Dereferences the iterator to return the message object, for accessing variables

class Message

Provides access to a specific message Returned by the iterator

See

In::iterator

Public Functions

__device__ inline Message(const MsgBruteForce::In &parent)

Constructs a message and directly initialises all of it’s member variables index is always init to 0

Note

See member variable documentation for their purposes

__device__ inline Message(const MsgBruteForce::In &parent, size_type index)

Alternate constructor, allows index to be manually set

Note

I think this is unused

__host__ __device__ inline bool operator==(const Message &rhs) const

Equality operator Compares all internal member vars for equality

Note

Does not compare _parent

__host__ __device__ inline bool operator!=(const Message &rhs) const

Inequality operator Returns inverse of equality operator

See

operator==(const Message&)

__host__ __device__ inline Message &operator++()

Updates the message to return variables from the next message in the message list

Returns

Returns itself

__host__ __device__ inline size_type getIndex() const

Returns the index of the message within the full message list

template<typename T, size_type N>
__device__ T getVariable(const char (&variable_name)[N]) const

Returns the value for the current message attached to the named variable

Parameters

variable_name – Name of the variable

Template Parameters
  • T – type of the variable

  • N – Length of variable name (this should be implicit if a string literal is passed to variable name)

Returns

The specified variable, else 0x0 if an error occurs

struct MetaData

MetaData required by brute force during message reads

Public Members

unsigned int length = 0
class Out

This class is accessible via DeviceAPI.message_out if MsgBruteForce is specified in FLAMEGPU_AGENT_FUNCTION It gives access to functionality for outputting brute force messages

Subclassed by MsgBucket::Out, MsgSpatial2D::Out, MsgSpatial3D::Out

Public Functions

__device__ inline Out(Curve::NamespaceHash agentfn_hash, Curve::NamespaceHash msg_hash, const void*, unsigned int *scan_flag_messageOutput)

Constructer Initialises member variables

Parameters
  • agentfn_hash – Added to msg_hash to produce combined_hash

  • msg_hash – Added to agentfn_hash to produce combined_hash

  • scan_flag_messageOutput – Scan flag array for optional message output

template<typename T, unsigned int N>
__device__ void setVariable(const char (&variable_name)[N], T value) const

Sets the specified variable for this agents message

Parameters
  • variable_name – Name of the variable

  • value – The value to set the specified variable

Template Parameters
  • T – type of the variable

  • N – Length of variable name (this should be implicit if a string literal is passed to variable name)

Returns

The specified variable, else 0x0 if an error occurs

Protected Attributes

Curve::NamespaceHash combined_hash

CURVE hash for accessing message data agentfn_hash + msg_hash

unsigned int *scan_flag

Scan flag array for optional message output