-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible bug in configure.ac #375
Comments
Hi there. Thanks for raising an issue but it is actually somewhat woefully short on details:
I effectively work only on Linux where things generally work. Other OSs have issues even getting OpenMP to you--the recommended way seem to change every year on macOS from what I can tell. Windows is a different beast again but we do not run All that said, it is of course entirely possibly that over the rewrites we dropped a ball and don't set a variable right. But here I see So for example on my system edd@rob:~/git/rcpparmadillo(master)$ ./configure
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether ccache g++-11 accepts -g... yes
checking how to run the C++ preprocessor... ccache g++-11 -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether ccache g++-11 accepts -g... (cached) yes
checking whether we have a suitable tempdir... /tmp
checking whether R CMD SHLIB can already compile programs using OpenMP... yes ## We see R already has it
checking LAPACK_LIBS... system LAPACK found
configure: creating ./config.status
config.status: creating inst/include/RcppArmadilloConfigGenerated.h
config.status: creating src/Makevars
edd@rob:~/git/rcpparmadillo(master)$
edd@rob:~/git/rcpparmadillo(master)$ grep -i openmp src/Makevars ## and we do not add it here
## Also, OpenMP support in Armadillo prefers C++11 support. However, for wider
## And with R 3.4.0, and RcppArmadillo 0.7.960.*, we turn C++11 on as OpenMP
edd@rob:~/git/rcpparmadillo(master)$
edd@rob:~/git/rcpparmadillo(master)$ grep openmp /etc/R/Makeconf ## but it really is in R's
DYLIB_LDFLAGS = -shared -fopenmp# $(CFLAGS) $(CPICFLAGS)
MAIN_LDFLAGS = -Wl,--export-dynamic -fopenmp
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
edd@rob:~/git/rcpparmadillo(master)$ and when I then compile this one-liner Rcpp::cppFunction("arma::mat doubleup(arma::mat a) { return a+a; }", depends="RcppArmadillo", verbose=TRUE) I do in fact see what I need to see:
which has |
I am on Arch Linux using the most recent CRAN version of rcpparmadillo and R. Don't have a reproducible example.
Sent From My Mobile Device
…________________________________
From: Dirk Eddelbuettel ***@***.***>
Sent: Tuesday, May 10, 2022 5:23:39 PM
To: RcppCore/RcppArmadillo ***@***.***>
Cc: Justin Silverman ***@***.***>; Author ***@***.***>
Subject: Re: [RcppCore/RcppArmadillo] Possible bug in configure.ac (Issue #375)
Hi there. Thanks for raising an issue but it is actually somewhat woefully short on details:
* What OS? Which versions of the OS?
* What versions of R, the packages involved, the compiler?
* If this varies on the platform, how did you install them?
* Do you have a reproducible example?
I effectively work only on Linux where things generally work. Other OSs have issues even getting OpenMP to you--the recommended way seem to change every year on macOS from what I can tell. Windows is a different beast again but we do not run configure there.
—
Reply to this email directly, view it on GitHub<#375 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AADOORXYAPQX4BQHAU63Q7DVJLHVXANCNFSM5VS2MPBA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Openmp, R, and gcc we installed from official Arch repos and are up to date.
Sent From My Mobile Device
…________________________________
From: Justin Silverman ***@***.***>
Sent: Tuesday, May 10, 2022 5:36:16 PM
To: RcppCore/RcppArmadillo ***@***.***>; RcppCore/RcppArmadillo ***@***.***>
Cc: Author ***@***.***>
Subject: Re: [RcppCore/RcppArmadillo] Possible bug in configure.ac (Issue #375)
I am on Arch Linux using the most recent CRAN version of rcpparmadillo and R. Don't have a reproducible example.
Sent From My Mobile Device
________________________________
From: Dirk Eddelbuettel ***@***.***>
Sent: Tuesday, May 10, 2022 5:23:39 PM
To: RcppCore/RcppArmadillo ***@***.***>
Cc: Justin Silverman ***@***.***>; Author ***@***.***>
Subject: Re: [RcppCore/RcppArmadillo] Possible bug in configure.ac (Issue #375)
Hi there. Thanks for raising an issue but it is actually somewhat woefully short on details:
* What OS? Which versions of the OS?
* What versions of R, the packages involved, the compiler?
* If this varies on the platform, how did you install them?
* Do you have a reproducible example?
I effectively work only on Linux where things generally work. Other OSs have issues even getting OpenMP to you--the recommended way seem to change every year on macOS from what I can tell. Windows is a different beast again but we do not run configure there.
—
Reply to this email directly, view it on GitHub<#375 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AADOORXYAPQX4BQHAU63Q7DVJLHVXANCNFSM5VS2MPBA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Well when you are back at your computer excute the line I added in my last post: Rcpp::cppFunction("arma::mat doubleup(arma::mat a) { return a+a; }", depends="RcppArmadillo", verbose=TRUE) It just adds two matrices (when you call it) but that is immaterial. Setting If you have no reproducible example, how do you know that (per your first post) "[the suspected issue is] causing parallelization to not work for me". I.e. how do you tell if parallelization is, or is not, working for you? |
Sorry for the delay. I realized I was becoming "that guy" who is super unhelpful and wanted to take my time in responding. Here is the relevant ssection of loading / building the package:
I think the critical parts look like yours. Here is the output of configure wrt src/Makevars:
Critical thing I noticed is that the openmp_flag must have been "" because there is no Functionally here is my evidence of the lack of parallelization (unless I am misunderstanding something which is possible):
I load the package and run this function and here is the ouput:
(no parallelization). Now if I modify configure.ac as I mentioned above (run autoreconf) then load the package, my Makevars now reads:
and the output of that same function now is:
Note. I think one difference between out setups is that I don't have a global system setting (e.g., /etc/R/Makeconf) that specifies to use openmp. My guess is that many users will not have that either. Justin |
Oh and here is the output you asked for:
|
Overall I think the logic is fairly straight forward. As configure.ac is currently written, if openmp_already_works is yes, then the openmp_flag never gets set and remains an empty string. |
I am sorry but I do not have time for 5000 word three message flood submissions. If you can demonstrate something replicably and concisely without using extraneous package (no devtools, please: stick to R CMD check or Rcpp functions) then I will reconsider. |
Look at
You have |
Lastly your example works if you enable the OpenMP plugin for Rcpp so that is a different issue: > Rcpp::sourceCpp("/tmp/rcpparma375.cpp")
> get_threads(5)
0 tid
5 nThreads
4 tid
5 nThreads
2 tid1
5 nThreads
3 tid
5 nThreads
tid
5 nThreads
> Modified code: #include <RcppArmadillo.h>
#include <omp.h>
using namespace Rcpp;
// [[Rcpp::plugins(openmp)]]
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
void get_threads(int nthreads) {
omp_set_num_threads(nthreads);
#pragma omp parallel for
for(int i = 0; i < 5; i++){
int tid = omp_get_thread_num();
std::cout<<tid<<"\t tid"<<std::endl;
int nThreads = omp_get_num_threads();
std::cout<<nThreads<<"\t nThreads"<<std::endl;
}
} |
So first off, my appologies for comming off as "flooding". I realize that I have -fopenmp in there, and I am not the Cpp expert you are. That said, even when I add the pluggins, I still don't get multithreading (the following was run on my system using exactly the same modifed code as you provided).
That said, when I made the change to configure.ac mentioned in my original post, I get multithreading. |
What it boils down to, I think, is whether Arch gets in the way. Do you have 'fopenmp' in your Makeconf? You can run the one-line expression I use here: edd@rob:~$ grep fopenmp $(R RHOME)/etc/Makeconf
DYLIB_LDFLAGS = -shared -fopenmp# $(CFLAGS) $(CPICFLAGS)
MAIN_LDFLAGS = -Wl,--export-dynamic -fopenmp
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
edd@rob:~$ If you have it, then we don't need your fix. If you don't have it, we need a fix either to the system Arch or maybe the one you suggested. But so far I do not have a clear view into what's going on. |
Actually I do it turns out:
|
That's not bad, and what I suspected (as R is really rugged here and can be trusted). I suspect we have more of an issue with documentation here. You may be building your testcase wrong, no more, no less. And I don't want to sound whiny but you haven't exactly made clear how you are building your sample code and what options may or may not be set but I have the suspicion that that is the issue -- not how RcppArmadillo sets itself up. |
While I don't understand what you mean by documentation. Here is a more cookbook set of steps and details that may satisfy you other point:
So thats not expected. But I can get the expected behavior if I modify autoconfigure.ac
then I run autoreconf to regenerate configure script then I repeat steps 4-7 from above. Then the output is:
So all this said, it seems very likely to me that there is something suboptimal in configure.ac Edit: To help, I have put together a pull request that you can accept or not. I am happy to help out if that fix is not ideal but I think I am done trying to convince that the bug exists. |
That is exactly the right test of adding an OpenMP using tester to the package. In my (weak) excuse, I think the (As an aside: don't just quote suggested code changes. Show them as a |
Re mac OS: wholehartedly agree. Actually trying to develop C++ header libraries with R bindings (thank you for Rcpp btw) with OpenMP support is actually what finally got me away from mac to linux. Actually I posted one some online forum asking for advise and I believe it was you that said something like "come to fedora" or something. Anyways. Thanks for the advice about diff output. Will work that into future bug reports. |
The key giveway, and I am once again going to harp on the world's smalled violin here, is that And it must have been my evil twin saying that. I know nothing about Fedora, but a bit about Debian + Ubuntu. Close enough for a refugee macOS user like you 😉 |
Ensure openmp propagates in the 'found' case (closes #375)
This (what I think is a) bug was causing parallelization to not work for me.
If I read it correctly, configure.ac doesn't set
can_use_openmp="yes"
ifopenmp_already_works="yes"
. As a result openmp_flag never gets set (e.g., stays an empty string) and then parallelization may not work.For me, I was able to fix this by adding the commented line
The text was updated successfully, but these errors were encountered: