Porting projects with multithreading dependencies with Emscripten

279 views
Skip to first unread message

fr...@luna-technology.com

unread,
May 10, 2016, 12:39:00 PM5/10/16
to emscripten-discuss
Hello, I have 2 questions. I'm trying to port a project with Emscripten, and the project has among its dependencies Intel TBB library.

Question 1: do I have to rewrite all the project to get rid of all multithreading code, or does Emscripten somehow map multithreaded code to monothreaded code?

Question 2: When trying to build the project with em++, it is parsing dependencies headers and it raises errors with undeclared unidentifiers.
I isolated one particular command with em++ that raises such errors.
When I run the same command with Emscripten clang++ version, there is no problem.
So I'm trying to go through emcc.py to find out which stuff added by emcc, on top of clang++, is causing the problem.
Does that sound like a reasonable approach? Are there any known cause that could explain that a compilation with Emscripten clang++ fastcomp is OK but with em++, is not?

many thanks

Alon Zakai

unread,
May 10, 2016, 12:43:09 PM5/10/16
to emscripten-discuss
1. Emscripten supports pthreads, so if TBB uses that under the hood, things might just work? That happens with c++ standard library <thread>, for example.

https://kripken.github.io/emscripten-site/docs/porting/pthreads.html

2. Yes, sounds like you are seeing a bug that should be fixed. In general that should work.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

François Ruty

unread,
May 10, 2016, 1:22:48 PM5/10/16
to emscripte...@googlegroups.com
ok thanks I'll keep you updated when I have news, in next couple of days

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/-SQboIAl2ew/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Charles Vaughn

unread,
May 10, 2016, 3:11:31 PM5/10/16
to emscripten-discuss
I believe TBB includes x86 specific assembly code, so it won't work.


On Tuesday, May 10, 2016 at 10:22:48 AM UTC-7, François Ruty wrote:
ok thanks I'll keep you updated when I have news, in next couple of days
On Tue, May 10, 2016 at 6:43 PM, Alon Zakai <alon...@gmail.com> wrote:
1. Emscripten supports pthreads, so if TBB uses that under the hood, things might just work? That happens with c++ standard library <thread>, for example.

https://kripken.github.io/emscripten-site/docs/porting/pthreads.html

2. Yes, sounds like you are seeing a bug that should be fixed. In general that should work.
On Tue, May 10, 2016 at 9:39 AM, <fr...@luna-technology.com> wrote:
Hello, I have 2 questions. I'm trying to port a project with Emscripten, and the project has among its dependencies Intel TBB library.

Question 1: do I have to rewrite all the project to get rid of all multithreading code, or does Emscripten somehow map multithreaded code to monothreaded code?

Question 2: When trying to build the project with em++, it is parsing dependencies headers and it raises errors with undeclared unidentifiers.
I isolated one particular command with em++ that raises such errors.
When I run the same command with Emscripten clang++ version, there is no problem.
So I'm trying to go through emcc.py to find out which stuff added by emcc, on top of clang++, is causing the problem.
Does that sound like a reasonable approach? Are there any known cause that could explain that a compilation with Emscripten clang++ fastcomp is OK but with em++, is not?

many thanks

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/-SQboIAl2ew/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

François Ruty

unread,
May 10, 2016, 6:47:27 PM5/10/16
to emscripte...@googlegroups.com
ok many thanks for the information

On Tue, May 10, 2016 at 9:11 PM, Charles Vaughn <cva...@gmail.com> wrote:
I believe TBB includes x86 specific assembly code, so it won't work.

On Tuesday, May 10, 2016 at 10:22:48 AM UTC-7, François Ruty wrote:
ok thanks I'll keep you updated when I have news, in next couple of days
On Tue, May 10, 2016 at 6:43 PM, Alon Zakai <alon...@gmail.com> wrote:
1. Emscripten supports pthreads, so if TBB uses that under the hood, things might just work? That happens with c++ standard library <thread>, for example.

https://kripken.github.io/emscripten-site/docs/porting/pthreads.html

