Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to using c++ compiler instead of g++ to fix cpp-demos on mac os x #1865

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2d3f56d
CQF is replaced by MQF
shokrof May 2, 2018
02ff941
see if this the problem
shokrof May 2, 2018
cfa0708
check again
shokrof May 2, 2018
7f9cec3
remove exceptions
shokrof May 2, 2018
8b2ecf4
remove exceptions to be continued
shokrof May 2, 2018
0f40129
test flag
shokrof May 2, 2018
e8e8316
test
shokrof May 2, 2018
7c19647
testagain
shokrof May 2, 2018
837dc64
ttt
shokrof May 2, 2018
c6f1a70
reset
shokrof May 2, 2018
9a3fd68
test again
shokrof May 2, 2018
88f1276
Merge branch 'master' into MQFIntegration
ctb May 7, 2018
068f6d4
possible fix for OSx bug
shokrof May 7, 2018
c3c822a
Merge branch 'MQFIntegration' of https://github.com/dib-lab/khmer int…
shokrof May 7, 2018
797d6a3
fix for OSX
shokrof May 7, 2018
c7c62d6
test change
shokrof May 18, 2018
69bd37c
switch to using c++ compiler instead of g++ to fix cpp-demos on mac os x
ctb May 19, 2018
43f3741
Merge branch 'master' of github.com:dib-lab/khmer into mqf/ctbfix
ctb May 19, 2018
6d038ac
update c++-example makefile to use c++ instead of g++
ctb May 19, 2018
207888b
try disabling g++ more globally
ctb May 19, 2018
e4a9b6d
ok try forcing the issue of using cc/c++
ctb May 19, 2018
c5147f9
add -v flag for debugging output
ctb May 20, 2018
2bf68f1
allow shared library linking
ctb May 20, 2018
2fcd67b
include -lstdc++ at very end
ctb May 20, 2018
3d5be36
reorder arguments to work on my laptop :)
ctb May 20, 2018
af5f92a
revert cpp-demos makefile to something that mostly worked; try forcin…
ctb May 20, 2018
ae0d09b
argh fix append to extend
ctb May 20, 2018
3df15f5
specify arch specifically
ctb May 20, 2018
7b3252d
bump xcode version
ctb May 20, 2018
d31922c
bump xcode version again
ctb May 20, 2018
125aad1
ok, try swizzling around extern for cplusplus
ctb May 20, 2018
739d887
Merge branch 'master' into MQFIntegration
ctb May 20, 2018
6d426e4
Merge branch 'MQFIntegration' of github.com:dib-lab/khmer into mqf/ct…
ctb May 20, 2018
03bf2ef
ok, disable extern C stuff
ctb May 20, 2018
c221d92
add -lstdc++ to the compilation command of mqf
shokrof May 20, 2018
70d8abb
print os name
shokrof May 20, 2018
71690f4
No need to specail condition.
shokrof May 20, 2018
f405fef
add linking flags
shokrof May 21, 2018
be181c3
remove bundle
shokrof May 21, 2018
d00757a
add linking flags to cpp examples
shokrof May 21, 2018
1621b1c
add -lstdcc
shokrof May 21, 2018
a4bc9c6
t
shokrof May 21, 2018
bdb59a8
test
shokrof May 21, 2018
453fefb
add -stdlib=libstdc++ to compiling and linking
shokrof May 21, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ matrix:

