Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / utility / smalloc.cpp
index bf5015c006f71ad685e9fb65933153de8b71e769..b6dd271c3304650cc913b1d0a6538d8f42d26d2d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,7 +45,7 @@
 #include <cstdlib>
 
 #ifdef WITH_DMALLOC
-#include <dmalloc.h>
+#    include <dmalloc.h>
 #endif
 
 #include <cstring>
 #include "gromacs/utility/dir_separator.h"
 #include "gromacs/utility/fatalerror.h"
 #ifdef PRINT_ALLOC_KB
-#include "gromacs/utility/basenetwork.h"
-#include "gromacs/utility/gmxmpi.h"
+#    include "gromacs/utility/basenetwork.h"
+#    include "gromacs/utility/gmxmpi.h"
 #endif
 
 static gmx_bool            g_bOverAllocDD     = FALSE;
 static tMPI_Thread_mutex_t g_over_alloc_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
 
-void *save_malloc(const char *name, const char *file, int line, size_t size)
+void* save_malloc(const char* name, const char* file, int line, size_t size)
 {
-    void *p;
+    voidp;
 
     p = nullptr;
     if (size == 0)
@@ -77,19 +77,19 @@ void *save_malloc(const char *name, const char *file, int line, size_t size)
         if ((p = malloc(size)) == nullptr)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to malloc %" PRId64 " bytes for %s\n"
+                      "Not enough memory. Failed to malloc %" PRId64
+                      " bytes for %s\n"
                       "(called from file %s, line %d)",
                       static_cast<int64_t>(size), name, file, line);
         }
-        (void) memset(p, 0, size);
+        (void)memset(p, 0, size);
     }
     return p;
 }
 
-void *save_calloc(const char *name, const char *file, int line,
-                  size_t nelem, size_t elsize)
+void* save_calloc(const char* name, const char* file, int line, size_t nelem, size_t elsize)
 {
-    void *p;
+    voidp;
 
     p = nullptr;
     if ((nelem == 0) || (elsize == 0))
@@ -99,32 +99,29 @@ void *save_calloc(const char *name, const char *file, int line,
     else
     {
 #ifdef PRINT_ALLOC_KB
-        if (nelem*elsize >= PRINT_ALLOC_KB*1024)
+        if (nelem * elsize >= PRINT_ALLOC_KB * 1024)
         {
             int rank = gmx_node_rank();
             printf("Allocating %.1f MB for %s (called from file %s, line %d on %d)\n",
-                   nelem*elsize/1048576.0, name, file, line, rank);
+                   nelem * elsize / 1048576.0, name, file, line, rank);
         }
 #endif
 #if GMX_BROKEN_CALLOC
         /* emulate calloc(3) with malloc/memset on machines with
            a broken calloc, e.g. in -lgmalloc on cray xt3. */
-        if ((p = malloc((size_t)nelem*(size_t)elsize)) == NULL)
+        if ((p = malloc((size_t)nelem * (size_t)elsize)) == NULL)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to calloc %" PRId64
-                      " elements of size %" PRId64
+                      "Not enough memory. Failed to calloc %" PRId64 " elements of size %" PRId64
                       " for %s\n(called from file %s, line %d)",
-                      (int64_t)nelem, (int64_t)elsize,
-                      name, file, line);
+                      (int64_t)nelem, (int64_t)elsize, name, file, line);
         }
-        memset(p, 0, (size_t) (nelem * elsize));
+        memset(p, 0, (size_t)(nelem * elsize));
 #else
         if ((p = calloc(nelem, elsize)) == nullptr)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to calloc %" PRId64
-                      " elements of size %" PRId64
+                      "Not enough memory. Failed to calloc %" PRId64 " elements of size %" PRId64
                       " for %s\n(called from file %s, line %d)",
                       static_cast<int64_t>(nelem), static_cast<int64_t>(elsize), name, file, line);
         }
@@ -133,11 +130,10 @@ void *save_calloc(const char *name, const char *file, int line,
     return p;
 }
 
