@@ -18,38 +18,69 @@ void Metadata::add_transaction(unsigned int id,
1818 transaction_infos_[id][start_and_count] = std::make_pair (location, publisher);
1919}
2020
21- void Metadata::export_to_file (std::ofstream& ostream) const
21+ static void write_block_entries (std::ofstream& ostream,
22+ const std::map<std::pair<std::vector<size_t >, std::vector<size_t >>,
23+ std::pair<std::string, sg4::ActorPtr>, std::less<>>& transaction)
24+ {
25+ for (const auto & [block_info, location] : transaction) {
26+ const auto & [block_start, block_count] = block_info;
27+ const auto & [where, actor] = location;
28+
29+ ostream << " " << where.c_str () << " : [" ;
30+ XBT_DEBUG (" Actor %s wrote:" , actor->get_cname ());
31+ unsigned long last = block_start.size () - 1 ;
32+ for (unsigned long i = 0 ; i < last; i++) {
33+ ostream << block_start[i] << " :" << block_start[i] + block_count[i] << " , " ;
34+ XBT_DEBUG (" Dimension %lu : [%zu..%zu]" , i + 1 , block_start[i], block_start[i] + block_count[i]);
35+ }
36+ ostream << block_start[last] << " :" << block_start[last] + block_count[last] << " ]" << std::endl;
37+ XBT_DEBUG (" Dimension %lu : [%zu..%zu]" , last + 1 , block_start[last], block_start[last] + block_count[last]);
38+ XBT_DEBUG (" in: %s" , where.c_str ());
39+ }
40+ }
41+
42+ void Metadata::write_transaction_to_stream (unsigned int tx_id, std::ofstream& out)
43+ {
44+ auto it = transaction_infos_.find (tx_id);
45+ if (it == transaction_infos_.end ())
46+ return ;
47+ XBT_DEBUG (" Transaction %u:" , tx_id);
48+ out << " Transaction " << tx_id << " :" << std::endl;
49+ write_block_entries (out, it->second );
50+ flushed_count_++;
51+ transaction_infos_.erase (it);
52+ }
53+
54+ void Metadata::evict_transaction (unsigned int tx_id)
55+ {
56+ transaction_infos_.erase (tx_id);
57+ }
58+
59+ void Metadata::export_to_file (std::ofstream& ostream, const std::string& prog_file_path) const
2260{
2361 auto var = variable_.lock ();
2462 xbt_assert (var, " Metadata::export_to_file called after its Variable has been destroyed" );
2563 XBT_DEBUG (" Variable %s:" , var->get_cname ());
26- ostream << var->get_element_size () << " \t " << var->get_cname () << " \t " << transaction_infos_.size ();
64+ unsigned int total = flushed_count_ + static_cast <unsigned int >(transaction_infos_.size ());
65+ ostream << var->get_element_size () << " \t " << var->get_cname () << " \t " << total;
2766 ostream << " *{" ;
2867 auto shape = var->get_shape ();
2968 const auto last_index = shape.size () - 1 ;
3069 for (unsigned int i = 0 ; i < last_index; i++)
3170 ostream << shape[i] << " ," ;
3271 ostream << shape[last_index] << " }" << std::endl;
3372
73+ // Copy already-flushed entries from the per-variable prog file (if any)
74+ if (!prog_file_path.empty ()) {
75+ std::ifstream prog (prog_file_path, std::ios::binary);
76+ ostream << prog.rdbuf ();
77+ }
78+
79+ // Write remaining in-memory entries
3480 for (const auto & [id, transaction] : transaction_infos_) {
3581 XBT_DEBUG (" Transaction %u:" , id);
3682 ostream << " Transaction " << id << " :" << std::endl;
37- for (const auto & [block_info, location] : transaction) {
38- const auto & [block_start, block_count] = block_info;
39- const auto & [where, actor] = location;
40-
41- ostream << " " << where.c_str () << " : [" ;
42- XBT_DEBUG (" Actor %s wrote:" , actor->get_cname ());
43- unsigned long last = block_start.size () - 1 ;
44- for (unsigned long i = 0 ; i < last; i++) {
45- ostream << block_start[i] << " :" << block_start[i] + block_count[i] << " , " ;
46- XBT_DEBUG (" Dimension %lu : [%zu..%zu]" , i + 1 , block_start[i], block_start[i] + block_count[i]);
47- }
48- ostream << block_start[last] << " :" << block_start[last] + block_count[last] << " ]" << std::endl;
49- XBT_DEBUG (" Dimension %lu : [%zu..%zu]" , last + 1 , block_start[last], block_start[last] + block_count[last]);
50-
51- XBT_DEBUG (" in: %s" , where.c_str ());
52- }
83+ write_block_entries (ostream, transaction);
5384 }
5485}
5586// / \endcond
0 commit comments