Commit 94b0ddc0 authored by akalantz's avatar akalantz
Browse files

Add number_threads + change output file

git-svn-id: https://svn.vital-it.ch/svn/hp2c/trunk/Codeml_Variants/Fastcodeml@7105 95c5a404-1f88-0410-a6b0-c3f062b6f34a
parent 6a05a0a8
......@@ -27,7 +27,7 @@
static const double VERY_LOW_LIKELIHOOD = -1e14;
void BranchSiteModel::printFinalVars(std::ostream& aOut) const
std::string BranchSiteModel::printFinalVars(std::ostream& aOut) const
{
// To nicely format num branch lengths per line
static const unsigned int VARS_PER_LINE = 8;
......@@ -39,6 +39,10 @@ void BranchSiteModel::printFinalVars(std::ostream& aOut) const
std::streamsize prec = aOut.precision(VARS_PRECISION);
aOut.setf(std::ios::fixed, std::ios::floatfield);
std::ostringstream oss;
std::streamsize precS = oss.precision(VARS_PRECISION);
oss.setf(std::ios::fixed, std::ios::floatfield);
// Print all variables formatted to be readable
double v0 = 0;
std::vector<double>::const_iterator ix(mVar.begin());
......@@ -61,30 +65,57 @@ void BranchSiteModel::printFinalVars(std::ostream& aOut) const
aOut << " p2a:" << std::setw(VARS_WIDTH) << p[2];
aOut << " p2b:" << std::setw(VARS_WIDTH) << p[3];
aOut << std::endl;
oss << std::endl;
oss << "p0:" << std::setw(VARS_WIDTH) << p[0];
oss << " p1:" << std::setw(VARS_WIDTH) << p[1];
oss << " p2a:" << std::setw(VARS_WIDTH) << p[2];
oss << " p2b:" << std::setw(VARS_WIDTH) << p[3];
oss << std::endl;
}
break;
case 2:
aOut << "w0:" << std::setw(VARS_WIDTH) << *ix;
oss << "w0:" << std::setw(VARS_WIDTH) << *ix;
break;
case 3:
aOut << " k: " << std::setw(VARS_WIDTH) << *ix;
oss << " k: " << std::setw(VARS_WIDTH) << *ix;
break;
case 4:
aOut << " w2: " << std::setw(VARS_WIDTH) << *ix;
oss << " w2: " << std::setw(VARS_WIDTH) << *ix;
break;
default:
aOut << std::setw(VARS_WIDTH) << *ix;
oss << std::setw(VARS_WIDTH) << *ix;
++count_per_line;
if(count_per_line == VARS_PER_LINE)
{
count_per_line = 0;
aOut << std::endl;
oss << std::endl;
}
break;
}
}
aOut << std::endl;
aOut.precision(prec);
oss << std::endl;
oss.precision(precS);
std::string s = oss.str();
return s;
}
void BranchSiteModel::printVar(const std::vector<double>& aVars, double aLnl, std::ostream& aOut) const
......
......@@ -100,7 +100,7 @@ public:
///
/// @param[in] aOut The stream on which the variables should be printed
///
void printFinalVars(std::ostream& aOut=std::cout) const;
std::string printFinalVars(std::ostream& aOut=std::cout) const;
/// Compute the maximum likelihood for the given forest
///
......
......@@ -41,10 +41,10 @@ endif(Boost_FOUND)
# Get the configuration switches
OPTION(USE_LAPACK "Use BLAS/LAPACK" ON)
OPTION(USE_LAPACK "Use BLAS/LAPACK" OFF)
OPTION(USE_MKL_VML "Use Intel MKL vectorized routines" OFF)
OPTION(USE_OPENMP "Compile with OpenMP support" ON)
OPTION(USE_MPI "Use MPI for high level parallelization" OFF)
OPTION(USE_MPI "Use MPI for high level parallelization" ON)
if(NOT WIN32)
OPTION(BUILD_NOT_SHARED "Build FastCodeML not shared" OFF)
endif(NOT WIN32)
......@@ -87,7 +87,7 @@ set(LINK_DIR_LAPACK $ENV{LAPACK_LIB_DIR} CACHE PATH "LAPACK lib dir")
set(INCLUDE_DIR_MKL $ENV{MKL_INCLUDE_DIR} CACHE PATH "MKL include dir")
set(INCLUDE_DIR_NLOPT $ENV{NLOPT_INCLUDE_DIR} CACHE PATH "NLopt include dir")
set(LINK_DIR_NLOPT $ENV{NLOPT_LIB_DIR} CACHE PATH "NLopt lib dir")
set(MATH_LIB_NAMES $ENV{MATH_LIB_NAMES} CACHE STRING "Math libraries (Separated by ';')")
set(MATH_LIB_NAMES $ENV{MATH_LIB_NAMES} CACHE STRING "Math libraries (Separated by ';')")
# Set compiler switches
......@@ -167,68 +167,14 @@ endif(USE_LAPACK)
link_directories(${LINK_DIR_NLOPT})
include_directories(${INCLUDE_DIR_NLOPT})
###########################################################
# Set options for the various CSCS platforms
if($ENV{HOST} MATCHES "matterhorn")
add_definitions(-DBOOST_NO_CWCTYPE)
add_definitions(-xmt2)
add_definitions(-exceptions)
add_definitions(-pl ${CMAKE_CURRENT_BINARY_DIR}/fast.pl)
set(EXTRA_LIBS "m")
endif($ENV{HOST} MATCHES "matterhorn")
###########################################################
if($ENV{HOST} MATCHES "julier")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mkl" CACHE "Linker options" STRING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mkl -restrict" CACHE "Flags used by the compiler during all build types" STRING)
set(CMAKE_CXX_FLAGS_RELEASE "-fast -xSSE4.2 -fstrict-aliasing -Wstrict-aliasing -fomit-frame-pointer -unroll -finline-functions" CACHE "Flags used by the compiler during release build" STRING)
endif($ENV{HOST} MATCHES "julier")
###########################################################
if($ENV{HOST} MATCHES "rosa")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mkl" CACHE "Linker options" STRING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict -mkl" CACHE "Flags used by the compiler during all build types" STRING)
set(CMAKE_CXX_FLAGS_RELEASE "-fast -DNDEBUG -unroll-aggressive -simd -use-Intel-optimized-headers -fomit-frame-pointer -finline-functions" CACHE "Flags used by the compiler during release build" STRING)
endif($ENV{HOST} MATCHES "rosa")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_BUILD_TYPE DEBUG)
#set(CMAKE_CXX_FLAGS_DEBUG "-g -error -pg -O -Wall -std=c++98 -Wextra -Wno-unused-parameter -Wunused" CACHE "Debug mode options" STRING)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -g -pg -O0 -Wall -std=c++98 -Wextra -Wno-unused-parameter -Wunused")
###########################################################
if($ENV{HOST} MATCHES "eiger")
#Set g++ specific compiler settings
if(CMAKE_COMPILER_IS_GNUCXX)
#slow, but suitable for debugging
if(NOT ${CMAKE_CXX_FLAGS_DEBUG} MATCHES "-Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O -Wall -std=c++98 -Wextra -Wno-unused-parameter -Wunused" CACHE "Debug mode options" STRING)
# set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -Wno-unused-result -Wno-write-strings -g -pg -fcheck-data-deps")
# set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -g -pg -fcheck-data-deps" CACHE STRING "Debug mode options")
endif(NOT ${CMAKE_CXX_FLAGS_DEBUG} MATCHES "-Wextra")
# fast; -fomit-frame-pointer and -finline-functions not needed, automatically set by -O3; -O4 or higher not supported by gcc;
# -funroll-loops might be useful, but can sometimes make the code slower (see man gcc). We suppress warnings regarding unused results.
# -O3 -Wall -std=c++98 -Wextra -pedantic -ffast-math -mtune=native -minline-stringops-dynamically -Wno-unused-result -funroll-loops -funsafe-loop-optimizations -Wunsafe-loop-optimizations"
if(NOT ${CMAKE_CXX_FLAGS_RELEASE} MATCHES "-minline-stringops-dynamically")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -fstrict-aliasing -Wstrict-aliasing -std=c++98 -Wextra -ffast-math -msse2 -mtune=native -minline-stringops-dynamically -funroll-loops -fbuiltin" CACHE "Release mode options" STRING)
endif(NOT ${CMAKE_CXX_FLAGS_RELEASE} MATCHES "-minline-stringops-dynamically")
#if(NOT ${CMAKE_EXE_LINKER_FLAGS_RELEASE} MATCHES "Wl")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O1" CACHE "Release mode linker options" STRING)
#endif(NOT ${CMAKE_EXE_LINKER_FLAGS_RELEASE} MATCHES "Wl")
endif(CMAKE_COMPILER_IS_GNUCXX)
endif($ENV{HOST} MATCHES "eiger")
###########################################################
# Executable
add_executable(fast ${SRCS})
......@@ -246,14 +192,3 @@ if(MPI_LIBRARY)
endif(MPI_LIBRARY)
# Make documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile")
set(DOXY_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile")
endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile")
add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG})
endif(DOXYGEN_FOUND)
......@@ -68,7 +68,7 @@ void CmdLine::CmdLineImpl::showHelp(const CSimpleOpt::SOption *aParserOptions)
const char* type = "";
switch(aParserOptions[i].nArgType)
{
case SO_NONE:
case SO_NONE:
type = "(no argument)";
break;
......@@ -124,7 +124,8 @@ void CmdLine::parseCmdLine(int aCnt, char **aVal)
OPT_ONE_STEP,
OPT_COMP_TIMES,
OPT_TRACE,
OPT_FORCE_SERIAL,
OPT_NUM_THREADS,
// OPT_FORCE_SERIAL,
OPT_BRANCH_FROM_FILE,
OPT_ONE_HYP_ONLY,
OPT_INIT_H0_FROM_H1,
......@@ -174,8 +175,10 @@ void CmdLine::parseCmdLine(int aCnt, char **aVal)
{ OPT_COMP_TIMES, "--export-comp-times", SO_REQ_SEP, "" },
{ OPT_TRACE, "-r", SO_NONE, "Trace the maximization run" },
{ OPT_TRACE, "--trace", SO_NONE, "" },
{ OPT_FORCE_SERIAL, "-np", SO_NONE, "Don't use parallel execution" },
{ OPT_FORCE_SERIAL, "--no-parallel", SO_NONE, "" },
{ OPT_NUM_THREADS, "-nt", SO_REQ_SEP, "Number of threads (1 for non parallel execution)" },
{ OPT_NUM_THREADS, "--number-of-threads", SO_REQ_SEP, "" },
//{ OPT_FORCE_SERIAL, "-np", SO_NONE, "Don't use parallel execution" },
//{ OPT_FORCE_SERIAL, "--no-parallel", SO_NONE, "" },
{ OPT_BRANCH_FROM_FILE, "-bf", SO_NONE, "Do only the branch marked in the file as foreground branch" },
{ OPT_BRANCH_FROM_FILE, "--branch-from-file", SO_NONE, "" },
{ OPT_ONE_HYP_ONLY, "-hy", SO_REQ_SEP, "Compute only H0 if 0, H1 if 1" },
......@@ -204,7 +207,7 @@ void CmdLine::parseCmdLine(int aCnt, char **aVal)
{ OPT_MAX_ITER, "--max-iterations", SO_REQ_SEP, "" },
SO_END_OF_OPTIONS
};
// Setup the usage string
const char* usage_msg = "FastCodeML [options] tree_file alignment_file";
......@@ -301,11 +304,11 @@ void CmdLine::parseCmdLine(int aCnt, char **aVal)
case OPT_TRACE:
mTrace = true;
break;
break;
case OPT_FORCE_SERIAL:
/* case OPT_FORCE_SERIAL:
mForceSerial = true;
break;
break;*/
case OPT_BRANCH_FROM_FILE:
mBranchFromFile = true;
......@@ -364,6 +367,13 @@ void CmdLine::parseCmdLine(int aCnt, char **aVal)
tmpi = atoi(args.OptionArg());
if(tmpi <= 0) throw FastCodeMLFatal("Invalid max number of iterations. Should be > 0");
mMaxIterations = static_cast<unsigned int>(tmpi);
break;
case OPT_NUM_THREADS:
mNumThreads = static_cast<unsigned int>(atoi(args.OptionArg()));
/* if (mNumThreads == 1)
mForceSerial = true;*/
if (mNumThreads <=0) throw FastCodeMLFatal("Invalid number of threads");
break;
}
}
......
......@@ -5,6 +5,10 @@
#include <climits>
#include "VerbosityLevels.h"
#ifdef _OPENMP
#include <omp.h>
#endif
/// The default maximum number of optimization steps.
///
static const unsigned int MAX_ITERATIONS=10000;
......@@ -24,7 +28,7 @@ public:
///
/// Here are set the default values for the command line settable parameters
///
CmdLine() :
CmdLine() :
mDeltaValueForGradient(0.0),
mRelativeError(1e-3),
mTreeFile(NULL),
......@@ -45,6 +49,11 @@ public:
mBranchLengthsFromFile(false),
mNoMaximization(false),
mTrace(false),
#ifdef _OPENMP
mNumThreads(omp_get_max_threads()),
#else
mNumThreads(1),
#endif
mForceSerial(false),
mBranchFromFile(false),
mInitH0fromH1(false),
......@@ -96,6 +105,7 @@ public:
bool mInitFromParams; ///< Initialize times from phylo tree and the other from values hardcoded or entered on the command line
bool mCleanData; ///< Remove ambiguous or missing sites from the MSA (genes)
bool mStopIfNotLRT; ///< Stop H0 maximization when LRT cannot be satisfied
unsigned int mNumThreads; ///< Number of threads (if 1 the parallelization is disabled)
private:
struct CmdLineImpl;
......
How to set your hostname for cmake to recognize your system: export HOST=<hostname>
Requirements to generate the executable:
* C++ compiler, e.g. GCC 4
* CMake 2.6 (including ccmake) or later recommended, although compilation possible without
* Boost::Spirit, see http://boost-spirit.com/home/
* Reasonably new BLAS implementation (e.g. OpenBLAS, Goto2, ACML, MKL); packages from various Linux distributions can be used, but this deteriorates performance; recommended: OpenBLAS (http://xianyi.github.io/OpenBLAS/) or Intel MKL
* Reasonably new LAPACK library (e.g. original LAPACK or ACML, MKL); packages from various Linux distributions can be used, but this deteriorates performance
How to compile without CMake:
g++ *.cpp ./libblas.a ./liblapack.a ./libblas.a ./liblapack.a ./libnlopt.a -DUSE_LAPACK -D_USE_OPTIMIZER -lgfortran -lm -o codeml
Notice this does NOT optimize the code!!!
How to generate the FastCodeML executable:
* Generate BLAS if necessary
* Generate LAPACK if necessary
* Generate NLopt library (http://ab-initio.mit.edu/wiki/index.php/NLopt)
* Edit CMakeLists.txt if necessary
* Set paths for libraries (change and execute SETPATHS)
* "ccmake ." and switch USE_MPI and USE_OPENMP on/off (other default settings should be ok)
* make will create an executable "fast"
Computer system:
* Linux preferred, but sources are portable to other platforms
Build verbosely:
cmake .
make VERBOSE=1
......@@ -12,6 +12,8 @@ void WriteResults::outputResults(void)
// Range of branches to be output (for H0 and H1)
std::map<size_t, double>::const_iterator im;
std::map<size_t, std::string>::const_iterator ims;
size_t min_branch = std::numeric_limits<size_t>::max();
size_t max_branch = 0;
for(im = mLnL[0].begin(); im != mLnL[0].end(); ++im)
......@@ -41,17 +43,20 @@ void WriteResults::outputResults(void)
// Write the log-likelihood values (if a value is not present, write NA)
for(size_t branch = min_branch; branch <= max_branch; ++branch)
{
out << "Branch: " << std::setw(4) << branch << " LnL0: ";
out << "Branch: " << std::setw(4) << branch<<std::endl<< std::endl<< " LnL0: ";
// Prints LnL for H0 if present
im = mLnL[0].find(branch);
if(im == mLnL[0].end())
{
out << std::setw(22) << "NA";
out << std::setw(22) << "NA"<< std::endl<<std::endl;
}
else
{
out << std::setw(22) << std::setprecision(15) << std::fixed << im->second;
ims = mParamStr[0].find(branch);
out << std::endl<< std::fixed <<"Branch lengths:" << ims->second << std::endl;
}
out << " LnL1: ";
......@@ -64,6 +69,9 @@ void WriteResults::outputResults(void)
else
{
out << std::setw(22) << std::setprecision(15) << std::fixed << im->second;
ims = mParamStr[1].find(branch);
out << std::endl<< std::fixed <<"Branch lengths:" <<ims->second << std::endl;
}
out << std::endl;
}
......@@ -128,5 +136,17 @@ void WriteResults::savePositiveSelSites(size_t aFgBranch, const std::vector<unsi
// Save the positive selection sites and corresponding probabilities for later printing
mPositiveSelSites[aFgBranch] = std::make_pair(aPositiveSelSites, aPositiveSelSitesProb);
}
void WriteResults::saveParameters(size_t aFgBranch, std::string& aParamStr, unsigned int aHypothesis)
{
// If no file set, then do nothing
if(!mFilename) return;
// Sanity check
if(aHypothesis > 1) return;
// Save the likelihood for later printing
mParamStr[aHypothesis][aFgBranch] = aParamStr;
}
......@@ -65,12 +65,23 @@ public:
///
const std::vector<size_t>& orderSites(const std::vector<unsigned int>& aSites) const;
/// Save the parameters string for later printing.
///
/// @param[in] aFgBranch The foreground branch to which the log-likelihood refers
/// @param[in] aParamStr The parameters string
/// @param[in] aHypothesis The hypothesis (0 for H0 and 1 for H1) for which the log-likelihood has been computed
///
void saveParameters(size_t aFgBranch, std::string& aParamStr, unsigned int aHypothesis);
private:
const char* mFilename; ///< The file to which the results should be written. If null, no printing appear
std::map<size_t, double> mLnL[2]; ///< The log-likelihood for the given fg branch and for the two hypothesis
std::map<size_t, std::pair<std::vector<unsigned int>, std::vector<double> > >
mPositiveSelSites; ///< The sites under positive selection and the corresponding probabilities for a given fg branch
mutable std::vector<size_t> mSiteOrder; ///< The new site+prob order computed by orderSites routine
std::map<size_t, std::string> mParamStr[2]; ///< The parameters string for the given fg branch and for the two hypothesis
};
#endif
......
/// @mainpage FastCodeML
///
/// @section intro_sect Introduction
///
///
/// FastCodeML is a rewrite of CodeML based directly on the pseudocode document.
/// It incorporates various parallelization strategies to be able to exploit modern HPC machines architecture.
/// For this reason there are various parts of the code that can be selected at compile time or run time to experiment with various, possible solutions.
......@@ -9,7 +9,7 @@
/// @section contacts_sect Contacts
///
/// Contact us if you want more information on the project, want to collaborate or suggest new ideas.
///
///
///- Ing. <a href="mailto:mvalle@cscs.ch">Mario Valle</a> - Swiss National Supercomputing Centre (CSCS) - Switzerland
///- The HP2C <a href="mailto:selectome@hp2c.ch">Selectome</a> Project Group - Mainly based in University of Lausanne - Switzerland
///
......@@ -70,6 +70,25 @@ int main(int aRgc, char **aRgv)
// Adjust and report the number of threads that will be used
#ifdef _OPENMP
int num_threads = omp_get_max_threads();
//std::cout<<"max num of thr: "<< num_threads <<std::endl;
if((cmd.mNumThreads >=1)&&(cmd.mNumThreads <= num_threads))
num_threads = cmd.mNumThreads;
// std::cout<<"num of thr: "<< num_threads <<std::endl;
omp_set_num_threads(num_threads);
/*if (num_threads < 2)
cmd.mForceSerial = true;
else
cmd.mForceSerial = false;*/
#else
cmd.mNumThreads=1;
int num_threads = 1;
cmd.mForceSerial = true;
#endif
/*#ifdef _OPENMP
int num_threads = omp_get_max_threads();
if(num_threads < 2 || cmd.mForceSerial)
{
......@@ -80,7 +99,7 @@ int main(int aRgc, char **aRgv)
#else
cmd.mForceSerial = true;
int num_threads = 1;
#endif
#endif*/
#ifdef USE_MPI
// Shutdown messages from all MPI processes except the master
......@@ -245,7 +264,7 @@ int main(int aRgc, char **aRgv)
#ifndef NEW_LIKELIHOOD
forest.addAggressiveReduction();
#endif
forest.cleanReductionWorkingData();
forest.cleanReductionWorkingData();
#ifdef NEW_LIKELIHOOD
forest.prepareNewReduction();
#endif
......@@ -359,7 +378,12 @@ int main(int aRgc, char **aRgv)
std::cout << "(Doesn't pass LRT, skipping)";
std::cout << " Function calls: " << h0.getNumEvaluations() << " ";
std::cout << std::endl << std::endl;
if(lnl0 != std::numeric_limits<double>::infinity()) h0.printFinalVars(std::cout);
if(lnl0 != std::numeric_limits<double>::infinity())
{
std::string s0 = h0.printFinalVars(std::cout);
//std::cout<<"EDW0: "<< s0 <<std::endl;
output_results.saveParameters(fg_branch, s0, 0);
}
std::cout << std::endl;
}
if(cmd.mComputeHypothesis != 0)
......@@ -371,7 +395,12 @@ int main(int aRgc, char **aRgv)
std::cout << std::setprecision(15) << std::fixed << lnl1;
std::cout << " Function calls: " << h1.getNumEvaluations();
std::cout << std::endl << std::endl;
if(lnl1 != std::numeric_limits<double>::infinity()) h1.printFinalVars(std::cout);
if(lnl1 != std::numeric_limits<double>::infinity())
{
std::string s1= h1.printFinalVars(std::cout);
//std::cout<<"EDW1: "<< s1 <<std::endl;
output_results.saveParameters(fg_branch, s1, 1);
}
std::cout << std::endl;
}
if(cmd.mComputeHypothesis > 1)
......@@ -508,7 +537,7 @@ int main(int aRgc, char **aRgv)
/// @section misc_sect Miscellaneous rules
/// In case of error main should return 1.
///
/// Array sizes and corresponding indexes should be size_t. The remaining counters should be unsigned int.
/// Array sizes and corresponding indexes should be size_t. The remaining counters should be unsigned int.
///
/// The null pointer should be written as NULL, not 0 to make clear its purpose.
///
......@@ -566,8 +595,8 @@ Usage:
-r --trace (no argument)
Trace the maximization run
-np --no-parallel (no argument)
Don't use parallel execution
-nt --number-of-threads (required argument)
Number of threads (1 for non parallel execution)
-bf --branch-from-file (no argument)
Do only the branch marked in the file as foreground branch
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment