Added fast full buffered I/O buffer in fortran

This commit is contained in:
Guilhem Lavaux 2017-05-13 15:25:18 +02:00
parent 6c74ca6504
commit 0451d8e650
4 changed files with 66 additions and 3 deletions

42
color_msg.cmake Normal file
View File

@ -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()

View File

@ -54,6 +54,9 @@ if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
add_library(_cosmo_bispectrum MODULE _cosmo_bispectrum.cpp) add_library(_cosmo_bispectrum MODULE _cosmo_bispectrum.cpp)
target_link_libraries(_cosmo_bispectrum ${MATH_LIBRARY}) 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) if (Boost_DEP)
add_dependencies(_cosmo_bispectrum ${Boost_DEP}) add_dependencies(_cosmo_bispectrum ${Boost_DEP})
endif() endif()

View File

@ -63,11 +63,14 @@ UnformattedRead::UnformattedRead(const char *fname)
swapOrdering = false; swapOrdering = false;
cSize = Check_32bits; cSize = Check_32bits;
checkPointRef = checkPointAccum = 0; checkPointRef = checkPointAccum = 0;
recordBuffer = 0;
} }
UnformattedRead::~UnformattedRead() UnformattedRead::~UnformattedRead()
{ {
if (recordBuffer != 0)
delete[] recordBuffer;
delete f; delete f;
} }
@ -115,7 +118,7 @@ void UnformattedRead::skip(int64_t off)
checkPointAccum += off; checkPointAccum += off;
} }
void UnformattedRead::beginCheckpoint() void UnformattedRead::beginCheckpoint(bool bufferRecord)
throw (InvalidUnformattedAccess,EndOfFileException) throw (InvalidUnformattedAccess,EndOfFileException)
{ {
if (checkPointAccum != 0) if (checkPointAccum != 0)
@ -129,11 +132,21 @@ void UnformattedRead::beginCheckpoint()
if (f->eof()) if (f->eof())
throw EndOfFileException(); throw EndOfFileException();
if (bufferRecord) {
recordBuffer = new uint8_t[checkPointRef];
f->read(reinterpret_cast<char *>(recordBuffer), checkPointRef);
}
} }
void UnformattedRead::endCheckpoint(bool autodrop) void UnformattedRead::endCheckpoint(bool autodrop)
throw (InvalidUnformattedAccess) throw (InvalidUnformattedAccess)
{ {
if (recordBuffer != 0) {
delete[] recordBuffer;
recordBuffer = 0;
}
if (checkPointRef != checkPointAccum) if (checkPointRef != checkPointAccum)
{ {
if (!autodrop || checkPointAccum > checkPointRef) { if (!autodrop || checkPointAccum > checkPointRef) {
@ -161,7 +174,11 @@ void UnformattedRead::readOrderedBuffer(void *buffer, int size)
if ((checkPointAccum+(uint64_t)size) > checkPointRef) if ((checkPointAccum+(uint64_t)size) > checkPointRef)
throw InvalidUnformattedAccess(); throw InvalidUnformattedAccess();
if (recordBuffer != 0) {
memcpy(buffer, &recordBuffer[checkPointAccum], size);
} else {
f->read((char *)buffer, size); f->read((char *)buffer, size);
}
if (swapOrdering) if (swapOrdering)
{ {

View File

@ -79,7 +79,7 @@ namespace CosmoTool
uint64_t getBlockSize() const { return checkPointRef; } uint64_t getBlockSize() const { return checkPointRef; }
void beginCheckpoint() void beginCheckpoint(bool bufferRecord = false)
throw (InvalidUnformattedAccess,EndOfFileException); throw (InvalidUnformattedAccess,EndOfFileException);
void endCheckpoint(bool autodrop = false) void endCheckpoint(bool autodrop = false)
throw (InvalidUnformattedAccess); throw (InvalidUnformattedAccess);
@ -109,6 +109,7 @@ namespace CosmoTool
uint64_t checkPointRef; uint64_t checkPointRef;
uint64_t checkPointAccum; uint64_t checkPointAccum;
std::ifstream *f; std::ifstream *f;
uint8_t *recordBuffer;
}; };