Repository navigation
Conversation
|
So I tested this out just now.
I tried to reproduce the issue on my mac, but i may have been building it locally using clang by accident rather than gcc. anyways, the original problem is fixed by having my ffi binding (when applicable) explicitly link in libpthreads, though I don't know if thats a good surprise to throw at folks down stream |
|
What I don't understand is that if the library is built with the threading mode (e.g. @xianyi any idea why this is happening? |
|
hrm, i'm building it with the vanilla settings in my TravisCI (not explicitly setting any of the build flags, I think) |
|
For USE_OPENMP=1, OpenBLAS also defined SMP_SERVER. Please use |
|
and USE_OPEMP is set to 0 by default when built with gcc? |
|
Yes, it doesn't set USE_OPENMP by default.
|
|
ok, so its not all my fault :) |
|
Alright but if OpenBLAS uses pthread by default (as was presumably also the case in past versions of OpenBLAS), I don't understand how the new use of Update: I googled a bit more and apparently the GLIBC has a special handling of the export of the The article is only about PPC but some of those considerations might also apply for other architectures. Apparently the link order is very important for this symbol and the author presents several possible options at the end of the article. In particular appending |
|
Weird, I cannot reproduce the issue when building this sample program: https://gist.github.com/ogrisel/6440446#file-openblas_fork-c I do not need to link |
|
Actually I made a mistake, I think I built openblas with clang rather than GCC, rebuilding from scratch now. |
|
Even re-building with GCC I still cannot reproduce the problem. However I cannot find any single occurrence of |
|
I tried again on a Linux with libc 2.15-0ubuntu10.5 and gcc 4.6.3-1ubuntu5 and I do not need to link explicitly against pthread when building a program that links against a freshly built @cartazio could you please try to provide me with a minimalistic reproduction case? Preferably written in C? |
|
@ogrisel i've a few work / business / income related deadlines this week, so no promises about being able to get to it this week Have you written any code that tickles the setthreads function in openblas? "openblas_set_num_threads" |
|
also, in my case I'm static linking to openblas. |
|
if no progress happesn this week, i can def make the time to try to cook up a minimal repro next week |
|
I'll check static linking and |
|
@cartazio I confirm static linking is the trigger: #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <cblas.h>
void* xmalloc(size_t n)
{
void* tmp;
tmp = malloc(n);
if (tmp == NULL) {
fprintf(stderr, "You are about to die\n");
exit(1);
} else {
return tmp;
}
}
int main(int argc, char *argv[])
{
int n;
int i;
double *a, *b, *c;
size_t n_bytes;
if (argc != 2) {
fprintf(stderr, "USAGE: %s size\n", argv[0]);
exit(1);
} else {
n = atoi(argv[1]);
printf("computing for size %d\n", n);
}
n_bytes = sizeof(*a) * n * n;
a = xmalloc(n_bytes);
b = xmalloc(n_bytes);
c = xmalloc(n_bytes);
for(i = 0; i < n * n; ++i) {
a[i] = 1;
b[i] = 1;
}
printf("calling DGEMM...\n");
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n, n, n,
1.0, a, n, b, n, 0.0, c, n);
printf("done.\n");
return 0;
}When I build with a static link to openblas and without pthread, I get: while it works if I build with an additional pthread link on the custom program: |
|
Ok. So is this a bug in OpenBLAS' static linking, or do I need to handle that on my side? |
|
also thank you very very very much @ogrisel, I appreciate you taking the time to help out on this. |
@cartazio I don't know. I am not a pthread / glibc expert.
The We could try to extract the and then include |
|
@xianyi independently of the
|
|
pthread_atfork is indeed quite special, see: In particular, on glibc systems, doing -lpthread actually does statically Can you build the static library with -pthread or -lpthread?
|
|
Thanks @njsmith for the help.
If I am not mistaken, the static library is built by assembling object files into an archive manually with ar: https://github.com/xianyi/OpenBLAS/blob/develop/interface/Makefile#L420 I have tried to manually add a https://github.com/xianyi/OpenBLAS/blob/develop/driver/others/Makefile#L97 but that does not solve the issue. Maybe it should be added to all the objects files that need threads such as: https://github.com/xianyi/OpenBLAS/blob/develop/interface/Makefile#L1126 But that sounds cumbersome to me. |
|
@ogrisel , I used your test codes and static link the library on my Linux box. I got lots of undefined error. Thus, I think the user should add |
…k-reference Do not reference pthread_atfork in non-SMP_SERVER mode
|
thanks! |
|
ok, so if i dylink to openblas i won't have this problem? cool |
Tentative fix for:
#294 (comment)