diff --git a/color_msg.cmake b/color_msg.cmake new file mode 100644 index 0000000..4fdf518 --- /dev/null +++ b/color_msg.cmake @@ -0,0 +1,42 @@ +if(NOT WIN32) + string(ASCII 27 Esc) + set(ColourReset "${Esc}[m") + set(ColourBold "${Esc}[1m") + set(Red "${Esc}[31m") + set(Green "${Esc}[32m") + set(Yellow "${Esc}[33m") + set(Blue "${Esc}[34m") + set(Magenta "${Esc}[35m") + set(Cyan "${Esc}[36m") + set(White "${Esc}[37m") + set(BoldRed "${Esc}[1;31m") + set(BoldGreen "${Esc}[1;32m") + set(BoldYellow "${Esc}[1;33m") + set(BoldBlue "${Esc}[1;34m") + set(BoldMagenta "${Esc}[1;35m") + set(BoldCyan "${Esc}[1;36m") + set(BoldWhite "${Esc}[1;37m") +endif() + +function(cmessage) + list(GET ARGV 0 MessageType) + if(MessageType STREQUAL FATAL_ERROR OR MessageType STREQUAL SEND_ERROR) + list(REMOVE_AT ARGV 0) + message(${MessageType} "${BoldRed}${ARGV}${ColourReset}") + elseif(MessageType STREQUAL CWARNING) + list(REMOVE_AT ARGV 0) + message(STATUS "${BoldYellow}${ARGV}${ColourReset}") + elseif(MessageType STREQUAL WARNING) + list(REMOVE_AT ARGV 0) + message(${MessageType} "${BoldYellow}${ARGV}${ColourReset}") + elseif(MessageType STREQUAL AUTHOR_WARNING) + list(REMOVE_AT ARGV 0) + message(${MessageType} "${BoldCyan}${ARGV}${ColourReset}") + elseif(MessageType STREQUAL STATUS) + list(REMOVE_AT ARGV 0) + message(${MessageType} "${Green}${ARGV}${ColourReset}") + else() + message("${ARGV}") + endif() +endfunction() + diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index da703d4..ede9c5b 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -54,6 +54,9 @@ if (Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) add_library(_cosmo_bispectrum MODULE _cosmo_bispectrum.cpp) target_link_libraries(_cosmo_bispectrum ${MATH_LIBRARY}) + if(ENABLE_OPENMP) + set_target_properties(_cosmo_bispectrum PROPERTIES COMPILE_FLAGS "${OpenMP_CXX_FLAGS}" LINK_FLAGS "${OpenMP_CXX_FLAGS}") + endif() if (Boost_DEP) add_dependencies(_cosmo_bispectrum ${Boost_DEP}) endif() diff --git a/src/fortran.cpp b/src/fortran.cpp index 678e523..c41a720 100644 --- a/src/fortran.cpp +++ b/src/fortran.cpp @@ -63,11 +63,14 @@ UnformattedRead::UnformattedRead(const char *fname) swapOrdering = false; cSize = Check_32bits; checkPointRef = checkPointAccum = 0; + recordBuffer = 0; } UnformattedRead::~UnformattedRead() { + if (recordBuffer != 0) + delete[] recordBuffer; delete f; } @@ -115,7 +118,7 @@ void UnformattedRead::skip(int64_t off) checkPointAccum += off; } -void UnformattedRead::beginCheckpoint() +void UnformattedRead::beginCheckpoint(bool bufferRecord) throw (InvalidUnformattedAccess,EndOfFileException) { if (checkPointAccum != 0) @@ -129,11 +132,21 @@ void UnformattedRead::beginCheckpoint() if (f->eof()) throw EndOfFileException(); + + if (bufferRecord) { + recordBuffer = new uint8_t[checkPointRef]; + f->read(reinterpret_cast(recordBuffer), checkPointRef); + } } void UnformattedRead::endCheckpoint(bool autodrop) throw (InvalidUnformattedAccess) { + if (recordBuffer != 0) { + delete[] recordBuffer; + recordBuffer = 0; + } + if (checkPointRef != checkPointAccum) { if (!autodrop || checkPointAccum > checkPointRef) { @@ -161,7 +174,11 @@ void UnformattedRead::readOrderedBuffer(void *buffer, int size) if ((checkPointAccum+(uint64_t)size) > checkPointRef) throw InvalidUnformattedAccess(); - f->read((char *)buffer, size); + if (recordBuffer != 0) { + memcpy(buffer, &recordBuffer[checkPointAccum], size); + } else { + f->read((char *)buffer, size); + } if (swapOrdering) { diff --git a/src/fortran.hpp b/src/fortran.hpp index 91136a5..49d8e67 100644 --- a/src/fortran.hpp +++ b/src/fortran.hpp @@ -79,7 +79,7 @@ namespace CosmoTool uint64_t getBlockSize() const { return checkPointRef; } - void beginCheckpoint() + void beginCheckpoint(bool bufferRecord = false) throw (InvalidUnformattedAccess,EndOfFileException); void endCheckpoint(bool autodrop = false) throw (InvalidUnformattedAccess); @@ -109,6 +109,7 @@ namespace CosmoTool uint64_t checkPointRef; uint64_t checkPointAccum; std::ifstream *f; + uint8_t *recordBuffer; };