Skip to content

Commit be3bc58

Browse files
committed
Fixed a couple bugs and a compile warning:
- Fixed issue where checkpointing shared objects that hadn't been intialized caused a segfault - Fixed a bug where information about nonlocal remote rank was getting overwritten - SparseVectorMap now throws an exception on an access to a non-existent entry
1 parent c3b87f7 commit be3bc58

File tree

8 files changed

+111
-17
lines changed

8 files changed

+111
-17
lines changed

src/sst/core/configGraph.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ ConfigLink::updateLatencies()
141141
if ( order >= 1 ) {
142142
latency[0] = ConfigLink::getLatencyFromIndex(latency[0]);
143143
}
144-
if ( order >= 2 ) {
144+
// If this is nonlocal, latency[1] holds the remote thread instead of the latency
145+
if ( order >= 2 && !nonlocal ) {
145146
latency[1] = ConfigLink::getLatencyFromIndex(latency[1]);
146147
}
147148
}
@@ -1160,7 +1161,7 @@ ConfigGraph::GraphFilter::operator()(ConfigLink* link)
11601161
if ( !link->nonlocal && (c0_in_new ^ c1_in_new) ) {
11611162
// Only one side is in the set. Figure out which one and set the link as nonlocal
11621163
int index = c0_in_new ? 0 : 1;
1163-
link->setAsNonLocal(index, ranks[(index + 1) % 1]);
1164+
link->setAsNonLocal(index, ranks[(index + 1) % 2]);
11641165
}
11651166
return nullptr;
11661167
case 3:

