SST  14.1.0
StructuralSimulationToolkit
coreTest_SharedObjectComponent.h
1 // Copyright 2009-2024 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2024, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_CORETEST_SHAREDOBJECT_H
13 #define SST_CORE_CORETEST_SHAREDOBJECT_H
14 
15 #include "sst/core/component.h"
16 #include "sst/core/output.h"
17 #include "sst/core/shared/sharedArray.h"
18 #include "sst/core/shared/sharedMap.h"
19 #include "sst/core/shared/sharedSet.h"
20 
21 namespace SST {
22 namespace CoreTestSharedObjectsComponent {
23 
24 // Class so that we can check to see if the equivalence check works
25 // for sets
27 {
28  int key;
29  int value;
30 
31  setItem() : key(0), value(0) {}
32 
33  setItem(int key, int value) : key(key), value(value) {}
34 
35  bool operator<(const setItem& lhs) const { return key < lhs.key; }
36 
37  bool operator==(const setItem& lhs) const
38  {
39  if ( key != lhs.key ) return false;
40  if ( value != lhs.value ) return false;
41  return true;
42  }
43 
44  void serialize_order(SST::Core::Serialization::serializer& ser) override
45  {
46  SST_SER(key);
47  SST_SER(value);
48  }
49 
50  ImplementSerializable(SST::CoreTestSharedObjectsComponent::setItem);
51 };
52 
54 {
55 public:
56  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
57  SST_ELI_REGISTER_COMPONENT(
59  "coreTestElement",
60  "coreTestSharedObjectsComponent",
61  SST_ELI_ELEMENT_VERSION(1,0,0),
62  "Test for SharedObjects",
63  COMPONENT_CATEGORY_UNCATEGORIZED
64  )
65 
66  SST_ELI_DOCUMENT_PARAMS(
67  { "object_type", "Type of object to test ( array | map | set )", "array"},
68  { "num_entities", "Number of entities in the sim", "12"},
69  { "myid", "ID Number (0 <= myid < num_entities)", nullptr},
70  { "full_initialization", "If true, id 0 will initialize whole array, otherwise each id will contribute", "true"},
71  { "multiple_initializers", "If doing full_initialization, this will cause ID N-1 to also initialize array", "false"},
72  { "conflicting_write", "Controls whether a conflicting write is done when full_initialization and multiple_initializers are turned on (otherwise it has no effect)", "false"},
73  { "verify_mode", "Sets verify mode for SharedArray ( FE | INIT | NONE )", "INIT" },
74  { "late_write", "Controls whether a late write is done", "false" },
75  { "publish", "Controls whether publish() is called or not", "true"},
76  { "double_initialize", "If true, initialize() will be called twice", "false" },
77  { "late_initialize", "If true, initialize() will be called during setup instead of in constructor", "false" },
78  { "checkpoint", "If true, SharedObject state will be printed in setup() and finish()", "false" }
79  )
80 
81  // Optional since there is nothing to document
82  SST_ELI_DOCUMENT_STATISTICS(
83  )
84 
85  // Optional since there is nothing to document
86  SST_ELI_DOCUMENT_PORTS(
87  {"left", "Link to the component to the left", { "" } },
88  {"right", "Link to the component to the right", { "" } }
89 
90  )
91 
92  // Optional since there is nothing to document
93  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
94  )
95 
96  coreTestSharedObjectsComponent(SST::ComponentId_t id, SST::Params& params);
98 
99  void init(unsigned int phase) override;
100  void setup() override;
101  void finish() override;
102  void complete(unsigned int phase) override;
103 
104  bool tick(SST::Cycle_t);
105 
106  coreTestSharedObjectsComponent() : Component() {} // For serialization ONLY
107  void serialize_order(SST::Core::Serialization::serializer& ser) override;
109 
110 private:
111  Output out;
112 
113  bool test_array;
114  bool test_bool_array;
115  bool test_map;
116  bool test_set;
117 
118  int myid;
119  int num_entities;
120 
121  int count;
122  bool check;
123  bool late_write;
124  bool pub;
125  bool late_initialize;
126  bool checkpoint;
127 
129  Shared::SharedArray<bool> bool_array;
132 };
133 
134 } // namespace CoreTestSharedObjectsComponent
135 } // namespace SST
136 
137 #endif // SST_CORE_CORETEST_SHAREDOBJECT_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:53
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
SharedSet class.
Definition: sharedSet.h:28
Definition: coreTest_SharedObjectComponent.h:53
Main component object for the simulation.
Definition: component.h:30
Definition: action.cc:18
Definition: serializable.h:24
SharedArray class.
Definition: sharedArray.h:423
void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: coreTest_SharedObjectComponent.cc:238
Parameter store.
Definition: params.h:55
Definition: coreTest_SharedObjectComponent.h:26
void finish() override
Called after complete phase, but before objects are destroyed.
Definition: coreTest_SharedObjectComponent.cc:299