Program Listing for File MessageArray3DHost.h

Return to documentation for file (include/flamegpu/runtime/messaging/MessageArray3D/MessageArray3DHost.h)

#ifndef INCLUDE_FLAMEGPU_RUNTIME_MESSAGING_MESSAGEARRAY3D_MESSAGEARRAY3DHOST_H_
#define INCLUDE_FLAMEGPU_RUNTIME_MESSAGING_MESSAGEARRAY3D_MESSAGEARRAY3DHOST_H_

#include <string>
#include <memory>
#include <array>

#include "flamegpu/model/Variable.h"
#include "flamegpu/runtime/messaging/MessageArray3D.h"
#include "flamegpu/runtime/messaging/MessageBruteForce/MessageBruteForceHost.h"


namespace flamegpu {

class MessageArray3D::CUDAModelHandler : public MessageSpecialisationHandler {
 public:
     explicit CUDAModelHandler(detail::CUDAMessage &a);
    ~CUDAModelHandler() { }
    void init(detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream) override;
    void buildIndex(detail::CUDAScatter &scatter, unsigned int streamId, cudaStream_t stream) override;
    void allocateMetaDataDevicePtr(cudaStream_t stream) override;
    void freeMetaDataDevicePtr() override;
    const void *getMetaDataDevicePtr() const override { return d_metadata; }

 private:
    MetaData hd_metadata;
    MetaData *d_metadata;
    detail::CUDAMessage &sim_message;
    unsigned int *d_write_flag;
    size_type d_write_flag_len;
};

struct MessageArray3D::Data : public MessageBruteForce::Data {
    friend class ModelDescription;
    friend struct ModelData;
    std::array<size_type, 3> dimensions;
    virtual ~Data() = default;

    std::unique_ptr<MessageSpecialisationHandler> getSpecialisationHander(detail::CUDAMessage &owner) const override;

    std::type_index getType() const override;

 protected:
    Data *clone(const std::shared_ptr<const ModelData> & newParent) override;
    Data(std::shared_ptr<const ModelData> model, const Data &other);
    Data(std::shared_ptr<const ModelData> model, const std::string &message_name);
};

class MessageArray3D::CDescription : public MessageBruteForce::CDescription {
    friend struct Data;

 public:
    explicit CDescription(std::shared_ptr<Data> data);
    explicit CDescription(std::shared_ptr<const Data> data);
    CDescription(const CDescription& other_agent) = default;
    CDescription(CDescription&& other_agent) = default;
    CDescription& operator=(const CDescription& other_agent) = default;
    CDescription& operator=(CDescription&& other_agent) = default;
    bool operator==(const CDescription& rhs) const;
    bool operator!=(const CDescription& rhs) const;

    std::array<size_type, 3> getDimensions() const;
    size_type getDimX() const;
    size_type getDimY() const;
    size_type getDimZ() const;
};
class MessageArray3D::Description : public CDescription {
 public:
    explicit Description(std::shared_ptr<Data> data);
    Description(const Description& other_message) = default;
    Description(Description&& other_message) = default;
    Description& operator=(const Description& other_message) = default;
    Description& operator=(Description&& other_message) = default;

    using MessageBruteForce::CDescription::setPersistent;
    using MessageBruteForce::CDescription::newVariable;
#ifdef SWIG
    using MessageBruteForce::CDescription::newVariableArray;
#endif
    void setDimensions(size_type len_x, size_type len_y, size_type len_Z);
    void setDimensions(const std::array<size_type, 3> &dims);
};

}  // namespace flamegpu

#endif  // INCLUDE_FLAMEGPU_RUNTIME_MESSAGING_MESSAGEARRAY3D_MESSAGEARRAY3DHOST_H_