1
1
2
2
# ' Get the Path to a TBB Library
3
- # '
3
+ # '
4
4
# ' Retrieve the path to a TBB library. This can be useful for \R packages
5
5
# ' using RcppParallel that wish to use, or re-use, the version of TBB that
6
6
# ' RcppParallel has been configured to use.
7
- # '
7
+ # '
8
8
# ' @param name
9
9
# ' The name of the TBB library to be resolved. Normally, this is one of
10
10
# ' `tbb`, `tbbmalloc`, or `tbbmalloc_proxy`. When `NULL`, the library
11
11
# ' path containing the TBB libraries is returned instead.
12
- # '
12
+ # '
13
13
# ' @export
14
14
tbbLibraryPath <- function (name = NULL ) {
15
-
15
+
16
16
# library paths for different OSes
17
17
sysname <- Sys.info()[[" sysname" ]]
18
-
18
+
19
19
# find root for TBB install
20
20
tbbRoot <- Sys.getenv(" TBB_LIB" , unset = tbbRoot())
21
21
if (is.null(name ))
22
22
return (tbbRoot )
23
-
23
+
24
24
# form library names
25
25
tbbLibNames <- list (
26
26
" Darwin" = paste0(" lib" , name , " .dylib" ),
27
27
" Windows" = paste0( name , " .dll" ),
28
28
" SunOS" = paste0(" lib" , name , " .so" ),
29
29
" Linux" = paste0(" lib" , name , c(" .so.2" , " .so" ))
30
30
)
31
-
31
+
32
32
# skip systems that we know not to be compatible
33
33
isCompatible <- ! is_sparc() && ! is.null(tbbLibNames [[sysname ]])
34
34
if (! isCompatible )
35
35
return (NULL )
36
-
36
+
37
37
# find the request library (if any)
38
38
libNames <- tbbLibNames [[sysname ]]
39
39
for (libName in libNames ) {
40
40
tbbName <- file.path(tbbRoot , libName )
41
41
if (file.exists(tbbName ))
42
42
return (tbbName )
43
43
}
44
-
44
+
45
45
}
46
46
47
47
tbbCxxFlags <- function () {
48
-
48
+
49
49
flags <- character ()
50
-
50
+
51
51
# opt-in to TBB on Windows
52
52
if (is_windows()) {
53
53
flags <- c(flags , " -DRCPP_PARALLEL_USE_TBB=1" )
@@ -57,58 +57,78 @@ tbbCxxFlags <- function() {
57
57
flags <- c(flags , " -DTBB_USE_GCC_BUILTINS" )
58
58
}
59
59
}
60
-
60
+
61
61
# if TBB_INC is set, apply those library paths
62
62
tbbInc <- Sys.getenv(" TBB_INC" , unset = TBB_INC )
63
63
if (nzchar(tbbInc )) {
64
-
64
+
65
65
# add include path
66
66
flags <- c(flags , paste0(" -I" , asBuildPath(tbbInc )))
67
-
67
+
68
68
# prefer new interface if version.h exists
69
69
versionPath <- file.path(tbbInc , " tbb/version.h" )
70
70
if (file.exists(versionPath ))
71
71
flags <- c(flags , " -DTBB_INTERFACE_NEW" )
72
-
72
+
73
73
}
74
-
74
+
75
75
# return flags as string
76
76
paste(flags , collapse = " " )
77
-
77
+
78
78
}
79
79
80
80
# Return the linker flags required for TBB on this platform
81
81
tbbLdFlags <- function () {
82
-
82
+
83
+ tbbFlags <- tbbLdFlagsImpl()
84
+
85
+ if (is_windows()) {
86
+ libDir <- system.file(" libs" , .Platform $ r_arch , package = " RcppParallel" )
87
+ libName <- paste0(" RcppParallel" , .Platform $ dynlib.ext )
88
+ newFlags <- sprintf(" -L%s -lRcppParallel" , shQuote(libDir ))
89
+ tbbFlags <- paste(newFlags , tbbFlags )
90
+ }
91
+
92
+ tbbFlags
93
+
94
+ }
95
+
96
+ tbbLdFlagsImpl <- function () {
97
+
83
98
# shortcut if TBB_LIB defined
84
99
tbbLib <- Sys.getenv(" TBB_LINK_LIB" , Sys.getenv(" TBB_LIB" , unset = TBB_LIB ))
85
100
if (nzchar(tbbLib )) {
86
- fmt <- if (is_windows()) " -L%1$s -ltbb -ltbbmalloc"
87
- else " -L%1$s -Wl,-rpath,%1$s -ltbb -ltbbmalloc"
101
+
102
+ fmt <- if (is_windows()) {
103
+ " -L%1$s -ltbb -ltbbmalloc"
104
+ } else {
105
+ " -L%1$s -Wl,-rpath,%1$s -ltbb -ltbbmalloc"
106
+ }
107
+
88
108
return (sprintf(fmt , asBuildPath(tbbLib )))
89
109
}
90
-
110
+
91
111
# on Mac, Windows and Solaris, we need to explicitly link (#206)
92
112
needsExplicitFlags <- is_mac() || is_windows() || (is_solaris() && ! is_sparc())
93
113
if (needsExplicitFlags ) {
94
114
libPath <- asBuildPath(tbbLibraryPath())
95
115
libFlag <- paste0(" -L" , libPath )
96
116
return (paste(libFlag , " -ltbb" , " -ltbbmalloc" ))
97
117
}
98
-
118
+
99
119
# nothing required on other platforms
100
120
" "
101
-
121
+
102
122
}
103
123
104
124
tbbRoot <- function () {
105
-
125
+
106
126
if (nzchar(TBB_LIB ))
107
127
return (TBB_LIB )
108
-
128
+
109
129
rArch <- .Platform $ r_arch
110
130
parts <- c(" lib" , if (nzchar(rArch )) rArch )
111
131
libDir <- paste(parts , collapse = " /" )
112
132
system.file(libDir , package = " RcppParallel" )
113
-
133
+
114
134
}
0 commit comments