Class Agent#

Class Documentation#

class Agent#

Public Functions

__universal__ inline explicit Agent(const Index localIndex)#

The default constructor.

Parameters:

localIndex – The local index of this Agent within the Agent array on the current device.

__universal__ inline virtual ~Agent()#
__device__ virtual void callMethod(FunctionId functionId, void *arg) = 0#

Called by MASS while executing Agents.callAll(). This is intended to be a switch statement where each user-implemented function is mapped to a funcID, and is passed ‘args’ when called.

Parameters:
  • functionId – The ID of the function to be called.

  • arg – A pointer to the arguments passed to the function.

__device__ inline AgentID getId() const#

Returns the unique id of this Agent.

__device__ inline Index getIndex() const#
__device__ inline Index getLocalIndex() const#

Get the local index of this Agent instance within the Agent array on the current device

__device__ inline void setPlace(Place *place)#

Assigns this Agent to a particular Place (its place of residency).

Parameters:

place – The Place instance to which the Agent is assigned.

__device__ inline Place *getPlace() const#

#

Belows are getters for pre-defined attributes of Agent.#

Gets the Place on which this Agent resides.

__device__ Index getPlaceIndex() const#

Returns the index within the complete Places grid of the Place instance on which this agent resides.

__device__ inline bool isAlive() const#

Returns true if the Agent is in an active state. Returns false if the agent hasn’t been activated yet (extra inactive agents are allocated at simulation start to optimize memory allocation), or if it has already been terminated.

__device__ inline Place *getDestPlace() const#

Gets the destination Place where this Agent is migrating to.

__device__ inline Count32 getNumChildren() const#

Gets the number of children that this Agent is spawning.

__device__ inline Place *getChildrenDestPlace() const#

Gets the destination Place where the children of this Agent are spawning.

__device__ inline void setAlive()#

#

End of getters for pre-defined attributes of Place.#

Sets the Agent’s status to active, thus including the Agent in all callAll() calls.

__device__ void terminate()#

Sets the Agent’s status to inactive. The Agent’s place is set to vacant and the Agent is excluded from all subsequent callAll() function calls.

__device__ void migrate(Place *newDestPlace)#

Current Agent express the intention to migrate to the specified place. The Agent will be added to Place’s potential Migrating Agents list. The actual migration is performed during the subsequent Agents::manageAll() call. The migration is not guaranteed if the destination place is already occupied or if there is a competing agent trying to get to the same destination.

Parameters:

newDestPlace – The destination Place.

__device__ inline void spawn(const Count32 numAgents, Place *const place)#

Spawns the specified number of new agents at the specified place. The function does not accept instantiation arguments due to current limitations of the library. If you need to set some parameters of the newly created Agents, please set these parameters in a separate function after agent creation. The actual spawning is performed during the subsequent Agents::manageAll() call. The spawning is not guaranteed if the destination place is already full or if there is a competing agent trying to spawn at the same place.

Parameters:
  • numAgents – The number of agents to be spawned.

  • place – The Place where the agents will be spawned.

__device__ inline void clearSpawningData()#

Clears the spawning data of the current Agent. This function should be called after the spawning of new agents is completed.

This function will clear the N_CHILDREN & CHILDREN_DEST_PLACE attributes of the current Agent.

template<typename T>
__device__ ArrayAttrPtr<T> getAttribute(AttrTag tag, Count elementCount)#

Resolve the pointer to the value of an attribute identified by the attribute tag

Template Parameters:

T – the type of the attribute value

Parameters:
  • tag – The tag of the attribute.

  • elementCount – The length of the attribute (length set when adding an attribute).

Returns:

A pointer to the attribute value

template<typename T>
__device__ ArrayAttrPtr<const T> getAttribute(AttrTag tag, Count elementCount) const#

Resolve the pointer to the value of an attribute identified by the attribute tag

Template Parameters:

T – the type of the attribute value

Parameters:
  • tag – the tag of the attribute

  • elementCount – the length of the attribute (length set when adding an attribute)

Returns:

A pointer to the attribute value

template<typename T>
__device__ AttrPtr<const T> getAttribute(AttrTag tag) const#

Resolve the pointer to the value of an attribute identified by the attribute tag, where the attribute should have elementCount == 1.

Template Parameters:

T – the type of the attribute value

Parameters:

tag – the tag of the attribute

Returns:

A pointer to the attribute value

template<typename T>
__device__ AttrPtr<T> getAttribute(AttrTag tag)#

Resolve the pointer to the value of an attribute identified by the attribute tag, where the attribute should have elementCount == 1.

Template Parameters:

T – the type of the attribute value

Parameters:

tag – the tag of the attribute

Returns:

A pointer to the attribute value

template<typename T>
__device__ ArrayAttrPtr<T> getArrAttribute(AttrTag tag)#

Resolve the pointer to the value of an attribute identified by the attribute tag, where the attribute should have elementCount > 1.

Template Parameters:

T – the type of each element of the attribute

Parameters:

tag – the tag of the attribute

Returns:

A pointer to the attribute value

template<typename T>
__device__ ArrayAttrPtr<const T> getArrAttribute(AttrTag tag) const#

Resolve the pointer to the value of an attribute identified by the attribute tag, where the attribute should have elementCount > 1.

Template Parameters:

T – the type of each element of the attribute

Parameters:

tag – the tag of the attribute

Returns:

A pointer to the attribute value

template<typename T>
__device__ AttrPtr<const T> getSharedAttribute(AttrTag tag) const#

Resolve the pointer to the value of a shared attribute identified by the attribute tag, where the attribute should have elementCount == 1.

Template Parameters:

T – the type of the attribute value

Parameters:

tag – the tag of the attribute

Returns:

A pointer to the attribute value

template<typename T>
__device__ ArrayAttrPtr<const T, byteCountOf(T)> getSharedArrAttribute(AttrTag tag) const#

Resolve the pointer to the value of a shared attribute identified by the attribute tag, where the attribute should have elementCount > 1.

Template Parameters:

T – the type of each element of the attribute

Parameters:

tag – the tag of the attribute

Returns:

A pointer to the attribute value

template<typename T>
__device__ ArrayAttrPtr<T> getAttribute(Index destLocalIndex, AttrTag tag, Count elementCount) const#

Get an attribute of another Place by attribute tag (name set by user when adding an attribute). For more information about the tag and length, please refer to Places::setAttribute().

Parameters:
  • destLocalIndex – The index of the destination Place.

  • tag – The tag of the attribute.

  • elementCount – The length of the attribute (length set when adding an attribute).

Returns:

A pointer to the attribute, whether 1D or 2D.

__device__ inline void initMeta(const internal::EntityDeviceMeta *const entityMeta)#

Initialize this Place instance with the pointer to the shared metadata structure on device

Parameters:

entityMeta – pointer to the shared metadata structure