-void *save_realloc(const char *name, const char *file, int line, void *ptr,
-                   size_t nelem, size_t elsize)
+void* save_realloc(const char* name, const char* file, int line, void* ptr, size_t nelem, size_t elsize)
 {
-    void  *p;
-    size_t size = nelem*elsize;
+    void*  p;
+    size_t size = nelem * elsize;
 
     p = nullptr;
     if (size == 0)
@@ -147,11 +143,11 @@ void *save_realloc(const char *name, const char *file, int line, void *ptr,
     else
     {
 #ifdef PRINT_ALLOC_KB
-        if (size >= PRINT_ALLOC_KB*1024)
+        if (size >= PRINT_ALLOC_KB * 1024)
         {
             int rank = gmx_node_rank();
             printf("Reallocating %.1f MB for %s (called from file %s, line %d on %d)\n",
-                   size/1048576.0, name, file, line, rank);
+                   size / 1048576.0, name, file, line, rank);
         }
 #endif
         if (ptr == nullptr)
@@ -173,7 +169,7 @@ void *save_realloc(const char *name, const char *file, int line, void *ptr,
     return p;
 }
 
-void save_free(const char gmx_unused *name, const char gmx_unused *file, int gmx_unused line, void *ptr)
+void save_free(const char gmx_unused* name, const char gmx_unused* file, int gmx_unused line, void* ptr)
 {
     if (ptr != nullptr)
     {
@@ -186,22 +182,25 @@ void save_free(const char gmx_unused *name, const char gmx_unused *file, int gmx
  * on systems that lack posix_memalign() and memalign() when
  * freeing memory that needed to be adjusted to achieve
  * the necessary alignment. */
-void *save_malloc_aligned(const char *name, const char *file, int line,
-                          size_t nelem, size_t elsize, size_t alignment)
+void* save_malloc_aligned(const char* name, const char* file, int line, size_t nelem, size_t elsize, size_t alignment)
 {
-    void * p;
+    void* p;
 
     if (alignment == 0)
     {
         gmx_fatal(errno, __FILE__, __LINE__,
-                  "Cannot allocate aligned memory with alignment of zero!\n(called from file %s, line %d)", file, line);
+                  "Cannot allocate aligned memory with alignment of zero!\n(called from file %s, "
+                  "line %d)",
+                  file, line);
     }
 
     size_t alignmentSize = gmx::AlignedAllocationPolicy::alignment();
     if (alignment > alignmentSize)
     {
         gmx_fatal(errno, __FILE__, __LINE__,
-                  "Cannot allocate aligned memory with alignment > %zu bytes\n(called from file %s, line %d)", alignmentSize, file, line);
+                  "Cannot allocate aligned memory with alignment > %zu bytes\n(called from file "
+                  "%s, line %d)",
+                  alignmentSize, file, line);
     }
 
 
@@ -212,29 +211,30 @@ void *save_malloc_aligned(const char *name, const char *file, int line,
     else
     {
 #ifdef PRINT_ALLOC_KB
-        if (nelem*elsize >= PRINT_ALLOC_KB*1024)
+        if (nelem * elsize >= PRINT_ALLOC_KB * 1024)
         {
             int rank = gmx_node_rank();
             printf("Allocating %.1f MB for %s (called from file %s, line %d on %d)\n",
-                   nelem*elsize/1048576.0, name, file, line, rank);
+                   nelem * elsize / 1048576.0, name, file, line, rank);
         }
 #endif
 
-        p = gmx::AlignedAllocationPolicy::malloc(nelem*elsize);
+        p = gmx::AlignedAllocationPolicy::malloc(nelem * elsize);
 
         if (p == nullptr)
         {
             gmx_fatal(errno, __FILE__, __LINE__,
-                      "Not enough memory. Failed to allocate %zu aligned elements of size %zu for %s\n(called from file %s, line %d)", nelem, elsize, name, file, line);
+                      "Not enough memory. Failed to allocate %zu aligned elements of size %zu for "
+                      "%s\n(called from file %s, line %d)",
+                      nelem, elsize, name, file, line);
         }
     }
     return p;
 }
 
-void *save_calloc_aligned(const char *name, const char *file, int line,
-                          size_t nelem, size_t elsize, size_t alignment)
+void* save_calloc_aligned(const char* name, const char* file, int line, size_t nelem, size_t elsize, size_t alignment)
 {
-    void *aligned = save_malloc_aligned(name, file, line, nelem, elsize, alignment);
+    voidaligned = save_malloc_aligned(name, file, line, nelem, elsize, alignment);
     if (aligned != nullptr)
     {
         memset(aligned, 0, static_cast<size_t>(nelem * elsize));
@@ -243,7 +243,7 @@ void *save_calloc_aligned(const char *name, const char *file, int line,
 }
 
 /* This routine can NOT be called with any pointer */
-void save_free_aligned(const char gmx_unused *name, const char gmx_unused *file, int gmx_unused line, void *ptr)
+void save_free_aligned(const char gmx_unused* name, const char gmx_unused* file, int gmx_unused line, void* ptr)
 {
     gmx::AlignedAllocationPolicy::free(ptr);
 }
@@ -261,7 +261,7 @@ int over_alloc_dd(int n)
 {
     if (g_bOverAllocDD)
     {
-        return static_cast<int>(OVER_ALLOC_FAC*n + 100);
+        return static_cast<int>(OVER_ALLOC_FAC * n + 100);
     }
     else
     {