X-Git-Url: http://git.rrze.uni-erlangen.de/gitweb/?p=LbmBenchmarkKernelsPublic.git;a=blobdiff_plain;f=src%2FMemory.c;fp=src%2FMemory.c;h=d9d1f942c7e11c3c8ddf05e4d2d5ab58fac1f24e;hp=0000000000000000000000000000000000000000;hb=109880839321408644c94a34eb31208460b9f46d;hpb=42cf91486fb5c1ad178b3d21935a1be563e5fa39
diff --git a/src/Memory.c b/src/Memory.c
new file mode 100644
index 0000000..d9d1f94
--- /dev/null
+++ b/src/Memory.c
@@ -0,0 +1,86 @@
+// --------------------------------------------------------------------------
+//
+// Copyright
+// Markus Wittmann, 2016-2017
+// RRZE, University of Erlangen-Nuremberg, Germany
+// markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
+//
+// Viktor Haag, 2016
+// LSS, University of Erlangen-Nuremberg, Germany
+//
+// This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
+//
+// LbmBenchKernels is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// LbmBenchKernels is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with LbmBenchKernels. If not, see .
+//
+// --------------------------------------------------------------------------
+#include
+#include
+#include // strerror
+#include
+
+#include "Base.h"
+#include "Memory.h"
+
+
+int MemAlloc(void ** ptr, size_t bytesToAlloc)
+{
+ void * tmpPtr;
+
+ tmpPtr = malloc(bytesToAlloc);
+
+ if (tmpPtr == NULL) { // && bytesToAlloc != 0) {
+ Error("allocation of %lu bytes failed: %d - %s\n", bytesToAlloc, errno, strerror(errno));
+ exit(1);
+ }
+
+ *ptr = tmpPtr;
+
+ return 0;
+}
+
+int MemAllocAligned(void ** ptr, size_t bytesToAlloc, size_t alignmentBytes)
+{
+ int ret;
+
+ ret = posix_memalign(ptr, alignmentBytes, bytesToAlloc);
+
+ if (ret) {
+ Error("allocation of %lu bytes aligned to %lu bytes failed: %d - %s\n", bytesToAlloc, alignmentBytes, errno, strerror(errno));
+ exit(1);
+ }
+
+ return 0;
+}
+
+
+int MemFree(void ** ptr)
+{
+ Assert(*ptr != NULL);
+
+ free(*ptr);
+
+ *ptr = NULL;
+
+ return 0;
+}
+
+int MemZero(void * ptr, size_t bytesToZero)
+{
+ Assert(ptr != NULL);
+ Assert(bytesToZero > 0);
+
+ memset(ptr, 0, bytesToZero);
+
+ return 0;
+}