diff --git a/bfps/cpp/bfps_new.cpp b/bfps/cpp/bfps_new.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c169b4d7501b39b1ebfe6fad8dbb60cfc74e08cc --- /dev/null +++ b/bfps/cpp/bfps_new.cpp @@ -0,0 +1,51 @@ +#include <cstdlib> +#include "bfps_new.hpp" +#include "particles/particles_utils.hpp" + +// Do not make this function or in header. + +// Regular scalar new +void* operator new(std::size_t n) { + void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); + if(allocated){ + return allocated; + } + throw std::bad_alloc(); + return allocated; +} + +void* operator new[]( std::size_t n ) { + void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); + if(allocated){ + return allocated; + } + throw std::bad_alloc(); + return allocated; +} + +void* operator new ( std::size_t n, const std::nothrow_t& tag){ + void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); + return allocated; +} + +void* operator new[] ( std::size_t n, const std::nothrow_t& tag){ + void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); + return allocated; +} + +// Regular scalar delete +void operator delete(void* p) { + particles_utils::aligned_malloc::free(p); +} + +void operator delete[](void* p) { + particles_utils::aligned_malloc::free(p); +} + +void operator delete ( void* p, const std::nothrow_t& /*tag*/) { + particles_utils::aligned_malloc::free(p); +} + +void operator delete[]( void* p, const std::nothrow_t& /*tag*/) { + particles_utils::aligned_malloc::free(p); +} diff --git a/bfps/cpp/bfps_new.hpp b/bfps/cpp/bfps_new.hpp new file mode 100644 index 0000000000000000000000000000000000000000..473a0a669538306aa2d4b081f6b6cda5fea5e2fc --- /dev/null +++ b/bfps/cpp/bfps_new.hpp @@ -0,0 +1,6 @@ +#ifndef BFPS_NEW_HPP +#define BFPS_NEW_HPP + +#include <new> + +#endif diff --git a/bfps/cpp/particles/particles_utils.hpp b/bfps/cpp/particles/particles_utils.hpp index 09d6d7f3ef9b13dd3b15f1639d3175dd9e6ec7c5..1c327ea41155648c29f928eee0c70921ea7afbbc 100644 --- a/bfps/cpp/particles/particles_utils.hpp +++ b/bfps/cpp/particles/particles_utils.hpp @@ -311,6 +311,7 @@ public: } }; +// Default alignement for the complete application by redirecting the new operator static const int DefaultMemAlignement = 64; namespace aligned_malloc { @@ -348,51 +349,5 @@ inline void free(void* ptrToFree){ } -// Regular scalar new -inline void* operator new(std::size_t n) { - void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); - if(allocated){ - return allocated; - } - throw std::bad_alloc(); - return allocated; -} - -inline void* operator new[]( std::size_t n ) { - void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); - if(allocated){ - return allocated; - } - throw std::bad_alloc(); - return allocated; -} - -inline void* operator new ( std::size_t n, const std::nothrow_t& tag){ - void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); - return allocated; -} - -inline void* operator new[] ( std::size_t n, const std::nothrow_t& tag){ - void* const allocated = particles_utils::aligned_malloc::malloc<particles_utils::DefaultMemAlignement>(n); - return allocated; -} - -// Regular scalar delete -inline void operator delete(void* p) noexcept{ - particles_utils::aligned_malloc::free(p); -} - -inline void operator delete[](void* p) noexcept{ - particles_utils::aligned_malloc::free(p); -} - -inline void operator delete ( void* p, const std::nothrow_t& /*tag*/) { - particles_utils::aligned_malloc::free(p); -} - -inline void operator delete[]( void* p, const std::nothrow_t& /*tag*/) { - particles_utils::aligned_malloc::free(p); -} - #endif diff --git a/setup.py b/setup.py index c531263a05f10a89109d40a34097e5a93e9beb4f..7200cbc6889ed35a3fe215d2d26803e456e18198 100644 --- a/setup.py +++ b/setup.py @@ -118,7 +118,8 @@ src_file_list = ['full_code/direct_numerical_simulation', 'spline_n9', 'spline_n10', 'Lagrange_polys', - 'scope_timer'] + 'scope_timer', + 'bfps_new'] particle_headers = [ 'cpp/particles/particles_distr_mpi.hpp',