Browse code

added parallelization for mac

chakalakka authored on 09/06/2015 08:30:26
Showing 3 changed files

... ...
@@ -1,8 +1,111 @@
1
+#=======================================#
2
+### INSTALLATION INSTRUCTIONS FOR MAC ###
3
+#=======================================#
4
+
5
+#######Begin by installing xcode and xcode command line tools#######
6
+
7
+##Install Xcode using the appstore (free)
8
+
9
+##Open a terminal and instal Xcode command line tools
10
+xcode-select --install
11
+
12
+##Agree to Xcode license in Terminal
13
+sudo xcodebuild -license
14
+
15
+
16
+
17
+#######The following steps may be necessary in order to install some of chromstaR dependencies#######
18
+
19
+##In a terminal window, check if libcurl, libxml and ccache are installed
20
+curl-config --version
21
+xmllint --version
22
+ccache --version
23
+
24
+##if not installed, install (or update) them through macports
25
+##Install macports from this website https://www.macports.org/install.php
26
+##Go back to terminal and selfupdate macports
27
+sudo port -v selfupdate
28
+##install libcurl, libxml and ccache
29
+sudo port install curl libxml libxml2 ccache
30
+
31
+
32
+##Install the gfortran libraries
33
+curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
34
+sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
35
+
36
+
37
+
38
+#######As of June 5th, 2015, the following steps are needed to install chromstaR on OS X Yosemite (10.10) and below#######
39
+
40
+##Install Xcode using the appstore (free)
41
+
42
+##Open a terminal and instal Xcode command line tools
43
+xcode-select --install
44
+
45
+##Agree to Xcode license in Terminal
46
+sudo xcodebuild -license
47
+
48
+##OSX doesn't use the latest version of the GCC compiler allowing to use multithreading in R. To make the installation of chromstaR
49
+##successful, a recent version of GCC needs to be installed. This can be done using Homebrew
50
+##Note: you may have to chown the following directories in order for homebrew to install the previous packages and library
51
+sudo chown {your-user-name} /usr/local/bin
52
+sudo chown {your-user-name} /usr/local/include
53
+sudo chown {your-user-name} /usr/local/lib
54
+sudo chown {your-user-name} /usr/local/share
55
+
56
+##Install homebrew and the lastest versions of GCC (very long, takes 30 mins to 2 hours to compile) and CCache
57
+ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
58
+brew install gcc --without-multilib
59
+brew install clang-omp
60
+brew install ccache
61
+##Note: be careful in warning messages provided by homebrew and follow it's instruction/suggestions
62
+
63
+
64
+#Modify ~/.R/Makvars in order to tell R which compiler to use. Replace everything in that file by what is below
65
+###########################################################
66
+CFLAGS +=             -O3 -Wall -pipe -pedantic -std=gnu99
67
+CXXFLAGS +=           -O3 -Wall -pipe -Wno-unused -pedantic 
68
+
69
+CC=ccache gcc
70
+CXX=ccache g++
71
+SHLIB_CXXLD=g++
72
+
73
+SHLIB_OPENMP_CFLAGS = -fopenmp
74
+SHLIB_OPENMP_CXXFLAGS = -fopenmp
75
+SHLIB_OPENMP_FCFLAGS = -fopenmp
76
+SHLIB_OPENMP_FFLAGS = -fopenmp
77
+
78
+
79
+FC=ccache gfortran
80
+F77=ccache gfortran
81
+MAKE=make -j8
82
+
83
+###########################################################
84
+
85
+
86
+##Download chromstaR packages locally, as you may have to modify some of the files
87
+##In chromstaR Package, modifies /scr/R_interface.cpp and src/scalehmm.h
88
+##to replace #include <omp.h>  by #include <libiomp/omp.h> 
89
+##if these corrections were already present in the files, please ignore and install directly from bitbucket (see below)
90
+
91
+
92
+#=====================================================#
93
+### INSTALLATION INSTRUCTIONS FOR LINUX AND WINDOWS ###
94
+#=====================================================#
95
+
96
+##In R, install the following packages
1 97
 install.packages('devtools')
2 98
 source("http://bioconductor.org/biocLite.R")
3 99
 biocLite("GenomicRanges")
4 100
 biocLite("GenomicAlignments")
5 101
 biocLite("BSgenome")
6 102
 library(devtools)
103
+##If you have modified R_interface.cpp and scalhmm.h in chromstaR
104
+install.packages("path-to-chromstaR-package", type='source', repos=NULL)
105
+##If you have not modified chromstaR
7 106
 install_bitbucket('chakalakka/chromstaR', username='chakalakka', password='chromstaR2015')
8 107
 install_github('chakalakka/chromstaRExampleData')
108
+
109
+
110
+
111
+
... ...
@@ -1,9 +1,14 @@
1 1
 #include "utility.h"
2 2
 #include "scalehmm.h"
3 3
 #include <vector> // storing density functions in multivariate
4
-#include <omp.h> // parallelization options
5 4
 #include <string> // strcmp
6 5
 
6
+#if defined TARGET_OS_MAC || defined __APPLE__
7
+#include <libiomp/omp.h> // parallelization options on mac
8
+#elif defined __linux__ || defined _WIN32 || defined _WIN64
9
+#include <omp.h> // parallelization options
10
+#endif
11
+
7 12
 static ScaleHMM* hmm; // declare as static outside the function because we only need one and this enables memory-cleanup on R_CheckUserInterrupt()
8 13
 static int** multiO;
9 14
 
... ...
@@ -1,7 +1,6 @@
1 1
 #ifndef SCALEHMM_H
2 2
 #define SCALEHMM_H
3 3
 
4
-#include <omp.h> // #pragma omp parallel
5 4
 #include <R.h> // R_CheckUserInterrupt()
6 5
 #include <vector> // storing density functions
7 6
 #include <time.h> // time(), difftime()
... ...
@@ -9,6 +8,12 @@
9 8
 #include "densities.h"
10 9
 #include <string> // strcmp
11 10
 
11
+#if defined TARGET_OS_MAC || defined __APPLE__
12
+#include <libiomp/omp.h> // parallelization options on mac
13
+#elif defined __linux__ || defined _WIN32 || defined _WIN64
14
+#include <omp.h> // parallelization options
15
+#endif
16
+
12 17
 class ScaleHMM  {
13 18
 
14 19
 	public: