gmarcais / Jellyfish

A fast multi-threaded k-mer counter
Other
462 stars 136 forks source link

'aligned_alloc' was not declared in this scope #117

Closed lsmainzer closed 6 years ago

lsmainzer commented 6 years ago

Hello!

I can build Jellyfish 2.2.6 and 2.2.7 but not 2.2.8 or 2.2.9. I use gcc 4.9.4 and Makefile correctly states "CXXFLAGS = -std=c++11 -g -O2"

The error is the same for 2.2.8 and 2.2.9 :

CXX lib/rectangular_binary_matrix.lo lib/rectangular_binary_matrix.cc: In static member function 'static uint64_t jellyfish::RectangularBinaryMatrix::alloc(unsigned int, unsigned int)': lib/rectangular_binary_matrix.cc:35:82: error: 'aligned_alloc' was not declared in this scope if(!(mem = aligned_alloc(sizeof(uint64_t) 2, alloc_columns * sizeof(uint64_t)))) ^ Makefile:1695: recipe for target 'lib/rectangular_binary_matrix.lo' failed make[1]: [lib/rectangular_binary_matrix.lo] Error 1 make[1]: Leaving directory '/usr/local/apps/bioapps/trinity/jellyfish-2.2.9' Makefile:970: recipe for target 'all' failed make: [all] Error 2

Any ideas what this could be?

Thanks a lot, -Liudmila Mainzer

mdshw5 commented 6 years ago

I'm having the same issue, gcc 6.4.0.

lsmainzer commented 6 years ago

Hi, Matt! Thanks for posting.

We found a way to do the install by hacking the source. Specifically, in the file lib/rectangular_binary_matrix.cc we added the following lines right after all the #include statements:

/ ISO C variant of aligned allocation. /

void aligned_alloc (size_t __alignment, size_t __size)
{ void
retval = malloc(size + alignment); size_t rem = ((size_t)retval) % __alignment; if (rem) { retval = (void *)((size_t)retval + __alignment - rem); } return retval; }

Basically defined our own aligned_alloc function. It is only called in this one script, it seems.

So far the runs on small test datasets came back good. However, there is some concern that the allocated memory never gets cleared (as far as we can see from the code), so it could break potentially at some point. But that danger would have existed anyway in the original source.

In any case, hacking the source should not be necessary for an install, so it'd be good to hear some thoughts from the developers as to whether this solution carries any danger, and what would be the right way to do the install without the hack above.

Regards, Liudmila Mainzer

gmarcais commented 6 years ago

tl;dr It is fixed now. The change will appear in develop today and will be released soon thereafter.

Sorry about this bug. I originally used posix_memalign and then changed to aligned_alloc recently to allow compilation on cygwin. Linux did not care, as it supports both, but OSX only supports posix_memalign. It is now properly detected.

I would not use the piece of code above as it could lead to a crash: the returned addressed is not guaranteed to be valid for a call to free.