18 #include <flecsi-config.h> 20 #if !defined(FLECSI_ENABLE_LEGION) 21 #error FLECSI_ENABLE_LEGION not defined! This file depends on Legion! 31 inline log::devel_tag io_tag(
"io");
35 inline void checkpoint_with_attach_task(
const Legion::Task * task,
36 const std::vector<Legion::PhysicalRegion> & regions,
38 Legion::Runtime * runtime);
40 inline void checkpoint_without_attach_task(
const Legion::Task * task,
41 const std::vector<Legion::PhysicalRegion> & regions,
43 Legion::Runtime * runtime);
45 inline void recover_with_attach_task(
const Legion::Task * task,
46 const std::vector<Legion::PhysicalRegion> & regions,
48 Legion::Runtime * runtime);
50 inline void recover_without_attach_task(
const Legion::Task * task,
51 const std::vector<Legion::PhysicalRegion> & regions,
53 Legion::Runtime * runtime);
60 Legion::LogicalPartition lp,
62 std::map<Legion::FieldID, std::string> & field_string_map)
63 : logical_region(lr), logical_partition(lp), logical_region_name(lr_name),
64 field_string_map(field_string_map) {
65 Legion::Runtime * runtime = Legion::Runtime::get_runtime();
66 Legion::Context ctx = Legion::Runtime::get_context();
67 if(lr.get_dim() == 1) {
68 Legion::Domain domain =
69 runtime->get_index_space_domain(ctx, lr.get_index_space());
70 dim_size[0] = domain.get_volume();
73 flog_devel(info) <<
"ID logical region size " << dim_size[0]
78 Legion::Domain domain =
79 runtime->get_index_space_domain(ctx, lr.get_index_space());
80 dim_size[0] = domain.get_volume();
83 flog_devel(info) <<
"ID logical region size " << dim_size[0]
90 Legion::LogicalPartition lp,
92 : logical_region(lr), logical_partition(lp), logical_region_name(lr_name) {}
94 Legion::LogicalRegion logical_region;
95 Legion::LogicalPartition logical_partition;
96 std::string logical_region_name;
97 std::map<Legion::FieldID, std::string> field_string_map;
110 : hdf5_file_id(-1), file_name(file_name), num_files(num_files) {
111 hdf5_region_vector.clear();
112 hdf5_group_map.clear();
115 flog_devel(info) <<
"Init HDF5 file " << file_name <<
" num_files " 116 << num_files << std::endl;
129 bool create_hdf5_file(
int file_idx) {
130 assert(hdf5_file_id == -1);
131 std::string fname = file_name + std::to_string(file_idx);
133 H5Fcreate(fname.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
134 if(hdf5_file_id < 0) {
135 flog(error) <<
"H5Fcreate failed: " << hdf5_file_id << std::endl;
140 flog_devel(info) <<
"Create HDF5 file " << fname <<
" file_id " 141 << hdf5_file_id << std::endl;
149 bool open_hdf5_file(
int file_idx) {
150 assert(hdf5_file_id == -1);
151 std::string fname = file_name + std::to_string(file_idx);
152 hdf5_file_id = H5Fopen(fname.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
153 if(hdf5_file_id < 0) {
154 flog(error) <<
"H5Fopen failed: " << hdf5_file_id << std::endl;
159 flog_devel(info) <<
"Open HDF5 file " << fname <<
" file_id " 160 << hdf5_file_id << std::endl;
168 bool close_hdf5_file() {
169 assert(hdf5_file_id >= 0);
170 H5Fflush(hdf5_file_id, H5F_SCOPE_LOCAL);
171 H5Fclose(hdf5_file_id);
174 flog_devel(info) <<
"Close HDF5 file_id " << hdf5_file_id << std::endl;
183 bool write_string_to_hdf5_file(
const char * group_name,
184 const char * dataset_name,
185 const std::string & str,
188 assert(hdf5_file_id >= 0);
190 const char * cstr = str.c_str();
191 [[maybe_unused]] herr_t status;
197 std::map<std::string, hid_t>::iterator it;
198 it = hdf5_group_map.find(std::string(group_name));
199 if(it != hdf5_group_map.end()) {
200 group_id = H5Gopen2(hdf5_file_id, group_name, H5P_DEFAULT);
203 group_id = H5Gcreate2(
204 hdf5_file_id, group_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
205 hdf5_group_map[std::string(group_name)] = group_id;
208 flog(error) <<
"H5Gcreate2 failed: " << group_id << std::endl;
209 H5Fclose(hdf5_file_id);
213 hid_t filetype = H5Tcopy(H5T_C_S1);
214 status = H5Tset_size(filetype, H5T_VARIABLE);
215 hid_t memtype = H5Tcopy(H5T_C_S1);
216 status = H5Tset_size(memtype, H5T_VARIABLE);
220 hid_t dataspace_id = H5Screate_simple(1, dims, NULL);
222 const char * data[1];
224 hid_t dset = H5Dcreate2(group_id,
231 status = H5Dwrite(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
233 H5Fflush(hdf5_file_id, H5F_SCOPE_LOCAL);
234 status = H5Dclose(dset);
235 status = H5Sclose(dataspace_id);
236 status = H5Tclose(filetype);
237 status = H5Tclose(memtype);
238 status = H5Gclose(group_id);
245 bool read_string_from_hdf5_file(
const char * group_name,
246 const char * dataset_name,
249 assert(hdf5_file_id >= 0);
251 [[maybe_unused]] herr_t status;
257 group_id = H5Gopen2(hdf5_file_id, group_name, H5P_DEFAULT);
260 flog(error) <<
"H5Gcreate2 failed: " << group_id << std::endl;
261 H5Fclose(hdf5_file_id);
265 hid_t dset = H5Dopen2(group_id, dataset_name, H5P_DEFAULT);
267 hid_t filetype = H5Dget_type(dset);
268 hid_t memtype = H5Tcopy(H5T_C_S1);
269 status = H5Tset_size(memtype, H5T_VARIABLE);
272 status = H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
274 str = str + std::string(data[0]);
275 H5Fflush(hdf5_file_id, H5F_SCOPE_LOCAL);
277 hid_t space = H5Dget_space(dset);
278 status = H5Dvlen_reclaim(memtype, space, H5P_DEFAULT, data);
279 status = H5Dclose(dset);
280 status = H5Tclose(filetype);
281 status = H5Tclose(memtype);
282 status = H5Gclose(group_id);
289 void add_logical_region(Legion::LogicalRegion lr,
290 Legion::LogicalPartition lp,
292 std::map<Legion::FieldID, std::string> field_string_map) {
294 hdf5_region_vector.push_back(h5_lr);
301 hdf5_region_vector.push_back(hdf5_region);
307 bool create_datasets_for_regions(
int file_idx) {
308 assert(hdf5_region_vector.size() > 0);
309 assert(hdf5_file_id >= 0);
311 Legion::Runtime * runtime = Legion::Runtime::get_runtime();
312 Legion::Context ctx = Legion::Runtime::get_context();
316 flog_devel(info) <<
"Create HDF5 datasets file_id " << hdf5_file_id
317 <<
" regions size " << hdf5_region_vector.size()
323 hid_t dataspace_id = -1;
324 if(lr_it.logical_region.get_index_space().get_dim() == 1) {
325 Legion::LogicalRegion sub_lr = runtime->get_logical_subregion_by_color(
326 ctx, lr_it.logical_partition, file_idx);
327 Legion::Domain domain =
328 runtime->get_index_space_domain(ctx, sub_lr.get_index_space());
330 dims[0] = domain.get_volume();
331 dataspace_id = H5Screate_simple(1, dims, NULL);
334 Legion::LogicalRegion sub_lr = runtime->get_logical_subregion_by_color(
335 ctx, lr_it.logical_partition, file_idx);
336 Legion::Domain domain =
337 runtime->get_index_space_domain(ctx, sub_lr.get_index_space());
339 dims[0] = domain.get_volume();
340 dataspace_id = H5Screate_simple(1, dims, NULL);
342 if(dataspace_id < 0) {
343 flog(error) <<
"H5Screate_simple failed: " << dataspace_id << std::endl;
344 H5Fclose(hdf5_file_id);
348 hid_t group_id = H5Gcreate2(file_id, (*lr_it).logical_region_name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
350 printf(
"H5Gcreate2 failed: %lld\n", (
long long)group_id);
351 H5Sclose(dataspace_id);
352 H5Fclose(hdf5_file_id);
356 for(std::pair<const Legion::FieldID, std::string> & it :
357 lr_it.field_string_map) {
358 const char * dataset_name = (it.second).c_str();
359 hid_t dataset = H5Dcreate2(hdf5_file_id,
367 flog(error) <<
"H5Dcreate2 failed: " << dataset << std::endl;
369 H5Sclose(dataspace_id);
370 H5Fclose(hdf5_file_id);
376 H5Sclose(dataspace_id);
378 H5Fflush(hdf5_file_id, H5F_SCOPE_LOCAL);
383 std::string file_name;
385 std::vector<legion_hdf5_region_t> hdf5_region_vector;
386 std::map<std::string, hid_t> hdf5_group_map;
394 using launch_space_t = Legion::IndexSpace;
397 init_hdf5_file(
const char * file_name,
int num_files) {
403 return hdf5_file.create_hdf5_file(file_idx);
408 return hdf5_file.open_hdf5_file(file_idx);
413 return hdf5_file.close_hdf5_file();
417 create_datasets_for_regions(
legion_hdf5_t & hdf5_file,
int file_idx) {
418 return hdf5_file.create_datasets_for_regions(file_idx);
424 const char * group_name,
425 const char * dataset_name,
426 const std::string & str,
428 return hdf5_file.write_string_to_hdf5_file(
429 group_name, dataset_name, str, size);
435 const char * group_name,
436 const char * dataset_name,
438 return hdf5_file.read_string_from_hdf5_file(group_name, dataset_name, str);
443 std::vector<legion_hdf5_region_t> & hdf5_region_vector) {
444 for(
auto & r : hdf5_region_vector)
445 hdf5_file.add_hdf5_region(r);
450 for(
int i = 0; i < hdf5_file.num_files; i++) {
451 hdf5_file.create_hdf5_file(i);
452 hdf5_file.create_datasets_for_regions(i);
453 hdf5_file.close_hdf5_file();
459 Legion::IndexSpace launch_space,
460 std::vector<legion_hdf5_region_t> & hdf5_region_vector,
462 std::string file_name = hdf5_file.file_name;
464 Legion::Runtime * runtime = Legion::Runtime::get_runtime();
465 Legion::Context ctx = Legion::Runtime::get_context();
467 std::vector<std::map<Legion::FieldID, std::string>> field_string_map_vector;
469 field_string_map_vector.push_back(it.field_string_map);
472 std::vector<std::byte> task_args;
473 task_args = util::serial_put(std::tie(field_string_map_vector, file_name));
477 ? exec::leg::task_id<checkpoint_with_attach_task, loc | inner>
478 : exec::leg::task_id<checkpoint_without_attach_task, loc | leaf>;
480 Legion::IndexLauncher checkpoint_launcher(task_id,
482 Legion::TaskArgument((
void *)(task_args.data()), task_args.size()),
483 Legion::ArgumentMap());
487 checkpoint_launcher.add_region_requirement(
488 Legion::RegionRequirement(it.logical_partition,
494 std::map<Legion::FieldID, std::string> & field_string_map =
496 for(std::pair<const Legion::FieldID, std::string> & it : field_string_map) {
497 checkpoint_launcher.region_requirements[idx].add_field(it.first);
504 flog_devel(info) <<
"Start checkpoint file " << file_name
505 <<
" regions size " << hdf5_region_vector.size()
509 Legion::FutureMap fumap =
510 runtime->execute_index_space(ctx, checkpoint_launcher);
511 fumap.wait_all_results();
516 Legion::IndexSpace launch_space,
517 std::vector<legion_hdf5_region_t> & hdf5_region_vector,
519 std::string file_name = hdf5_file.file_name;
521 Legion::Runtime * runtime = Legion::Runtime::get_runtime();
522 Legion::Context ctx = Legion::Runtime::get_context();
524 std::vector<std::map<Legion::FieldID, std::string>> field_string_map_vector;
526 field_string_map_vector.push_back(it.field_string_map);
529 std::vector<std::byte> task_args;
530 task_args = util::serial_put(std::tie(field_string_map_vector, file_name));
533 attach_flag ? exec::leg::task_id<recover_with_attach_task, loc | inner>
534 : exec::leg::task_id<recover_without_attach_task, loc | leaf>;
536 Legion::IndexLauncher recover_launcher(task_id,
538 Legion::TaskArgument((
void *)(task_args.data()), task_args.size()),
539 Legion::ArgumentMap());
542 recover_launcher.add_region_requirement(
543 Legion::RegionRequirement(it.logical_partition,
549 std::map<Legion::FieldID, std::string> & field_string_map =
551 for(std::pair<const Legion::FieldID, std::string> & it : field_string_map) {
552 recover_launcher.region_requirements[idx].add_field(it.first);
559 flog_devel(info) <<
"Start recover file " << file_name <<
" regions size " 560 << hdf5_region_vector.size() << std::endl;
563 Legion::FutureMap fumap = runtime->execute_index_space(ctx, recover_launcher);
564 fumap.wait_all_results();
569 auto & index_runtime_data = process_topology.get();
571 std::map<Legion::FieldID, std::string> field_string_map;
574 run::context::instance().get_field_info_store<topo::index>()) {
575 field_string_map[p->fid] = std::to_string(p->fid);
578 Legion::Runtime * runtime = Legion::Runtime::get_runtime();
579 Legion::Context ctx = Legion::Runtime::get_context();
580 Legion::Rect<1> file_color_bounds(0, hdf5_file.num_files - 1);
582 runtime->create_index_space(ctx, file_color_bounds);
584 process_topology_file_ip = runtime->create_pending_partition(ctx, index_runtime_data.index_space, process_topology_file_is);
586 int num_subregions = index_runtime_data.colors;
587 for (
int point = 0; point < hdf5_file.num_files; point++) {
588 std::vector<IndexSpace> subspaces;
589 for (
int i = 0; i < num_subregions/hdf5_file.num_files; i++) {
590 subspaces.push_back(runtime->get_index_subspace(ctx, index_runtime_data.color_partition.get_index_partition(), idx));
593 runtime->create_index_space_union(ctx, process_topology_file_ip, point, subspaces);
596 data::leg::unique_index_partition process_topology_file_ip =
597 runtime->create_equal_partition(
598 ctx, index_runtime_data.index_space, process_topology_file_is);
600 data::leg::unique_logical_partition process_topology_file_lp =
601 runtime->get_logical_partition(
602 ctx, index_runtime_data.logical_region, process_topology_file_ip);
603 hdf5_file.add_logical_region(index_runtime_data.logical_region,
604 process_topology_file_lp,
608 file_map[&index_runtime_data] = {std::move(process_topology_file_is),
609 std::move(process_topology_file_ip),
610 std::move(process_topology_file_lp)};
613 void checkpoint_process_topology(
legion_hdf5_t & hdf5_file) {
614 auto const & fid_vector =
615 run::context::instance().get_field_info_store<
topo::index>();
617 auto & index_runtime_data = process_topology.get();
620 flog_devel(info) <<
"Checkpoint default index topology, fields size " 621 << fid_vector.size() << std::endl;
624 const auto & file = file_map[&index_runtime_data];
626 file.logical_partition,
628 for(
const auto p : fid_vector) {
629 checkpoint_region.field_string_map[p->fid] = std::to_string(p->fid);
632 std::vector<legion_hdf5_region_t> hdf5_region_vector;
633 hdf5_region_vector.push_back(checkpoint_region);
634 checkpoint_data(hdf5_file, file.index_space, hdf5_region_vector,
true);
640 void checkpoint_index_topology_field(
hdf5_t & hdf5_file,
642 const size_t fid = fh.fid();
643 auto & index_runtime_data = fh.topology().get();
647 flog_devel(info) <<
"Checkpoint index topology, field " << fid
651 const auto & file = file_map[&index_runtime_data];
653 file.logical_partition,
655 checkpoint_region.field_string_map[fid] = std::to_string(fid);
657 std::vector<legion_hdf5_region_t> hdf5_region_vector;
658 hdf5_region_vector.push_back(checkpoint_region);
659 checkpoint_data(hdf5_file, file.index_space, hdf5_region_vector,
true);
663 auto const & fid_vector =
664 run::context::instance().get_field_info_store<
topo::index>();
666 auto & index_runtime_data = process_topology.get();
670 flog_devel(info) <<
"Recover default index topology, fields size " 671 << fid_vector.size() << std::endl;
674 const auto & file = file_map[&index_runtime_data];
676 file.logical_partition,
678 for(
const auto p : fid_vector) {
679 recover_region.field_string_map[p->fid] = std::to_string(p->fid);
682 std::vector<legion_hdf5_region_t> hdf5_region_vector;
683 hdf5_region_vector.push_back(recover_region);
684 recover_data(hdf5_file, file.index_space, hdf5_region_vector,
true);
687 void recover_index_topology_field(
hdf5_t & hdf5_file,
689 const size_t fid = fh.fid();
690 auto & index_runtime_data = fh.topology().get();
694 flog_devel(info) <<
"Recover index topology, field " << fid << std::endl;
697 const auto & file = file_map[&index_runtime_data];
699 file.logical_partition,
701 recover_region.field_string_map[fid] = std::to_string(fid);
703 std::vector<legion_hdf5_region_t> hdf5_region_vector;
704 hdf5_region_vector.push_back(recover_region);
705 recover_data(hdf5_file, file.index_space, hdf5_region_vector,
true);
709 struct topology_data {
711 data::leg::unique_index_partition index_partition;
712 data::leg::unique_logical_partition logical_partition;
714 std::map<const topo::index::core *, topology_data> file_map;
718 checkpoint_with_attach_task(
const Legion::Task * task,
719 const std::vector<Legion::PhysicalRegion> & regions,
721 Legion::Runtime * runtime) {
723 const int point = task->index_point.point_data[0];
725 const std::byte * task_args = (
const std::byte *)task->args;
727 std::vector<std::map<Legion::FieldID, std::string>> field_string_map_vector;
729 field_string_map_vector =
730 util::serial_get<std::vector<std::map<Legion::FieldID, std::string>>>(
733 std::string fname = util::serial_get<std::string>(task_args);
735 fname = fname + std::to_string(point);
736 char * file_name =
const_cast<char *
>(fname.c_str());
738 for(
unsigned int rid = 0; rid < regions.size(); rid++) {
739 Legion::PhysicalRegion attach_dst_pr;
740 Legion::LogicalRegion input_lr = regions[rid].get_logical_region();
741 Legion::LogicalRegion attach_dst_lr = runtime->create_logical_region(
742 ctx, input_lr.get_index_space(), input_lr.get_field_space());
744 Legion::AttachLauncher hdf5_attach_launcher(
745 EXTERNAL_HDF5_FILE, attach_dst_lr, attach_dst_lr);
746 std::map<Legion::FieldID, const char *> field_map;
747 std::set<Legion::FieldID> field_set = task->regions[rid].privilege_fields;
748 std::map<Legion::FieldID, std::string>::iterator map_it;
749 for(Legion::FieldID it : field_set) {
750 map_it = field_string_map_vector[rid].find(it);
751 if(map_it != field_string_map_vector[rid].end()) {
752 field_map.insert(std::make_pair(it, (map_it->second).c_str()));
761 flog_devel(info) <<
"Checkpoint data to HDF5 file attach " << file_name
762 <<
" region_id " << rid
763 <<
" (dataset(fid) size= " << field_map.size() <<
")" 764 <<
" field_string_map_vector(regions) size " 765 << field_string_map_vector.size() << std::endl;
768 hdf5_attach_launcher.attach_hdf5(
769 file_name, field_map, LEGION_FILE_READ_WRITE);
771 runtime->attach_external_resource(ctx, hdf5_attach_launcher);
774 Legion::CopyLauncher copy_launcher1;
775 copy_launcher1.add_copy_requirements(
776 Legion::RegionRequirement(input_lr, READ_ONLY, EXCLUSIVE, input_lr),
777 Legion::RegionRequirement(
778 attach_dst_lr, WRITE_DISCARD, EXCLUSIVE, attach_dst_lr));
779 for(Legion::FieldID it : field_set) {
780 copy_launcher1.add_src_field(0, it);
781 copy_launcher1.add_dst_field(0, it);
783 runtime->issue_copy_operation(ctx, copy_launcher1);
786 runtime->detach_external_resource(ctx, attach_dst_pr,
true);
788 runtime->destroy_logical_region(ctx, attach_dst_lr);
793 checkpoint_without_attach_task(
const Legion::Task * task,
794 const std::vector<Legion::PhysicalRegion> & regions,
796 Legion::Runtime * runtime) {
798 const int point = task->index_point.point_data[0];
800 const std::byte * task_args = (
const std::byte *)task->args;
802 std::vector<std::map<Legion::FieldID, std::string>> field_string_map_vector;
804 field_string_map_vector =
805 util::serial_get<std::vector<std::map<Legion::FieldID, std::string>>>(
808 std::string fname = util::serial_get<std::string>(task_args);
810 fname = fname + std::to_string(point);
811 char * file_name =
const_cast<char *
>(fname.c_str());
814 file_id = H5Fopen(file_name, H5F_ACC_RDWR, H5P_DEFAULT);
816 flog(error) <<
"H5Fopen failed: " << file_id << std::endl;
820 for(
unsigned int rid = 0; rid < regions.size(); rid++) {
821 std::set<Legion::FieldID> field_set = task->regions[rid].privilege_fields;
822 std::map<Legion::FieldID, std::string>::iterator map_it;
823 for(Legion::FieldID it : field_set) {
824 map_it = field_string_map_vector[rid].find(it);
825 if(map_it != field_string_map_vector[rid].end()) {
826 const Legion::FieldAccessor<READ_ONLY,
830 Realm::AffineAccessor<double, 1, Legion::coord_t>>
831 acc_fid(regions[rid], it);
832 Legion::Rect<1> rect = runtime->get_index_space_domain(
833 ctx, task->regions[rid].region.get_index_space());
834 const double * dset_data = acc_fid.ptr(rect.lo);
836 H5Dopen2(file_id, (map_it->second).c_str(), H5P_DEFAULT);
838 flog(error) <<
"H5Dopen2 failed: " << dataset_id << std::endl;
843 dataset_id, H5T_IEEE_F64LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data);
844 H5Dclose(dataset_id);
853 flog_devel(info) <<
"Checkpoint data to HDF5 file no attach " << file_name
854 <<
" region_id " << rid
855 <<
" (dataset(fid) size= " << field_set.size() <<
")" 856 <<
" field_string_map_vector(regions) size " 857 << field_string_map_vector.size() << std::endl;
861 H5Fflush(file_id, H5F_SCOPE_LOCAL);
866 recover_with_attach_task(
const Legion::Task * task,
867 const std::vector<Legion::PhysicalRegion> & regions,
869 Legion::Runtime * runtime) {
870 const int point = task->index_point.point_data[0];
872 const std::byte * task_args = (
const std::byte *)task->args;
874 std::vector<std::map<Legion::FieldID, std::string>> field_string_map_vector;
876 field_string_map_vector =
877 util::serial_get<std::vector<std::map<Legion::FieldID, std::string>>>(
880 std::string fname = util::serial_get<std::string>(task_args);
882 fname = fname + std::to_string(point);
883 char * file_name =
const_cast<char *
>(fname.c_str());
885 for(
unsigned int rid = 0; rid < regions.size(); rid++) {
886 Legion::PhysicalRegion attach_src_pr;
887 Legion::LogicalRegion output_lr = regions[rid].get_logical_region();
888 Legion::LogicalRegion attach_src_lr = runtime->create_logical_region(
889 ctx, output_lr.get_index_space(), output_lr.get_field_space());
891 Legion::AttachLauncher hdf5_attach_launcher(
892 EXTERNAL_HDF5_FILE, attach_src_lr, attach_src_lr);
893 std::map<Legion::FieldID, const char *> field_map;
894 std::set<Legion::FieldID> field_set = task->regions[rid].privilege_fields;
895 std::map<Legion::FieldID, std::string>::iterator map_it;
896 for(Legion::FieldID it : field_set) {
897 map_it = field_string_map_vector[rid].find(it);
898 if(map_it != field_string_map_vector[rid].end()) {
899 field_map.insert(std::make_pair(it, (map_it->second).c_str()));
908 flog_devel(info) <<
"Recorver data to HDF5 file attach " << file_name
909 <<
" region_id " << rid
910 <<
" (dataset(fid) size= " << field_map.size() <<
")" 911 <<
" field_string_map_vector(regions) size " 912 << field_string_map_vector.size() << std::endl;
915 hdf5_attach_launcher.attach_hdf5(
916 file_name, field_map, LEGION_FILE_READ_WRITE);
918 runtime->attach_external_resource(ctx, hdf5_attach_launcher);
920 Legion::CopyLauncher copy_launcher2;
921 copy_launcher2.add_copy_requirements(
922 Legion::RegionRequirement(
923 attach_src_lr, READ_ONLY, EXCLUSIVE, attach_src_lr),
924 Legion::RegionRequirement(
925 output_lr, WRITE_DISCARD, EXCLUSIVE, output_lr));
926 for(Legion::FieldID it : field_set) {
927 copy_launcher2.add_src_field(0, it);
928 copy_launcher2.add_dst_field(0, it);
930 runtime->issue_copy_operation(ctx, copy_launcher2);
933 runtime->detach_external_resource(ctx, attach_src_pr,
true);
935 runtime->destroy_logical_region(ctx, attach_src_lr);
940 recover_without_attach_task(
const Legion::Task * task,
941 const std::vector<Legion::PhysicalRegion> & regions,
943 Legion::Runtime * runtime) {
944 const int point = task->index_point.point_data[0];
946 const std::byte * task_args = (
const std::byte *)task->args;
948 std::vector<std::map<Legion::FieldID, std::string>> field_string_map_vector;
950 field_string_map_vector =
951 util::serial_get<std::vector<std::map<Legion::FieldID, std::string>>>(
954 std::string fname = util::serial_get<std::string>(task_args);
956 fname = fname + std::to_string(point);
957 char * file_name =
const_cast<char *
>(fname.c_str());
960 file_id = H5Fopen(file_name, H5F_ACC_RDWR, H5P_DEFAULT);
962 flog(error) <<
"H5Fopen failed: " << file_id << std::endl;
966 for(
unsigned int rid = 0; rid < regions.size(); rid++) {
967 std::set<Legion::FieldID> field_set = task->regions[rid].privilege_fields;
968 std::map<Legion::FieldID, std::string>::iterator map_it;
969 for(Legion::FieldID it : field_set) {
970 map_it = field_string_map_vector[rid].find(it);
971 if(map_it != field_string_map_vector[rid].end()) {
972 const Legion::FieldAccessor<WRITE_DISCARD,
976 Realm::AffineAccessor<double, 1, Legion::coord_t>>
977 acc_fid(regions[rid], it);
978 Legion::Rect<1> rect = runtime->get_index_space_domain(
979 ctx, task->regions[rid].region.get_index_space());
980 double * dset_data = acc_fid.ptr(rect.lo);
982 H5Dopen2(file_id, (map_it->second).c_str(), H5P_DEFAULT);
984 flog(error) <<
"H5Dopen2 failed: " << dataset_id << std::endl;
989 dataset_id, H5T_IEEE_F64LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data);
990 H5Dclose(dataset_id);
999 flog_devel(info) <<
"Checkpoint data to HDF5 file no attach " << file_name
1000 <<
" region_id " << rid
1001 <<
" (dataset(fid) size= " << field_set.size() <<
")" 1002 <<
" field_string_map_vector(regions) size " 1003 << field_string_map_vector.size() << std::endl;
#define flog(severity)
Definition: flog.hh:136
Definition: policy.hh:567
Definition: policy.hh:104
Definition: control.hh:31