Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compact into a CSR #52

Merged
merged 26 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcusp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(shad_dist_graph shad-dist-graph.cpp)
target_link_libraries(shad_dist_graph galois_gnn)
target_link_libraries(shad_dist_graph galois_shmem galois_cusp)
84 changes: 25 additions & 59 deletions libgalois/include/galois/LargeVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace galois {
* 2. All iterator methods (e.g. increment) preserve generation.
* 3. It is undefined behavior to compare iterators across generations.
* 4. Decreasing the container size invalidates some iterators.
*
* Note also that, like LargeArray, this class does not call constructors or
* destructors for elements. If you need to call constructors or destructors,
* you can use placement new and explicit destructor calls.
*/
template <typename T>
class LargeVector : public boost::noncopyable {
Expand Down Expand Up @@ -71,18 +75,20 @@ class LargeVector : public boost::noncopyable {
throw std::runtime_error(std::string("mmap failed: ") +
std::strerror(errno));

madvise(m_data, file_size, MADV_WILLNEED | MADV_HUGEPAGE);

m_mappings.push_front(std::make_pair(m_data, mmap_size));
}

public:
LargeVector(size_t initial_capacity)
LargeVector(size_t initial_size)
: m_capacity(0), m_size(0), m_data(nullptr),
m_fd(memfd_create("LargeVector", 0)),
m_mappings({std::make_pair(nullptr, 0)}) {
if (m_fd == -1)
throw std::runtime_error(std::string("creating memfd: ") +
std::strerror(errno));
ensure_capacity(initial_capacity);
resize(initial_size);
}

LargeVector() : LargeVector(1) {}
Expand All @@ -98,20 +104,13 @@ class LargeVector : public boost::noncopyable {
assert(other.m_mappings.empty());
}

LargeVector& operator=(LargeVector<T>&& other) {
m_capacity = std::move(other.m_capacity);
m_size = std::move(other.m_size);
m_data = std::move(other.m_data);
m_fd = std::move(other.m_fd);
m_mappings = std::move(other.m_mappings);

other.m_capacity = 0;
other.m_size = 0;
other.m_data = nullptr;
other.m_fd = -1;
assert(other.m_mappings.empty());

return *this;
friend void swap(LargeVector& first, LargeVector& second) {
using std::swap;
swap(first.m_capacity, second.m_capacity);
swap(first.m_size, second.m_size);
swap(first.m_data, second.m_data);
swap(first.m_fd, second.m_fd);
swap(first.m_mappings, second.m_mappings);
}

~LargeVector() {
Expand All @@ -125,63 +124,30 @@ class LargeVector : public boost::noncopyable {

uint64_t size() const noexcept { return m_size; }

template <typename... Args>
T& emplace_back(Args&&... args) {
if (m_size == m_capacity) {
ensure_capacity(m_size + 1);
}
return *new (m_data + m_size++) T(std::forward<Args>(args)...);
}

T& push_back(const T& t) { return emplace_back(t); }

T& push_back(T&& t) { return emplace_back(std::move(t)); }

T& operator[](size_t index) const { return m_data[index]; }

void pop_back() {
assert(m_size > 0);
m_data[--m_size].~T();
}

/**
* Note: unlike std::vector, resize does not call constructors or
* destructors.
*/
void resize(size_t count) {
for (T* ii = begin() + count; ii < end(); ++ii)
ii->~T();
// galois::do_all(galois::iterate(begin() + count, end()),
// [](T* ii) { ii->~T(); });

ensure_capacity(count);

for (T* ii = end(); ii < begin() + count; ++ii)
new (ii) T();
// galois::do_all(galois::iterate(end(), begin() + count),
// [](T* ii) { new (ii) T(); });

m_size = count;
}

bool empty() { return m_size == 0; }

inline T* begin() { return m_data; }
inline T* end() { return m_data + m_size; }
};

}; // namespace galois

namespace std {
template <typename T>
ostream& operator<<(std::ostream& os, const galois::LargeVector<T>& vec) {
for (uint64_t i = 0; i < vec.getSize(); i++) {
os << vec[i];
if (i < vec.getSize() - 1) {
os << " ";
}
}
return os;
}

template <typename T>
istream& operator>>(istream& is, galois::LargeVector<T>& vec) {
T value;
while (is >> value) {
vec.push_back(value);
}
return is;
}
} // namespace std

#endif
Loading