# How to Compile VTK-9.0.20210224 with TBB into webassembly

**URL:** https://discourse.vtk.org/t/how-to-compile-vtk-9-0-20210224-with-tbb-into-webassembly/6352
**Category:** Support
**Created:** [August 11, 2021, 9:14am UTC](https://discourse.vtk.org/t/how-to-compile-vtk-9-0-20210224-with-tbb-into-webassembly/6352 "2021-08-11T09:14:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![reichtiger](https://discourse.vtk.org/user_avatar/discourse.vtk.org/reichtiger/32/3671_2.png) [@reichtiger](https://discourse.vtk.org/u/reichtiger)
#### Post date: [August 11, 2021, 9:14am UTC](https://discourse.vtk.org/t/how-to-compile-vtk-9-0-20210224-with-tbb-into-webassembly/6352/1 "2021-08-11T09:14:08Z")

</div>

Hi, all  
I have compiled VTK-9.0.20210224 as lib and it worked well with my project. Now the question is , how can I use TBB or OpenMP for multithreading in web page ? I have tested on win 10 + VTK+TBB it is all OK.

dir list is :  
/work/vtk/build  
/work/wasmtbb/

tbb can be built in /work/wasmtbb/build/linux\_wasm32\_emscripten\_emscripten\_wasm32\_release/libtbb.a  
I tried this :

cmake   
-G Ninja   
-DCMAKE\_TOOLCHAIN\_FILE=${CMAKE\_TOOLCHAIN\_FILE}   
-DBUILD\_SHARED\_LIBS:BOOL=OFF   
-DCMAKE\_BUILD\_TYPE:STRING=Release   
-DVTK\_ENABLE\_LOGGING:BOOL=OFF   
-DVTK\_ENABLE\_WRAPPING:BOOL=OFF   
-DVTK\_LEGACY\_REMOVE:BOOL=ON   
-DVTK\_OPENGL\_USE\_GLES:BOOL=ON   
-DVTK\_USE\_SDL2:BOOL=ON   
-DVTK\_NO\_PLATFORM\_SOCKETS:BOOL=ON   
-DVTK\_MODULE\_ENABLE\_VTK\_hdf5:STRING=NO   
- **DVTK\_SMP\_IMPLEMENTATION\_TYPE:STRING=TBB**   
- **DTBB\_INCLUDE\_DIR:STRING=/work/wasmtbb/include**   
- **DTBB\_LIBRARY\_RELEASE:STRING=/work/wasmtbb/build/linux\_wasm32\_emscripten\_emscripten\_wasm32\_release/libtbb.a**   
…

cmake worked but errors appearted during make like this :

In file included from …/Common/Core/SMP/TBB/vtkSMPTools.cxx:16:  
In file included from …/Common/Core/vtkSMPTools.h:32:  
In file included from Common/Core/vtkSMPThreadLocal.h:81:  
In file included from /work/wasmtbb/include/tbb/enumerable\_thread\_specific.h:20:  
/work/wasmtbb/include/tbb/atomic.h:195:1: error: use of undeclared identifier ‘\_\_TBB\_machine\_cmpswp2’  
\_\_TBB\_DECL\_ATOMIC\_PRIMITIVES(2)  
^  
/work/wasmtbb/include/tbb/atomic.h:149:20: note: expanded from macro ‘\_\_TBB\_DECL\_ATOMIC\_PRIMITIVES’  
return \_\_TBB\_machine\_cmpswp##S(location,new\_value,comparand);   
^  
:29:1: note: expanded from here  
\_\_TBB\_machine\_cmpswp2  
^  
fatal error: too many errors emitted, stopping now [-ferror-limit=]

PS：  
I followed this link [boilerplate/install.md at master · hpcwasm/boilerplate · GitHub](https://github.com/hpcwasm/boilerplate/blob/master/install.md)  
and I have a question , does TBB need boost to work together ?

Any help would be greatly appreciated !

Thanks !

William

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 11, 2021, 10:48am UTC](https://discourse.vtk.org/t/how-to-compile-vtk-9-0-20210224-with-tbb-into-webassembly/6352/2 "2021-08-11T10:48:08Z")

</div>

My understanding is that emscripten won’t handle threading properly. CCing Matt M. as he may have more to say on this topic.

---

<div class="post-metadata">

### Author: ![reichtiger](https://discourse.vtk.org/user_avatar/discourse.vtk.org/reichtiger/32/3671_2.png) [@reichtiger](https://discourse.vtk.org/u/reichtiger)
#### Post date: [August 12, 2021, 8:53am UTC](https://discourse.vtk.org/t/how-to-compile-vtk-9-0-20210224-with-tbb-into-webassembly/6352/3 "2021-08-12T08:53:56Z")

</div>

Will，  
Thanks for reply.  
I checked emscripten website and there are thread samples [Pthreads support — Emscripten 2.0.27 (dev) documentation](https://emscripten.org/docs/porting/pthreads.html)  
But my application is not use multi-thread directly, it run some vtk class which execute in thread like vtkImageGaussianSmooth and vtkImageMarchingCubes. That’s why I need to compile VTK+TBB to speed up .

Thank you again.
