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

Fix for case where no aligned_alloc #559

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
19 changes: 15 additions & 4 deletions src/madness/world/worldgop.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,11 +967,22 @@ namespace madness {
};
using sptr_t = std::unique_ptr<std::byte[], free_dtor>;

auto buf0 = sptr_t(static_cast<std::byte *>(
std::aligned_alloc(sizeof(void *), bufsz)),
auto aligned_buf_alloc = [&]() -> std::byte* {
#ifdef HAVE_POSIX_MEMALIGN
void *ptr;
if (posix_memalign(&ptr, sizeof(void *), bufsz) != 0) {
throw std::bad_alloc();
}
return static_cast<std::byte *>(ptr);
#else
return static_cast<std::byte *>(
std::aligned_alloc(sizeof(void *), bufsz));
#endif
};

auto buf0 = sptr_t(aligned_buf_alloc(),
free_dtor{});
auto buf1 = sptr_t(static_cast<std::byte *>(
std::aligned_alloc(sizeof(void *), bufsz)),
auto buf1 = sptr_t(aligned_buf_alloc(),
free_dtor{});

// transfer data in chunks at most this large
Expand Down
Loading