2. Yes, sounds like you are seeing a bug that should be fixed. In general that should work.
On Tue, May 10, 2016 at 9:39 AM, <fr...@luna-technology.com> wrote:
Hello, I have 2 questions. I'm trying to port a project with Emscripten, and the project has among its dependencies Intel TBB library.

Question 1: do I have to rewrite all the project to get rid of all multithreading code, or does Emscripten somehow map multithreaded code to monothreaded code?

Question 2: When trying to build the project with em++, it is parsing dependencies headers and it raises errors with undeclared unidentifiers.
I isolated one particular command with em++ that raises such errors.
When I run the same command with Emscripten clang++ version, there is no problem.
So I'm trying to go through emcc.py to find out which stuff added by emcc, on top of clang++, is causing the problem.
Does that sound like a reasonable approach? Are there any known cause that could explain that a compilation with Emscripten clang++ fastcomp is OK but with em++, is not?

many thanks

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/-SQboIAl2ew/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/-SQboIAl2ew/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

François Ruty

unread,
May 10, 2016, 7:25:02 PM5/10/16
to emscripte...@googlegroups.com
OK so since it appears it's a no-go for Intel TBB, I will have to get rid of this dependency, so I think I won't investigate the issue with em++
Here is how you can reproduce the issue though

OS: ubuntu 14.04 64 bits (AWS VM)

I successfully built Emscripten from source on ubuntu 14.04 64bit using those instructions: https://kripken.github.io/emscripten-site/docs/building_from_source/building_emscripten_from_source_on_linux.html
--> Emscripten 1.36.0

Then I downloaded the most recent source of Intel TBB library --> Intel TBB 4.4

To build Intel TBB, there is no configure script and no install, so you only have to run make.

In the make procedure a lot of stuff is hardcoded so using emmake does not work, it's still g++ which is called for compilation.

So, I symlinked g++ to em++ and I started having a lot of errors, for example:
Unsupported machine word size
or:
./include/tbb/tbb_machine.h:338:9: error: use of undeclared identifier '__TBB_Yield'
        __TBB_Yield();

I think the reason is that em++ probably sets a custom target OS for cross compilation (something like "emscripten" or "unknown", so the TBB configure header has no pre-made config to include for that OS and a lot of stuff end up undefined.
I modified TBB headers to force it to use its pre-made linux 32 bit config and got rid of those errors.

Then, I started having issues about "incorrect output for asm" errors, which were caused by various areas of TBB headers.

BUT, if instead of symlinking g++ to em++, I symlink g++ to emscripten clang (fastcomp) binary, I have no error and everything builds fine!

So, somehow, the em++ wrapper, either via a flag or via an environment variable, causes those errors.




François Ruty

unread,
May 10, 2016, 7:27:37 PM5/10/16
to emscripte...@googlegroups.com
Btw here is the precise command that triggers some errors: (current directory = TBB directory after you unzipped the source code archive)

/home/ubuntu/myfastcomp/emscripten-fastcomp/build/Emscripten/emscripten/em++ -o concurrent_hash_map.o -c -MMD -DTBB_USE_DEBUG -DDO_ITT_NOTIFY -g -O0 -DUSE_PTHREAD -m64 -mrtm -fPIC -D__TBB_BUILD=1 -Wall -Wno-parentheses -Wno-non-virtual-dtor    -I./src -I./src/rml/include -I./include ./src/tbb/concurrent_hash_map.cpp


and this one works fine: (you just replace em++ by clang)


/home/ubuntu/myfastcomp/emscripten-fastcomp/build/Release/bin/clang++ -o concurrent_hash_map.o -c -MMD -DTBB_USE_DEBUG -DDO_ITT_NOTIFY -g -O0 -DUSE_PTHREAD -m64 -mrtm -fPIC -D__TBB_BUILD=1 -Wall -Wno-parentheses -Wno-non-virtual-dtor    -I./src -I./src/rml/include -I./include ./src/tbb/concurrent_hash_map.cpp
Reply all
Reply to author
Forward
0 new messages