@@ -127,6 +127,7 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer
127127 For self links, no rank info is stored since we don't need
128128 to create a unique ID
129129 */
130+
130131 if ( type == SYNC || type == REG ) {
131132 SST_SER (my_rank);
132133
@@ -158,6 +159,13 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer
158159 }
159160 } // if ( type == SYNC || type == REG )
160161
162+
163+ // Serialize the ID for the Link
164+ if ( !s->has_tool_list )
165+ SST_SER (s->id );
166+ else
167+ SST_SER ((*s->attached_tools )[0 ].second );
168+
161169 /*
162170 Store the metadata for this link
163171 */
@@ -217,24 +225,31 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer
217225
218226 // Determine how many serializable tools there are
219227 Link::ToolList tools;
220- if ( s->attached_tools ) {
221- for ( auto x : *s->attached_tools ) {
222- if ( dynamic_cast <SST::Core::Serialization::serializable*>(x.first ) ) {
223- tools.push_back (x);
228+
229+ if ( s->has_tool_list ) {
230+ for ( auto x = ++s->attached_tools ->begin (); x != s->attached_tools ->end (); ++x ) {
231+ if ( dynamic_cast <SST::Core::Serialization::serializable*>(x->first ) ) {
232+ tools.push_back (*x);
224233 }
225234 }
226235 }
227236 size_t tool_count = tools.size ();
228- SST_SER (tool_count);
229- if ( tool_count > 0 ) {
230- // Serialize each tool, then call
231- // serializeEventAttachPointKey() to serialize any data
232- // associated with the key
233- for ( auto x : tools ) {
234- SST::Core::Serialization::serializable* obj =
235- dynamic_cast <SST::Core::Serialization::serializable*>(x.first );
236- SST_SER (obj);
237- x.first ->serializeEventAttachPointKey (ser, x.second );
237+
238+ // Need to determine if we'll have any tools attached on restart. We only have tools when tool_count > 0
239+ bool restart_tools = (tool_count > 0 );
240+ SST_SER (restart_tools);
241+
242+ if ( restart_tools ) {
243+ SST_SER (tool_count);
244+ if ( tool_count > 0 ) {
245+ // Serialize each tool, then call serializeEventAttachPointKey() to serialize any data associated with
246+ // the key
247+ for ( auto x : tools ) {
248+ SST::Core::Serialization::serializable* obj =
249+ dynamic_cast <SST::Core::Serialization::serializable*>(x.first );
250+ SST_SER (obj);
251+ x.first ->serializeEventAttachPointKey (ser, x.second );
252+ }
238253 }
239254 }
240255
@@ -339,6 +354,8 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer
339354 }
340355 }
341356
357+ SST_SER (s->id );
358+
342359 /*
343360 Get the metadata for the link
344361 */
@@ -401,13 +418,20 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer
401418 s->pair_link ->latency += latency;
402419 }
403420
404- /*
405- Restore attached tools
406- */
407- size_t tool_count;
408- SST_SER (tool_count);
409- if ( tool_count > 0 ) {
410- s->attached_tools = new Link::ToolList ();
421+ SST_SER (s->has_tool_list );
422+
423+ if ( s->has_tool_list ) {
424+ /*
425+ Restore attached tools
426+ */
427+ size_t tool_count;
428+ SST_SER (tool_count);
429+
430+ // If has_tool_list is true, then tool_count is greater than 0
431+ Link::ToolList* tools = new Link::ToolList ();
432+ tools->emplace_back (nullptr , s->id );
433+ s->attached_tools = tools;
434+ s->has_tool_list = true ;
411435 for ( size_t i = 0 ; i < tool_count; ++i ) {
412436 SST::Core::Serialization::serializable* tool;
413437 uintptr_t key;
@@ -417,9 +441,7 @@ SST::Core::Serialization::serialize_impl<Link*>::operator()(Link*& s, serializer
417441 s->attached_tools ->emplace_back (ap, key);
418442 }
419443 }
420- else {
421- s->attached_tools = nullptr ;
422- }
444+
423445
424446 /*
425447 Deserialize the events targetting this link
@@ -477,7 +499,7 @@ class NullEvent : public Event
477499};
478500
479501
480- Link::Link (LinkId_t tag ) :
502+ Link::Link (LinkId_t id ) :
481503 send_queue(nullptr ),
482504 delivery_info(0 ),
483505 defaultTimeBase(0 ),
@@ -486,8 +508,8 @@ Link::Link(LinkId_t tag) :
486508 current_time(Simulation_impl::getSimulation()->currentSimCycle),
487509 type(UNINITIALIZED),
488510 mode(INIT),
489- tag(tag ),
490- attached_tools( nullptr )
511+ tag(0 ),
512+ id(id )
491513{}
492514
493515Link::Link () :
@@ -499,8 +521,7 @@ Link::Link() :
499521 current_time(Simulation_impl::getSimulation()->currentSimCycle),
500522 type(UNINITIALIZED),
501523 mode(INIT),
502- tag(bit_util::type_max<uint32_t >),
503- attached_tools(nullptr )
524+ tag(bit_util::type_max<uint32_t >)
504525{}
505526
506527Link::~Link ()
@@ -514,7 +535,7 @@ Link::~Link()
514535 if ( SYNC == pair_link->type ) delete pair_link;
515536 }
516537
517- if ( attached_tools ) delete attached_tools;
538+ if ( has_tool_list ) delete attached_tools;
518539}
519540
520541void
@@ -683,9 +704,10 @@ Link::send_impl(SimTime_t delay, Event* event)
683704 event->addRecvComponent (pair_link->comp , pair_link->ctype , pair_link->port );
684705#endif
685706
686- if ( attached_tools ) {
687- for ( auto & x : *attached_tools ) {
688- x.first ->eventSent (x.second , event);
707+ if ( has_tool_list ) {
708+ // First entry just holds the Link id, so we can skip it
709+ for ( auto x = ++attached_tools->begin (); x != attached_tools->end (); ++x ) {
710+ x->first ->eventSent (x->second , event);
689711 // Check to see if the event was deleted. If so, return.
690712 if ( nullptr == event ) return ;
691713 }
@@ -840,17 +862,23 @@ Link::createUniqueGlobalLinkName(RankInfo local_rank, uintptr_t local_ptr, RankI
840862void
841863Link::attachTool (AttachPoint* tool, const AttachPointMetaData& mdata)
842864{
843- if ( !attached_tools ) attached_tools = new ToolList ();
865+ if ( !has_tool_list ) {
866+ auto tools = new ToolList ();
867+ tools->emplace_back (nullptr , id);
868+ attached_tools = tools;
869+ has_tool_list = true ;
870+ }
844871 auto key = tool->registerLinkAttachTool (mdata);
845- attached_tools->push_back ( std::make_pair ( tool, key) );
872+ attached_tools->emplace_back ( tool, key);
846873}
847874
848875void
849876Link::detachTool (AttachPoint* tool)
850877{
851- if ( !attached_tools ) return ;
878+ if ( !has_tool_list ) return ;
852879
853- for ( auto x = attached_tools->begin (); x != attached_tools->end (); ++x ) {
880+ // First entry just holds the Link id, so we can skip it
881+ for ( auto x = ++attached_tools->begin (); x != attached_tools->end (); ++x ) {
854882 if ( x->first == tool ) {
855883 attached_tools->erase (x);
856884 break ;
0 commit comments