Metall  v0.29
A persistent memory allocator for data-centric analytics
csr_graph.cpp

This is an example of how to use a CSR graph data structure with Metall.

// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
#include <iostream>
using index_t = uint64_t;
using vid_t = uint64_t;
// We have two CSR graph data structures that have the same interfaces
#if 0
#else
using csr_graph_t =
#endif
int main() {
{
// Create a new Metall datastore in "/tmp/dir"
// If 'dir' does not exist, Metall creates automatically
metall::manager manager(metall::create_only, "/tmp/dir");
std::size_t num_vertices = 16;
std::size_t num_edges = 256;
// Allocate and construct an object in the persistent memory with a name
// "csr_graph"
csr_graph_t *csr_graph = manager.construct<csr_graph_t>("csr_graph")(
num_vertices, num_edges,
manager.get_allocator()); // Arguments to the constructor
// You can use the arrays normally
index_t *indices_array = csr_graph->indices();
vid_t *edges_array = csr_graph->edges();
edges_array[indices_array[1]++] = 10;
}
{
// Open the existing Metall datastore in "/tmp/dir"
metall::manager manager(metall::open_read_only, "/tmp/dir");
csr_graph_t *csr_graph = manager.find<csr_graph_t>("csr_graph").first;
if (!csr_graph) {
std::cerr << "Object csr_graph does not exist" << std::endl;
std::abort();
}
// You can use the arrays normally
index_t *indices_array = csr_graph->indices();
vid_t *edges_array = csr_graph->edges();
std::cout << edges_array[indices_array[0]] << std::endl;
}
return 0;
}
Simple CSR graph data structure that can take a custom C++ allocator and be stored in persistent memo...
Definition: csr_using_vector.hpp:20
Simple CSR graph data structure that can take a custom C++ allocator and be stored in persistent memo...
Definition: csr.hpp:17
A generalized Metall manager class.
Definition: basic_manager.hpp:40
int main()
Definition: jgraph.cpp:24
basic_manager<> manager
Default Metall manager class which is an alias of basic_manager with the default template parameters.
Definition: metall.hpp:34