SCOREC / core

parallel finite element unstructured meshes
Other
181 stars 63 forks source link

Build fails on non-Linux systems: error: variable has incomplete type 'struct mallinfo' #409

Open yurivict opened 9 months ago

yurivict commented 9 months ago

Errors/warnings:

/usr/ports/math/scorec-core/work/core-2.2.8/pcu/reel/reel.c:62:13: warning: incompatible pointer types passing 'FILE *' (aka 'struct __sFILE *') to parameter of type 'const char *' [-Wincompatible-pointer-types]
  reel_fail(stderr, "reel_protect only supported on Linux and OS X");
            ^~~~~~
/usr/include/stdio.h:241:16: note: expanded from macro 'stderr'
#define stderr  __stderrp
                ^~~~~~~~~
/usr/ports/math/scorec-core/work/core-2.2.8/pcu/reel/reel.c:16:28: note: passing argument to parameter 'format' here
void reel_fail(const char* format, ...)
                           ^
1 warning generated.
--- pcu/CMakeFiles/pcu.dir/pcu_mem.c.o ---
/usr/ports/math/scorec-core/work/core-2.2.8/pcu/pcu_mem.c:55:33: warning: call to undeclared function 'mallinfo'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  struct mallinfo meminfo_now = mallinfo();
                                ^
/usr/ports/math/scorec-core/work/core-2.2.8/pcu/pcu_mem.c:55:19: error: variable has incomplete type 'struct mallinfo'
  struct mallinfo meminfo_now = mallinfo();
                  ^
/usr/ports/math/scorec-core/work/core-2.2.8/pcu/pcu_mem.c:55:10: note: forward declaration of 'struct mallinfo'
  struct mallinfo meminfo_now = mallinfo();
         ^
1 warning and 1 error generated.

mallinfo is a linux-specific function.

Version: 2.2.8 clang-16 FreeBSD 14.0 STABLE

bobpaw commented 9 months ago

BSD might require -lmalloc according to the manpage.

yurivict commented 9 months ago

No, mallocinfo() only exists in SunOS. FreeBSD doesn't have it.


As an alternative, you can use Google's tcmalloc from the google-perftools package. google-perftools has better performance than most other malloc libraries, and it provides all sorts of information about memory allocator.

bobpaw commented 9 months ago

Is this malloc documentation available on your FreeBSD? It should also be possible (albeit a pain) to extract memory information from the malloc_stats_print function described there.

I created #411. Can you see if it fixes the first warning?

bobpaw commented 9 months ago

I don't have a BSD system of my own and won't be able to spin up a VM for a few weeks. Since PCU_GetMem and pumi_getMem are only used in debug messages in a few places, it's probably ok to do something like this for now (until a more robust fix for FreeBSD is added):

diff --git a/pcu/pcu_mem.c b/pcu/pcu_mem.c
index 8ac2345c..5532ffac 100644
--- a/pcu/pcu_mem.c
+++ b/pcu/pcu_mem.c
@@ -8,6 +8,7 @@

 *******************************************************************************/
 #include <PCU.h>
+#include "reel.h" // reel_fail

 #if defined(__APPLE__)

@@ -54,5 +55,7 @@ double PCU_GetMem() {
 #elif defined(__GNUC__)
   struct mallinfo meminfo_now = mallinfo();
   return ((double)meminfo_now.arena)/M;
+#else
+  reel_fail("mallinfo not supported.");
 #endif
 }

Or, if you want those tests to run more or less successfully:

diff --git a/pcu/pcu_mem.c b/pcu/pcu_mem.c
index 8ac2345c..889650fb 100644
--- a/pcu/pcu_mem.c
+++ b/pcu/pcu_mem.c
@@ -54,5 +54,7 @@ double PCU_GetMem() {
 #elif defined(__GNUC__)
   struct mallinfo meminfo_now = mallinfo();
   return ((double)meminfo_now.arena)/M;
+#else
+  return 0.0;
 #endif
 }

In any case, I'm sure there are other systems where mallinfo isn't available, so there ought to be a solution.