- os: osx
language: generic
osx_image: xcode7.3
osx_image: xcode9
env:
- TESTATTR="'not linux and not known_failing and not huge'"
- CC=cc
- CXX=c++
# - c++=g++
before_install:
- source ci_scripts/install.sh

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ clean: FORCE
cd src/oxli && $(MAKE) clean || true
cd tests && rm -rf khmertest_* || true
rm -f pytests.xml
cd third-party/cqf && make clean || true
cd third-party/mqf && make clean || true
rm -f $(EXTENSION_MODULE)
rm -f khmer/*.pyc scripts/*.pyc tests/*.pyc oxli/*.pyc \
sandbox/*.pyc khmer/__pycache__/* sandbox/__pycache__/* \
Expand Down
12 changes: 8 additions & 4 deletions examples/c++-api/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
CXXFLAGS=--std=c++11 \
-I ../../include/ \
-I ../../third-party/smhasher \
-I ../../third-party/cqf \
-I ../../third-party/mqf \
-I ../../third-party/seqan/core/include/ \
-I ../../third-party/rollinghash

TESTS=exact-counting bloom consume

ifneq ($(INCLUDE),)
INCLUDE := -I$(INCLUDE)
endif

all: $(TESTS)

%: %.cc ../../src/oxli/liboxli.a
$(CXX) $(CXXFLAGS) $< ../../src/oxli/liboxli.a -o $@
$(CXX) -undefined dynamic_lookup -arch x86_64 -lstdc++ -stdlib=libstdc++ -std=c++11 $(CXXFLAGS) $< ../../src/oxli/liboxli.a -o $@

../../src/oxli/liboxli.a:
cd ../../src/oxli && make
Expand All @@ -18,7 +24,5 @@ run: all
./bloom
./consume reads.fastq

all: $(TESTS)

clean:
-rm -f exact-counting bloom consume
113 changes: 70 additions & 43 deletions include/oxli/storage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Contact: [email protected]
#include <unordered_map>
using MuxGuard = std::lock_guard<std::mutex>;

#include "gqf.h"
#include "gqf.hh"

namespace oxli {
typedef std::unordered_map<HashIntoType, BoundedCounterType> KmerCountMap;
Expand Down Expand Up @@ -410,51 +410,78 @@ public:
*
* \brief A Quotient Filter storage
*/
class QFStorage : public Storage {
class QFStorage : public Storage
{
protected:
QF cf;
QF mf;

public:
QFStorage(int size) {
// size is the power of two to specify the number of slots in
// the filter (2**size). Third argument sets the number of bits used
// in the key (current value of size+8 is copied from the CQF example)
// Final argument is the number of bits allocated for the value, which
// we do not use.
qf_init(&cf, (1ULL << size), size+8, 0);
}

~QFStorage() { qf_destroy(&cf); }

BoundedCounterType test_and_set_bits(HashIntoType khash) {
BoundedCounterType x = get_count(khash);
add(khash);
return !x;
}

//
bool add(HashIntoType khash) {
bool is_new = get_count(khash) == 0;
qf_insert(&cf, khash % cf.range, 0, 1);
return is_new;
}

// get the count for the given k-mer hash.
const BoundedCounterType get_count(HashIntoType khash) const {
return qf_count_key_value(&cf, khash % cf.range, 0);
}

// Accessors for protected/private table info members
// xnslots is larger than nslots. It includes some extra slots to deal
// with some details of how the counting is implemented
std::vector<uint64_t> get_tablesizes() const { return {cf.xnslots}; }
const size_t n_tables() const { return 1; }
const uint64_t n_unique_kmers() const { return cf.ndistinct_elts; }
const uint64_t n_occupied() const { return cf.noccupied_slots; }
void save(std::string outfilename, WordLength ksize);
void load(std::string infilename, WordLength &ksize);

Byte **get_raw_tables() { return nullptr; }
QFStorage(int size)
{
// size is the power of two to specify the number of slots in
// the filter (2**size). Third argument sets the number of bits used
// in the key (current value of size+8 is copied from the CQF example)
// Final argument is the number of bits allocated for the value, which
// we do not use.
_supports_bigcount = true;
qf_init(&mf, (1ULL << size), size+8, 0,2,true,"",2038074761);



}

~QFStorage()
{
qf_destroy(&mf);
}

BoundedCounterType test_and_set_bits(HashIntoType khash)
{
BoundedCounterType x = get_count(khash);
add(khash);
return !x;
}

//
bool add(HashIntoType khash)
{
bool is_new = get_count(khash) == 0;
qf_insert(&mf, khash % mf.metadata->range, 1,false,false);
return is_new;
}

// get the count for the given k-mer hash.
const BoundedCounterType get_count(HashIntoType khash) const
{
return qf_count_key(&mf, khash % mf.metadata->range);
}

// Accessors for protected/private table info members
// xnslots is larger than nslots. It includes some extra slots to deal
// with some details of how the counting is implemented
std::vector<uint64_t> get_tablesizes() const
{
return {mf.metadata->xnslots};
}
const size_t n_tables() const
{
return 1;
}
const uint64_t n_unique_kmers() const
{
return mf.metadata->ndistinct_elts;
}
const uint64_t n_occupied() const
{
return mf.metadata->noccupied_slots;
}
void save(std::string outfilename, WordLength ksize);
void load(std::string infilename, WordLength &ksize);

Byte **get_raw_tables()
{
return nullptr;
}
};


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ undef = NO_UNIQUE_RC
# docker/Dockerfile
# libraries = z,bz2
## if using system libraries
include-dirs = include:third-party/zlib:third-party/bzip2:third-party/seqan/core/include:third-party/smhasher:third-party/cqf:third-party/rollinghash
include-dirs = include:third-party/zlib:third-party/bzip2:third-party/seqan/core/include:third-party/smhasher:third-party/rollinghash:third-party/mqf
# include-dirs = lib
## if using system libraries (broken)

Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def build_dir():
# force 64bit only builds
EXTRA_COMPILE_ARGS.extend(['-arch', 'x86_64', '-mmacosx-version-min=10.7',
'-stdlib=libc++'])
EXTRA_LINK_ARGS.append('-mmacosx-version-min=10.7')
EXTRA_LINK_ARGS.extend(['-mmacosx-version-min=10.7', '-lstdc++'])

if check_for_openmp():
EXTRA_COMPILE_ARGS.extend(['-fopenmp'])
Expand Down Expand Up @@ -330,10 +330,10 @@ def run(self):
if sys.platform == 'darwin' and 'gcov' in self.libraries:
self.libraries.remove('gcov')

cqfcmd = ['bash', '-c', 'cd third-party/cqf && make']
spawn(cmd=cqfcmd, dry_run=self.dry_run)
mqfcmd = ['bash', '-c', 'cd third-party/mqf && make']
spawn(cmd=mqfcmd, dry_run=self.dry_run)
for ext in self.extensions:
ext.extra_objects.append(path_join("third-party", "cqf", "gqf.o"))
ext.extra_objects.append(path_join("third-party", "mqf", "gqf.o"))

if "z" not in self.libraries:
zcmd = ['bash', '-c', 'cd ' + ZLIBDIR + ' && ( test Makefile -nt'
Expand Down
31 changes: 18 additions & 13 deletions src/oxli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ PREFIX=/usr/local

INCLUDES= -I ../../include/ -I ../../third-party/seqan/core/include/ \
-I ../../third-party/smhasher/ \
-I ../../third-party/cqf/ \
-I ../../third-party/rollinghash
-I ../../third-party/mqf/ \
-I ../../third-party/rollinghash \


ifeq ($(USE_SYSTEM_ZLIB), false)
INCLUDES += -I ../../third-party/zlib/
Expand Down Expand Up @@ -102,6 +103,8 @@ CFLAGS += -Wshadow -Wcast-align -Wstrict-prototypes
CFLAGS += $(INCLUDES) $(CPPFLAGS)

LDFLAGS ?=
LDFLAGS += -lstdc++

ifneq ($(USE_SYSTEM_ZLIB), false)
LDFLAGS += -lz
endif
Expand Down Expand Up @@ -164,6 +167,8 @@ SONAME = liboxli.$(SHARED_EXT).$(LIB_VERSION)
SONAME_FLAGS = -install_name $(PREFIX)/lib/$(SONAME) \
-compatibility_version $(LIB_VERSION) \
-current_version $(LIB_VERSION)
LDFLAGS += -stdlib=libstdc++ -std=c++11 -arch x86_64
CXXFLAGS += -stdlib=libstdc++ -std=c++11
else
SHARED_EXT = so
SONAME = liboxli.$(SHARED_EXT).$(LIB_VERSION)
Expand Down Expand Up @@ -221,10 +226,10 @@ BZIP2_OBJS_BASE= \
BZIP2_OBJS=$(addprefix $(BZIP2_DIR)/, $(BZIP2_OBJS_BASE))

# Counting bloom filter
CQF_DIR=../../third-party/cqf
CQF_OBJS_BASE= gqf.o
MQF_DIR=../../third-party/mqf
MQF_OBJS_BASE= gqf.o

CQF_OBJS=$(addprefix $(CQF_DIR)/, $(CQF_OBJS_BASE))
MQF_OBJS=$(addprefix $(MQF_DIR)/, $(MQF_OBJS_BASE))

#### oxli proper below here ####

Expand Down Expand Up @@ -259,9 +264,9 @@ PRECOMILE_OBJS += $(BZIP2_OBJS)
PRECLEAN_TARGS += libbz2clean
endif

LIBOXLI_OBJS += $(CQF_OBJS)
PRECOMILE_OBJS += $(CQF_OBJS)
PRECLEAN_TARGS += libcqfclean
LIBOXLI_OBJS += $(MQF_OBJS)
PRECOMILE_OBJS += $(MQF_OBJS)
PRECLEAN_TARGS += libmqfclean

HEADERS= \
hashtable.hh \
Expand Down Expand Up @@ -290,8 +295,8 @@ zlibclean:
(cd $(ZLIB_DIR) && make distclean)
libbz2clean:
(cd $(BZIP2_DIR) && make -f Makefile-libbz2_so clean)
libcqfclean:
(cd $(CQF_DIR) && make clean)
libmqfclean:
(cd $(MQF_DIR) && make clean)

clean: $(PRECLEAN_TARGS)
rm -f *.o *.a *.$(SHARED_EXT)* oxli.pc $(TEST_PROGS)
Expand All @@ -315,8 +320,8 @@ $(ZLIB_OBJS):
$(BZIP2_OBJS):
(cd $(BZIP2_DIR) && make -f Makefile-libbz2_so $(BZIP2_OBJS_BASE))

$(CQF_OBJS):
(cd $(CQF_DIR) && make)
$(MQF_OBJS):
(cd $(MQF_DIR) && make)

# MurMur3
murmur3.o: ../../third-party/smhasher/MurmurHash3.cc
Expand All @@ -326,7 +331,7 @@ murmur3.o: ../../third-party/smhasher/MurmurHash3.cc
$(CXX) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $<

$(LIBOXLISO): $(LIBOXLI_OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $^
clang++ $(CXXFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $^
ln -sf $(SONAME) liboxli.$(SHARED_EXT)

liboxli.a: $(LIBOXLI_OBJS)
Expand Down
72 changes: 20 additions & 52 deletions src/oxli/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -923,34 +923,14 @@ void QFStorage::save(std::string outfilename, WordLength ksize)
unsigned char version = SAVED_FORMAT_VERSION;
unsigned char ht_type = SAVED_QFCOUNT;


outfile.write(SAVED_SIGNATURE, 4);
outfile.write((const char *) &version, 1);
outfile.write((const char *) &ht_type, 1);
outfile.write((const char *) &ksize, sizeof(ksize));

/* just a hack to handle __uint128_t value. Don't know a better to handle it
* right now */
uint64_t tmp_range;
tmp_range = cf.range;

outfile.write((const char *) &cf.nslots, sizeof(cf.nslots));
outfile.write((const char *) &cf.xnslots, sizeof(cf.xnslots));
outfile.write((const char *) &cf.key_bits, sizeof(cf.key_bits));
outfile.write((const char *) &cf.value_bits, sizeof(cf.value_bits));
outfile.write((const char *) &cf.key_remainder_bits, sizeof(cf.key_remainder_bits));
outfile.write((const char *) &cf.bits_per_slot, sizeof(cf.bits_per_slot));
outfile.write((const char *) &tmp_range, sizeof(tmp_range));
outfile.write((const char *) &cf.nblocks, sizeof(cf.nblocks));
outfile.write((const char *) &cf.nelts, sizeof(cf.nelts));
outfile.write((const char *) &cf.ndistinct_elts, sizeof(cf.ndistinct_elts));
outfile.write((const char *) &cf.noccupied_slots, sizeof(cf.noccupied_slots));

#if BITS_PER_SLOT == 8 || BITS_PER_SLOT == 16 || BITS_PER_SLOT == 32 || BITS_PER_SLOT == 64
outfile.write((const char *) cf.blocks, sizeof(qfblock) * cf.nblocks);
#else
outfile.write((const char *) cf.blocks,
(sizeof(qfblock) + SLOTS_PER_BLOCK * cf.bits_per_slot / 8) * cf.nblocks);
#endif
outfile.write((const char *)mf.metadata,sizeof(qfmetadata));
outfile.write((const char *)mf.blocks,mf.metadata->size);
outfile.close();
}

Expand Down Expand Up @@ -1011,34 +991,22 @@ void QFStorage::load(std::string infilename, WordLength &ksize)
infile.read((char *) &save_ksize, sizeof(save_ksize));
ksize = save_ksize;

infile.read((char *) &cf.nslots, sizeof(cf.nslots));
infile.read((char *) &cf.xnslots, sizeof(cf.xnslots));
infile.read((char *) &cf.key_bits, sizeof(cf.key_bits));
infile.read((char *) &cf.value_bits, sizeof(cf.value_bits));
infile.read((char *) &cf.key_remainder_bits, sizeof(cf.key_remainder_bits));
infile.read((char *) &cf.bits_per_slot, sizeof(cf.bits_per_slot));
infile.read((char *) &tmp_range, sizeof(tmp_range));

infile.read((char *) &cf.nblocks, sizeof(cf.nblocks));
infile.read((char *) &cf.nelts, sizeof(cf.nelts));
infile.read((char *) &cf.ndistinct_elts, sizeof(cf.ndistinct_elts));
infile.read((char *) &cf.noccupied_slots, sizeof(cf.noccupied_slots));
/* just a hack to handle __uint128_t value. Don't know a better to handle it
* right now */
cf.range = tmp_range;
// deallocate previously allocated blocks
free(cf.blocks);
/* allocate the space for the actual qf blocks */
#if BITS_PER_SLOT == 8 || BITS_PER_SLOT == 16 || BITS_PER_SLOT == 32 || BITS_PER_SLOT == 64
cf.blocks = (qfblock *)calloc(cf.nblocks, sizeof(qfblock));
#else
cf.blocks = (qfblock *)calloc(cf.nblocks, sizeof(qfblock) + SLOTS_PER_BLOCK * cf.bits_per_slot / 8);
#endif
#if BITS_PER_SLOT == 8 || BITS_PER_SLOT == 16 || BITS_PER_SLOT == 32 || BITS_PER_SLOT == 64
infile.read((char *) cf.blocks, sizeof(qfblock) * cf.nblocks);
#else
infile.read((char *) cf.blocks,
(sizeof(qfblock) + SLOTS_PER_BLOCK * cf.bits_per_slot / 8) * cf.nblocks);
#endif
mf.mem = (qfmem *)calloc(sizeof(qfmem), 1);
mf.metadata = (qfmetadata *)calloc(sizeof(qfmetadata), 1);
infile.read((char*)mf.metadata,sizeof(qfmetadata));
mf.blocks = (qfblock *)calloc(mf.metadata->size, 1);
infile.read((char*)mf.blocks, mf.metadata->size);

mf.metadata->num_locks =
10;//should be changed to something realistic like function qf_deserialize
mf.mem->metadata_lock = 0;
/* initialize all the locks to 0 */
mf.mem->locks = (volatile int *)calloc(mf.metadata->num_locks,
sizeof(volatile int));





infile.close();
}
Loading