src/sst/core/main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,9 @@ main(int argc, char* argv[])
988988
if ( myRank.rank == 0 || cfg.parallel_load() ) {
989989

990990
Simulation_impl::basicPerf.beginRegion("graph-cleanup");
991-
if ( cfg.parallel_load() ) graph->reduceGraphToSingleRank(myRank.rank);
991+
if ( cfg.parallel_load() ) {
992+
graph->reduceGraphToSingleRank(myRank.rank);
993+
}
992994
graph->postCreationCleanup();
993995
Simulation_impl::basicPerf.endRegion("graph-cleanup");
994996

src/sst/core/shared/sharedArray.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ class SharedArray : public SharedObject
216216
void serialize_order(SST::Core::Serialization::serializer& ser) override
217217
{
218218
SST::Shared::SharedObject::serialize_order(ser);
219-
SST_SER(published);
219+
SST_SER(published, SerOption::map_read_only);
220+
bool initialized = (data != nullptr);
221+
SST_SER(initialized, SerOption::map_read_only);
222+
223+
if ( !initialized ) return;
224+
220225
switch ( ser.mode() ) {
221226
case SST::Core::Serialization::serializer::SIZER:
222227
case SST::Core::Serialization::serializer::PACK:
@@ -241,7 +246,7 @@ class SharedArray : public SharedObject
241246

242247
private:
243248
bool published;
244-
Data* data;
249+
Data* data = nullptr;
245250

246251
class Data : public SharedObjectData
247252
{
@@ -629,7 +634,12 @@ class SharedArray<bool> : public SharedObject
629634
void serialize_order(SST::Core::Serialization::serializer& ser) override
630635
{
631636
SST::Shared::SharedObject::serialize_order(ser);
632-
SST_SER(published);
637+
SST_SER(published, SerOption::map_read_only);
638+
bool initialized = (data != nullptr);
639+
SST_SER(initialized, SerOption::map_read_only);
640+
641+
if ( !initialized ) return;
642+
633643
switch ( ser.mode() ) {
634644
case SST::Core::Serialization::serializer::SIZER:
635645
case SST::Core::Serialization::serializer::PACK:
@@ -654,7 +664,7 @@ class SharedArray<bool> : public SharedObject
654664

655665
private:
656666
bool published;
657-
Data* data;
667+
Data* data = nullptr;
658668

659669
class Data : public SharedObjectData
660670
{

src/sst/core/shared/sharedMap.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ class SharedMap : public SharedObject
230230
void serialize_order(SST::Core::Serialization::serializer& ser) override
231231
{
232232
SST::Shared::SharedObject::serialize_order(ser);
233-
SST_SER(published);
233+
SST_SER(published, SerOption::map_read_only);
234+
bool initialized = (data != nullptr);
235+
SST_SER(initialized, SerOption::map_read_only);
236+
237+
if ( !initialized ) return;
238+
234239
switch ( ser.mode() ) {
235240
case SST::Core::Serialization::serializer::SIZER:
236241
case SST::Core::Serialization::serializer::PACK:
@@ -255,7 +260,7 @@ class SharedMap : public SharedObject
255260

256261
private:
257262
bool published;
258-
Data* data;
263+
Data* data = nullptr;
259264

260265
class Data : public SharedObjectData
261266
{

src/sst/core/shared/sharedSet.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ class SharedSet : public SharedObject
197197
void serialize_order(SST::Core::Serialization::serializer& ser) override
198198
{
199199
SST::Shared::SharedObject::serialize_order(ser);
200-
SST_SER(published);
200+
SST_SER(published, SerOption::map_read_only);
201+
bool initialized = (data != nullptr);
202+
SST_SER(initialized, SerOption::map_read_only);
203+
204+
if ( !initialized ) return;
205+
201206
switch ( ser.mode() ) {
202207
case SST::Core::Serialization::serializer::SIZER:
203208
case SST::Core::Serialization::serializer::PACK:
@@ -222,7 +227,7 @@ class SharedSet : public SharedObject
222227

223228
private:
224229
bool published;
225-
Data* data;
230+
Data* data = nullptr;
226231

227232
class Data : public SharedObjectData
228233
{

src/sst/core/sparseVectorMap.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <algorithm>
2121
#include <cstddef>
22+
#include <stdexcept>
2223
#include <string>
2324
#include <vector>
2425

@@ -232,12 +233,13 @@ class SparseVectorMap
232233
233234
@return reference to the requested item.
234235
236+
@exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
235237
*/
236238
classT& operator[](keyT id)
237239
{
238240
int index = binary_search_find(id);
239241
if ( index == -1 ) {
240-
// Need to error out
242+
throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
241243
}
242244
return data[index];
243245
}
@@ -252,12 +254,13 @@ class SparseVectorMap
252254
253255
@return const reference to the requested item.
254256
257+
@exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
255258
*/
256259
const classT& operator[](keyT id) const
257260
{
258261
int index = binary_search_find(id);
259262
if ( index == -1 ) {
260-
// Need to error out
263+
throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
261264
}
262265
return data[index];
263266
}
@@ -498,12 +501,13 @@ class SparseVectorMap<keyT, classT*>
498501
499502
@return reference to the requested item.
500503
504+
@exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
501505
*/
502506
classT* operator[](keyT id)
503507
{
504508
int index = binary_search_find(id);
505509
if ( index == -1 ) {
506-
// Need to error out
510+
throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
507511
}
508512
return data[index];
509513
}
@@ -518,12 +522,13 @@ class SparseVectorMap<keyT, classT*>
518522
519523
@return const reference to the requested item.
520524
525+
@exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
521526
*/
522527
const classT* operator[](keyT id) const
523528
{
524529
int index = binary_search_find(id);
525530
if ( index == -1 ) {
526-
// Need to error out
531+
throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
527532
}
528533
return data[index];
529534
}
@@ -781,12 +786,13 @@ class SparseVectorMap<keyT, keyT>
781786
782787
@return reference to the requested item.
783788
789+
@exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
784790
*/
785791
keyT& operator[](keyT id)
786792
{
787793
int index = binary_search_find(id);
788794
if ( index == -1 ) {
789-
// Need to error out
795+
throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
790796
}
791797
return data[index];
792798
}
@@ -801,12 +807,13 @@ class SparseVectorMap<keyT, keyT>
801807
802808
@return const reference to the requested item.
803809
810+
@exception std::out_of_range try to access an element that doesn't exist in the SparseVectorMap
804811
*/
805812
const keyT& operator[](keyT id) const
806813
{
807814
int index = binary_search_find(id);
808815
if ( index == -1 ) {
809-
// Need to error out
816+
throw std::out_of_range("SparseVectorMap: trying to access element that does not exist");
810817
}
811818
return data[index];
812819
}

src/sst/core/testElements/coreTest_Checkpoint.cc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,26 @@ void
127127
coreTestCheckpoint::init(unsigned UNUSED(phase))
128128
{
129129
output->output("%s, init()\n", getName().c_str());
130+
131+
// Put data in the shared objects. Since there are no IDs, and we can't differentiate the components from each
132+
// other, we'll just have all of them put in the same values.
133+
shared_array.initialize("shared_array", 10);
134+
shared_set.initialize("shared_set");
135+
shared_map.initialize("shared_map");
136+
for ( int i = 0; i < 10; ++i ) {
137+
shared_array.write(i, i);
138+
shared_set.insert(i);
139+
shared_map.write(i, i);
140+
}
130141
}
131142

132143
void
133144
coreTestCheckpoint::setup()
134145
{
135146
output->output("%s, setup()\n", getName().c_str());
147+
shared_array.publish();
148+
shared_set.publish();
149+
shared_map.publish();
136150
if ( counter > 0 ) link_right->send(new coreTestCheckpointEvent(counter));
137151
}
138152

@@ -148,6 +162,39 @@ coreTestCheckpoint::finish()
148162
{
149163
output->output("%s finished. teststring=%s, output=('%s',%" PRIu32 ")\n", getName().c_str(), test_string.c_str(),
150164
output->getPrefix().c_str(), output->getVerboseLevel());
165+
166+
// Check the shared objects
167+
168+
// Shared Array
169+
bool error = false;
170+
for ( int i = 0; i < 10; ++i ) {
171+
if ( shared_array[i] != i ) error = true;
172+
}
173+
174+
if ( error ) {
175+
output->output("Error: contents in shared_array do not match");
176+
}
177+
178+
// Shared Set
179+
error = false;
180+
int count = 0;
181+
for ( auto x : shared_set ) {
182+
if ( x != count++ ) error = true;
183+
}
184+
185+
if ( error ) {
186+
output->output("Error: contents in shared_set do not match");
187+
}
188+
189+
// Shared Map
190+
error = false;
191+
for ( auto x : shared_map ) {
192+
if ( x.first != x.second ) error = true;
193+
}
194+
195+
if ( error ) {
196+
output->output("Error: contents in shared_map do not match");
197+
}
151198
}
152199

153200
// incoming event is bounced back after decrementing its counter
@@ -253,6 +300,12 @@ coreTestCheckpoint::serialize_order(SST::Core::Serialization::serializer& ser)
253300
SST_SER(stat_rng);
254301
SST_SER(stat_dist);
255302
SST_SER(stat_null);
303+
SST_SER(shared_array);
304+
SST_SER(shared_array_uninit);
305+
SST_SER(shared_set);
306+
SST_SER(shared_set_uninit);
307+
SST_SER(shared_map);
308+
SST_SER(shared_map_uninit);
256309
}
257310

258311

src/sst/core/testElements/coreTest_Checkpoint.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "sst/core/link.h"
1818
#include "sst/core/rng/distrib.h"
1919
#include "sst/core/rng/rng.h"
20+
#include "sst/core/shared/sharedArray.h"
21+
#include "sst/core/shared/sharedMap.h"
22+
#include "sst/core/shared/sharedSet.h"
2023

2124
#include <cstdint>
2225
#include <string>
@@ -164,6 +167,14 @@ class coreTestCheckpoint : public SST::Component
164167
Statistic<uint32_t>* stat_rng = nullptr;
165168
Statistic<double>* stat_dist = nullptr;
166169
Statistic<uint32_t>* stat_null = nullptr;
170+
171+
172+
Shared::SharedArray<int> shared_array;
173+
Shared::SharedArray<int> shared_array_uninit;
174+
Shared::SharedSet<int> shared_set;
175+
Shared::SharedSet<int> shared_set_uninit;
176+
Shared::SharedMap<int, int> shared_map;
177+
Shared::SharedMap<int, int> shared_map_uninit;
167178
};
168179

169180
} // namespace SST::CoreTestCheckpoint

0 commit comments

Comments
 (0)