1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[546],{3075:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>r,contentTitle:()=>o,default:()=>p,frontMatter:()=>s,metadata:()=>d,toc:()=>l});var n=a(7462),i=(a(7294),a(3905));a(5657);const s={sidebar_position:2},o="Create a Multi-Threading-Enabled Custom Build",d={unversionedId:"advanced/multi-threading/custom-build",id:"advanced/multi-threading/custom-build",title:"Create a Multi-Threading-Enabled Custom Build",description:"Have a look at this test for a working example.",source:"@site/docs/05-advanced/03-multi-threading/02-custom-build.md",sourceDirName:"05-advanced/03-multi-threading",slug:"/advanced/multi-threading/custom-build",permalink:"/docs/advanced/multi-threading/custom-build",draft:!1,editUrl:"https://github.com/donalffons/opencascade.js/tree/master/website/docs/05-advanced/03-multi-threading/02-custom-build.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"Intro",permalink:"/docs/advanced/multi-threading/intro"},next:{title:"Intro",permalink:"/docs/advanced/exceptions/intro"}},r={},l=[],u={toc:l},c="wrapper";function p(e){let{components:t,...a}=e;return(0,i.kt)(c,(0,n.Z)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h1",{id:"create-a-multi-threading-enabled-custom-build"},"Create a Multi-Threading-Enabled Custom Build"),(0,i.kt)("p",null,"Have a look at ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/donalffons/opencascade.js/blob/master/test/multi-threaded.test.ts"},"this test")," for a working example."),(0,i.kt)("p",null,"Start by pulling the latest Docker image with multi-threading support."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-sh"},"docker pull donalffons/opencascade.js:multi-threaded\n")),(0,i.kt)("p",null,"Next, create a custom build definition. The following will create a full build (based on ",(0,i.kt)("a",{parentName:"p",href:"https://github.com/donalffons/opencascade.js/blob/master/builds/opencascade.full.yml"},"this one"),", which is distributed as the NPM package) with multi-threading support."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yml"},"mainBuild:\n name: customBuild.multi-threaded.js\n # not specifying any bindings will bind everything\n emccFlags:\n # These are just the default values as defined in /src/customBuildSchema.py\n - -O3\n - -sEXPORT_ES6=1\n - -sUSE_ES6_IMPORT_META=0\n - -sEXPORTED_RUNTIME_METHODS=['FS']\n - -sINITIAL_MEMORY=100MB\n - -sMAXIMUM_MEMORY=4GB\n - -sALLOW_MEMORY_GROWTH=1\n - -sUSE_FREETYPE=1\n - -sLLD_REPORT_UNDEFINED\n - --no-entry\n\n # Currently, the thread pool size has to be defined at compile time, otherwise\n # the execution will hang indefinitely during initialization. The value below\n # will allocate as many threads as there are cpu cores in the system - for\n # the browser. When building a NodeJS application, you might want to use\n # ='require(\"os\").cpus().length' instead.\n - -sPTHREAD_POOL_SIZE='navigator.hardwareConcurrency'\n")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-sh"},'docker run \\\n -v "$(pwd):/src" \\\n -u "$(id -u):$(id -g)" \\\n donalffons/opencascade.js:multi-threaded \\\n ./opencascade.full.multi-threaded.yml\n')),(0,i.kt)("p",null,"This will output 3 files (as opposed to 2 when creating a single-threaded build) into the current folder: ",(0,i.kt)("inlineCode",{parentName:"p"},"opencascade.full.multi-threaded.js"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"opencascade.full.multi-threaded.wasm")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"opencascade.full.multi-threaded.worker.js"),". The web worker will be used for spawning new threads. This file must be accessible at run-time and depending on your bundler and folder structure, you might have to define the file path at which it can be accessed when initializing OpenCascade.js using the optional ",(0,i.kt)("inlineCode",{parentName:"p"},"worker")," property."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-js"},'import initOpenCascade from "opencascade.js";\nimport opencascade from "./openascade.full.js";\nimport opencascadeWasm from "./openascade.full.wasm";\n// When building web-apps, you might want to import the worker to give your bundler a chance to hash the file name.\n// import opencascadeWorker from "./openascade.full.worker.js";\n\ninitOpenCascade({\n mainJs: opencascade,\n mainWasm: opencascadeWasm,\n worker: "/path/to/opencascade.full.worker.js", // or pass opencascadeWorker (containing a string with the path to the worker)\n}).then(oc => {\n // ready to use multi-threaded build\n});\n')),(0,i.kt)("p",null,"That's it - multi-threading should now be enabled."))}p.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.