Commit fb7b42ec authored by Richard Berger's avatar Richard Berger
Browse files

Add support for aligned allocations on Windows

parent 183980e8
......@@ -49,6 +49,8 @@ void *Memory::smalloc(bigint nbytes, const char *name)
#if defined(LMP_USE_TBB_ALLOCATOR)
ptr = scalable_aligned_malloc(nbytes, LAMMPS_MEMALIGN);
#elif defined(_WIN32)
ptr = _aligned_malloc(nbytes, LAMMPS_MEMALIGN);
#else
int retval = posix_memalign(&ptr, LAMMPS_MEMALIGN, nbytes);
if (retval) ptr = NULL;
......@@ -109,6 +111,8 @@ void Memory::sfree(void *ptr)
if (ptr == NULL) return;
#if defined(LMP_USE_TBB_ALLOCATOR)
scalable_aligned_free(ptr);
#elif defined(_WIN32)
_aligned_free(ptr);
#else
free(ptr);
#endif
......
......@@ -220,8 +220,14 @@ class MyPage {
for (int i = npage-pagedelta; i < npage; i++) {
#if defined(LAMMPS_MEMALIGN)
void *ptr;
#ifdef _WIN32
ptr = _aligned_malloc(pagesize*sizeof(T), LAMMPS_MEMALIGN);
if(ptr == NULL)
errorflag = 2;
#else
if (posix_memalign(&ptr, LAMMPS_MEMALIGN, pagesize*sizeof(T)))
errorflag = 2;
#endif
pages[i] = (T *) ptr;
#else
pages[i] = (T *) malloc(pagesize*sizeof(T));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment