SST  15.1.0
StructuralSimulationToolkit
coreTest_SharedObjectComponent.h
1 // Copyright 2009-2025 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-2025, 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 
22 
23 // Class so that we can check to see if the equivalence check works
24 // for sets
26 {
27  int key;
28  int value;
29 
30  setItem() :
31  key(0),
32  value(0)
33  {}
34 
35  setItem(int key, int value) :
36  key(key),
37  value(value)
38  {}
39 
40  bool operator<(const setItem& lhs) const { return key < lhs.key; }
41 
42  bool operator==(const setItem& lhs) const
43  {
44  if ( key != lhs.key ) return false;
45  if ( value != lhs.value ) return false;
46  return true;
47  }
48 
49  void serialize_order(SST::Core::Serialization::serializer& ser) override
50  {
51  SST_SER(key);
52  SST_SER(value);
53  }
54 
55  ImplementSerializable(SST::CoreTestSharedObjectsComponent::setItem);
56 };
57 
59 {
60 public:
61  // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
62  SST_ELI_REGISTER_COMPONENT(
64  "coreTestElement",
65  "coreTestSharedObjectsComponent",
66  SST_ELI_ELEMENT_VERSION(1,0,0),
67  "Test for SharedObjects",
68  COMPONENT_CATEGORY_UNCATEGORIZED
69  )
70 
71  SST_ELI_DOCUMENT_PARAMS(
72  { "object_type", "Type of object to test ( array | map | set )", "array"},
73  { "num_entities", "Number of entities in the sim", "12"},
74  { "myid", "ID Number (0 <= myid < num_entities)", nullptr},
75  { "full_initialization", "If true, id 0 will initialize whole array, otherwise each id will contribute", "true"},
76  { "multiple_initializers", "If doing full_initialization, this will cause ID N-1 to also initialize array", "false"},
77  { "conflicting_write", "Controls whether a conflicting write is done when full_initialization and multiple_initializers are turned on (otherwise it has no effect)", "false"},
78  { "verify_mode", "Sets verify mode for SharedArray ( FE | INIT | NONE )", "INIT" },
79  { "late_write", "Controls whether a late write is done", "false" },
80  { "publish", "Controls whether publish() is called or not", "true"},
81  { "double_initialize", "If true, initialize() will be called twice", "false" },
82  { "late_initialize", "If true, initialize() will be called during setup instead of in constructor", "false" },
83  { "checkpoint", "If true, SharedObject state will be printed in setup() and finish()", "false" }
84  )
85 
86  // Optional since there is nothing to document
87  SST_ELI_DOCUMENT_STATISTICS(
88  )
89 
90  // Optional since there is nothing to document
91  SST_ELI_DOCUMENT_PORTS(
92  {"left", "Link to the component to the left", { "" } },
93  {"right", "Link to the component to the right", { "" } }
94 
95  )
96 
97  // Optional since there is nothing to document
98  SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
99  )
100 
101  SST_ELI_IS_CHECKPOINTABLE()
102 
103  coreTestSharedObjectsComponent(SST::ComponentId_t id, SST::Params& params);
105 
106  void init(unsigned int phase) override;
107  void setup() override;
108  void finish() override;
109  void complete(unsigned int phase) override;
110 
111  bool tick(SST::Cycle_t);
112 
114  Component()
115  {} // For serialization ONLY
116  void serialize_order(SST::Core::Serialization::serializer& ser) override;
118 
119 private:
120  Output out;
121 
122  bool test_array;
123  bool test_bool_array;
124  bool test_map;
125  bool test_set;
126 
127  int myid;
128  int num_entities;
129 
130  int count;
131  bool check;
132  bool late_write;
133  bool pub;
134  bool late_initialize;
135  bool checkpoint;
136 
138  Shared::SharedArray<bool> bool_array;
141 };
142 
143 } // namespace SST::CoreTestSharedObjectsComponent
144 
145 #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:57
Definition: coreTest_SharedObjectComponent.cc:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
SharedSet class.
Definition: sharedSet.h:30
Definition: coreTest_SharedObjectComponent.h:58
Main component object for the simulation.
Definition: component.h:30
Definition: serializable.h:23
SharedArray class.
Definition: sharedArray.h:448
void setup() override
Called after all components have been constructed and initialization has completed, but before simulation time has begun.
Definition: coreTest_SharedObjectComponent.cc:246
Parameter store.
Definition: params.h:63
Definition: coreTest_SharedObjectComponent.h:25
void finish() override
Called after complete phase, but before objects are destroyed.
Definition: coreTest_SharedObjectComponent.cc:339