From 427437d49ba5ba10a4183bc8b306fad9c3953922 Mon Sep 17 00:00:00 2001 From: Pepijn Schoen Date: Fri, 31 Mar 2017 14:40:17 +0200 Subject: [PATCH] Use a one-time defined generic signature for SharedMemoryVectors --- .../contiguous_internalmem_datafacade.hpp | 139 ++++++++---------- include/util/shared_memory_vector_wrapper.hpp | 3 + unit_tests/util/static_graph.cpp | 4 +- 3 files changed, 66 insertions(+), 80 deletions(-) diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index e411596d6..a17a01b0d 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -79,9 +79,9 @@ class ContiguousInternalMemoryAlgorithmDataFacade auto graph_edges_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::CH_GRAPH_EDGE_LIST); - util::ShM::vector node_list( + util::SharedMemoryVector node_list( graph_nodes_ptr, data_layout.num_entries[storage::DataLayout::CH_GRAPH_NODE_LIST]); - util::ShM::vector edge_list( + util::SharedMemoryVector edge_list( graph_edges_ptr, data_layout.num_entries[storage::DataLayout::CH_GRAPH_EDGE_LIST]); m_query_graph.reset(new QueryGraph(node_list, edge_list)); } @@ -155,7 +155,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade : public datafacade::AlgorithmDataFacade { private: - util::ShM::vector m_is_core_node; + util::SharedMemoryVector m_is_core_node; // allocator that keeps the allocation data std::shared_ptr allocator; @@ -164,7 +164,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade { auto core_marker_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::CH_CORE_MARKER); - util::ShM::vector is_core_node( + util::SharedMemoryVector is_core_node( core_marker_ptr, data_layout.num_entries[storage::DataLayout::CH_CORE_MARKER]); m_is_core_node = std::move(is_core_node); } @@ -217,9 +217,9 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::ShM::vector m_coordinate_list; util::PackedVector m_osmnodeid_list; - util::ShM::vector m_via_geometry_list; - util::ShM::vector m_name_ID_list; - util::ShM::vector m_lane_data_id; + util::SharedMemoryVector m_via_geometry_list; + util::SharedMemoryVector m_name_ID_list; + util::SharedMemoryVector m_lane_data_id; util::ShM::vector m_turn_instruction_list; util::ShM::vector @@ -229,19 +229,17 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::ShM::vector m_post_turn_bearing; util::NameTable m_names_table; - util::ShM::vector m_name_begin_indices; - util::ShM::vector m_is_core_node; + util::SharedMemoryVector m_name_begin_indices; + util::SharedMemoryVector m_is_core_node; util::ShM::vector m_lane_description_offsets; util::ShM::vector m_lane_description_masks; - util::ShM::vector - m_turn_weight_penalties; - util::ShM::vector - m_turn_duration_penalties; + util::SharedMemoryVector m_turn_weight_penalties; + util::SharedMemoryVector m_turn_duration_penalties; extractor::SegmentDataView segment_data; - util::ShM::vector m_datasource_name_data; + util::SharedMemoryVector m_datasource_name_data; util::ShM::vector m_datasource_name_offsets; util::ShM::vector @@ -255,11 +253,9 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::NameTable m_name_table; // bearing classes by node based node - util::ShM::vector - m_bearing_class_id_table; + util::SharedMemoryVector m_bearing_class_id_table; // entry class IDs - util::ShM::vector - m_entry_class_id_list; + util::SharedMemoryVector m_entry_class_id_list; // the look-up table for entry classes. An entry class lists the possibility of entry for all // available turns. Such a class id is stored with every edge. @@ -269,8 +265,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade // at an intersection std::shared_ptr> m_bearing_ranges_table; - util::ShM::vector - m_bearing_values_table; + util::SharedMemoryVector m_bearing_values_table; // allocator that keeps the allocation data std::shared_ptr allocator; @@ -353,7 +348,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade const auto lane_data_id_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::LANE_DATA_ID); - util::ShM::vector lane_data_id( + util::SharedMemoryVector lane_data_id( lane_data_id_ptr, data_layout.num_entries[storage::DataLayout::LANE_DATA_ID]); m_lane_data_id = std::move(lane_data_id); @@ -377,15 +372,14 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade const auto name_id_list_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::NAME_ID_LIST); - util::ShM::vector name_id_list( + util::SharedMemoryVector name_id_list( name_id_list_ptr, data_layout.num_entries[storage::DataLayout::NAME_ID_LIST]); m_name_ID_list = std::move(name_id_list); const auto entry_class_id_list_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::ENTRY_CLASSID); - typename util::ShM::vector - entry_class_id_list(entry_class_id_list_ptr, - data_layout.num_entries[storage::DataLayout::ENTRY_CLASSID]); + typename util::SharedMemoryVector entry_class_id_list( + entry_class_id_list_ptr, data_layout.num_entries[storage::DataLayout::ENTRY_CLASSID]); m_entry_class_id_list = std::move(entry_class_id_list); const auto pre_turn_bearing_ptr = data_layout.GetBlockPtr( @@ -409,7 +403,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto via_geometry_list_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::VIA_NODE_LIST); - util::ShM::vector via_geometry_list( + util::SharedMemoryVector via_geometry_list( via_geometry_list_ptr, data_layout.num_entries[storage::DataLayout::VIA_NODE_LIST]); m_via_geometry_list = std::move(via_geometry_list); } @@ -444,65 +438,57 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto turn_weight_penalties_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TURN_WEIGHT_PENALTIES); - m_turn_weight_penalties = - util::ShM::vector( - turn_weight_penalties_ptr, - data_layout.num_entries[storage::DataLayout::TURN_WEIGHT_PENALTIES]); + m_turn_weight_penalties = util::SharedMemoryVector( + turn_weight_penalties_ptr, + data_layout.num_entries[storage::DataLayout::TURN_WEIGHT_PENALTIES]); auto turn_duration_penalties_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::TURN_DURATION_PENALTIES); - m_turn_duration_penalties = - util::ShM::vector( - turn_duration_penalties_ptr, - data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES]); + m_turn_duration_penalties = util::SharedMemoryVector( + turn_duration_penalties_ptr, + data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES]); } void InitializeGeometryPointers(storage::DataLayout &data_layout, char *memory_block) { auto geometries_index_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::GEOMETRIES_INDEX); - util::ShM::vector - geometry_begin_indices(geometries_index_ptr, - data_layout.num_entries[storage::DataLayout::GEOMETRIES_INDEX]); + util::SharedMemoryVector geometry_begin_indices( + geometries_index_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_INDEX]); auto geometries_node_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_NODE_LIST); - util::ShM::vector geometry_node_list( + util::SharedMemoryVector geometry_node_list( geometries_node_list_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST]); auto geometries_fwd_weight_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST); - util::ShM::vector - geometry_fwd_weight_list( - geometries_fwd_weight_list_ptr, - data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]); + util::SharedMemoryVector geometry_fwd_weight_list( + geometries_fwd_weight_list_ptr, + data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]); auto geometries_rev_weight_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST); - util::ShM::vector - geometry_rev_weight_list( - geometries_rev_weight_list_ptr, - data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]); + util::SharedMemoryVector geometry_rev_weight_list( + geometries_rev_weight_list_ptr, + data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]); auto geometries_fwd_duration_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST); - util::ShM::vector - geometry_fwd_duration_list( - geometries_fwd_duration_list_ptr, - data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]); + util::SharedMemoryVector geometry_fwd_duration_list( + geometries_fwd_duration_list_ptr, + data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]); auto geometries_rev_duration_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST); - util::ShM::vector - geometry_rev_duration_list( - geometries_rev_duration_list_ptr, - data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]); + util::SharedMemoryVector geometry_rev_duration_list( + geometries_rev_duration_list_ptr, + data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]); auto datasources_list_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::DATASOURCES_LIST); - util::ShM::vector - datasources_list(datasources_list_ptr, - data_layout.num_entries[storage::DataLayout::DATASOURCES_LIST]); + util::SharedMemoryVector datasources_list( + datasources_list_ptr, data_layout.num_entries[storage::DataLayout::DATASOURCES_LIST]); segment_data = extractor::SegmentDataView{std::move(geometry_begin_indices), std::move(geometry_node_list), @@ -520,25 +506,23 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade { auto bearing_class_id_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::BEARING_CLASSID); - typename util::ShM::vector - bearing_class_id_table(bearing_class_id_ptr, - data_layout.num_entries[storage::DataLayout::BEARING_CLASSID]); + typename util::SharedMemoryVector bearing_class_id_table( + bearing_class_id_ptr, data_layout.num_entries[storage::DataLayout::BEARING_CLASSID]); m_bearing_class_id_table = std::move(bearing_class_id_table); auto bearing_class_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::BEARING_VALUES); - typename util::ShM::vector - bearing_class_table(bearing_class_ptr, - data_layout.num_entries[storage::DataLayout::BEARING_VALUES]); + typename util::SharedMemoryVector bearing_class_table( + bearing_class_ptr, data_layout.num_entries[storage::DataLayout::BEARING_VALUES]); m_bearing_values_table = std::move(bearing_class_table); auto offsets_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::BEARING_OFFSETS); auto blocks_ptr = data_layout.GetBlockPtr(memory_block, storage::DataLayout::BEARING_BLOCKS); - util::ShM::vector bearing_offsets( + util::SharedMemoryVector bearing_offsets( offsets_ptr, data_layout.num_entries[storage::DataLayout::BEARING_OFFSETS]); - util::ShM::vector bearing_blocks( + util::SharedMemoryVector bearing_blocks( blocks_ptr, data_layout.num_entries[storage::DataLayout::BEARING_BLOCKS]); m_bearing_ranges_table = @@ -974,15 +958,15 @@ class ContiguousInternalMemoryAlgorithmDataFacade memory_block, storage::DataLayout::MLD_PARTITION); auto partition_entries_count = data_layout.GetBlockEntries(storage::DataLayout::MLD_PARTITION); - util::ShM::vector partition( - mld_partition_ptr, partition_entries_count); + util::SharedMemoryVector partition(mld_partition_ptr, + partition_entries_count); auto mld_chilren_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::MLD_CELL_TO_CHILDREN); auto children_entries_count = data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_TO_CHILDREN); - util::ShM::vector cell_to_children( - mld_chilren_ptr, children_entries_count); + util::SharedMemoryVector cell_to_children(mld_chilren_ptr, + children_entries_count); mld_partition = partition::MultiLevelPartitionView{level_data, partition, cell_to_children}; @@ -1014,13 +998,12 @@ class ContiguousInternalMemoryAlgorithmDataFacade auto cell_level_offsets_entries_count = data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS); - util::ShM::vector weights( - mld_cell_weights_ptr, weight_entries_count); - util::ShM::vector source_boundary( - mld_source_boundary_ptr, source_boundary_entries_count); - util::ShM::vector - destination_boundary(mld_destination_boundary_ptr, - destination_boundary_entries_count); + util::SharedMemoryVector weights(mld_cell_weights_ptr, + weight_entries_count); + util::SharedMemoryVector source_boundary(mld_source_boundary_ptr, + source_boundary_entries_count); + util::SharedMemoryVector destination_boundary( + mld_destination_boundary_ptr, destination_boundary_entries_count); util::ShM::vector cells(mld_cells_ptr, cells_entries_counts); @@ -1045,9 +1028,9 @@ class ContiguousInternalMemoryAlgorithmDataFacade auto graph_node_to_offset_ptr = data_layout.GetBlockPtr( memory_block, storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET); - util::ShM::vector node_list( + util::SharedMemoryVector node_list( graph_nodes_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_NODE_LIST]); - util::ShM::vector edge_list( + util::SharedMemoryVector edge_list( graph_edges_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_EDGE_LIST]); util::ShM::vector node_to_offset(graph_node_to_offset_ptr, diff --git a/include/util/shared_memory_vector_wrapper.hpp b/include/util/shared_memory_vector_wrapper.hpp index 910bbaa9c..cf6286c08 100644 --- a/include/util/shared_memory_vector_wrapper.hpp +++ b/include/util/shared_memory_vector_wrapper.hpp @@ -182,6 +182,9 @@ template struct ShM SharedMemoryWrapper, std::vector>::type; }; + +template using SharedMemoryVector = typename util::ShM::vector; +template using InternalMemoryVector = typename util::ShM::vector; } } diff --git a/unit_tests/util/static_graph.cpp b/unit_tests/util/static_graph.cpp index 6a4b90466..34eda9f16 100644 --- a/unit_tests/util/static_graph.cpp +++ b/unit_tests/util/static_graph.cpp @@ -70,8 +70,8 @@ template struct RandomArrayEntryFixture std::shuffle(order.begin(), order.end(), g); } - typename ShM::vector nodes; - typename ShM::vector edges; + typename util::InternalMemoryVector nodes; + typename InternalMemoryVector edges; std::vector lengths; std::vector order; };