@stdlib/utils-parallel

Execute scripts in parallel.

https://github.com/stdlib-js/utils-parallel

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary

Keywords

concurrency concurrent exec execute javascript multi-core multi-cpu multi-process node node-js nodejs parallel runner stdlib util utilities utility utils worker workers

Keywords from Contributors

iterator name tokenizer accumulator normal assert capitals abbreviate inherited reduced
Last synced: 4 months ago · JSON representation ·

Repository

Execute scripts in parallel.

Basic Info
Statistics
  • Stars: 3
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
concurrency concurrent exec execute javascript multi-core multi-cpu multi-process node node-js nodejs parallel runner stdlib util utilities utility utils worker workers
Created over 4 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Security

README.md

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

Parallel

NPM version Build Status Coverage Status <!-- dependencies -->

Execute scripts in parallel.

## Installation ```bash npm install @stdlib/utils-parallel ``` Alternatively, - To load the package in a website via a `script` tag without installation and bundlers, use the [ES Module][es-module] available on the [`esm`][esm-url] branch (see [README][esm-readme]). - If you are using Deno, visit the [`deno`][deno-url] branch (see [README][deno-readme] for usage intructions). - For use in Observable, or in browser/node environments, use the [Universal Module Definition (UMD)][umd] build available on the [`umd`][umd-url] branch (see [README][umd-readme]). - To use as a general utility for the command line, install the corresponding [CLI package][cli-section] globally. The [branches.md][branches-url] file summarizes the available branches and displays a diagram illustrating their relationships. To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
## Usage ```javascript var parallel = require( '@stdlib/utils-parallel' ); ``` #### parallel( files, \[options,] clbk ) Executes scripts in parallel. ```text var files = [ './a.js', './b.js' ]; function done( error ) { if ( error ) { console.error( 'Exit code: '+error.code ); console.error( 'Signal: '+error.signal ); throw error; } console.log( 'Done!' ); } parallel( files, done ); ``` The function accepts the following `options`: - **cmd**: executable file/command. Default: `'node'`. - **workers**: number of workers. Default: number of CPUs minus `1`. - **concurrency**: number of scripts to execute concurrently. Default: `options.workers`. - **ordered**: `boolean` indicating whether to preserve the order of script output. Default: `false`. - **maxBuffer**: maximum child process `stdio` buffer size. This option is **only** applied when `options.ordered = true`. Default: `200*1024*1024` bytes. - **uid**: child process user identity. - **gid**: child process group identity. By default, the number of workers running scripts is equal to the number of CPUs minus `1` (master process). To adjust the number of workers, set the `workers` option. ```text var files = [ './a.js', './b.js' ]; function done( error ) { if ( error ) { console.error( 'Exit code: '+error.code ); console.error( 'Signal: '+error.signal ); throw error; } console.log( 'Done!' ); } var opts = { 'workers': 8 }; parallel( files, opts, done ); ``` By default, the number of scripts running concurrently is equal to the number of workers. To adjust the concurrency, set the `concurrency` option. ```text var files = [ './a.js', './b.js' ]; function done( error ) { if ( error ) { console.error( 'Exit code: '+error.code ); console.error( 'Signal: '+error.signal ); throw error; } console.log( 'Done!' ); } var opts = { 'concurrency': 6 }; parallel( files, opts, done ); ``` By specifying a concurrency greater than the number of workers, a worker may be executing more than `1` script at any one time. While not likely to be advantageous for synchronous scripts, setting a higher concurrency may be advantageous for scripts performing asynchronous tasks. By default, each script is executed as a [Node.js][node-js] script. ```text $ node ``` To run scripts via an alternative executable or none at all, set the `cmd` option. ```text var files = [ './a.js', './b.js' ]; function done( error ) { if ( error ) { console.error( 'Exit code: '+error.code ); console.error( 'Signal: '+error.signal ); throw error; } console.log( 'Done!' ); } var opts = { 'cmd': '' // e.g., if scripts contain a shebang }; parallel( files, opts, done ); ``` By default, the `stdio` output for each script is interleaved; i.e., the `stdio` output from one script **may** be interleaved with the `stdio` output from one or more other scripts. To preserve the `stdio` output order for each script, set the `ordered` option to `true`. ```text var files = [ './a.js', './b.js' ]; function done( error ) { if ( error ) { console.error( 'Exit code: '+error.code ); console.error( 'Signal: '+error.signal ); throw error; } console.log( 'Done!' ); } var opts = { 'ordered': true }; parallel( files, opts, done ); ```
## Notes - Relative file paths are resolved relative to the current working directory. - Ordered script output does **not** imply that scripts are executed in order. To preserve script order, execute the scripts sequentially via some other means. - Script concurrency cannot exceed the number of scripts. - If the script concurrency is less than the number of workers, the number of workers is reduced to match the specified concurrency.
## Examples ```javascript var fs = require( 'fs' ); var path = require( 'path' ); var writeFileSync = require( '@stdlib/fs-write-file' ).sync; var unlinkSync = require( '@stdlib/fs-unlink' ).sync; var parallel = require( '@stdlib/utils-parallel' ); var nFiles = 100; var files; var opts; var dir; function template( id ) { var file = ''; file += '\'use strict\';'; file += 'var id;'; file += 'var N;'; file += 'var i;'; file += 'id = '+id+';'; file += 'N = 1e5;'; file += 'console.log( \'File: %s. id: %s. N: %d.\', __filename, id, N );'; file += 'for ( i = 0; i < N; i++ ) {'; file += 'console.log( \'id: %s. v: %d.\', id, i );'; file += '}'; return file; } function createDir() { var dir = path.join( __dirname, 'examples', 'tmp' ); fs.mkdirSync( dir ); return dir; } function createScripts( dir, nFiles ) { var content; var fpath; var files; var i; files = new Array( nFiles ); for ( i = 0; i < nFiles; i++ ) { content = template( i.toString() ); fpath = path.join( dir, i+'.js' ); writeFileSync( fpath, content, { 'encoding': 'utf8' }); files[ i ] = fpath; } return files; } function cleanup() { var i; // Delete the temporary files... for ( i = 0; i < files.length; i++ ) { unlinkSync( files[ i ] ); } // Remove temporary directory: fs.rmdirSync( dir ); } function done( error ) { if ( error ) { throw error; } cleanup(); console.log( 'Done!' ); } // Make a temporary directory to store files... dir = createDir(); // Create temporary files... files = createScripts( dir, nFiles ); // Set the runner options: opts = { 'concurrency': 3, 'workers': 3, 'ordered': false }; // Run all temporary scripts: parallel( files, opts, done ); ```

## CLI
## Installation To use as a general utility, install the CLI package globally ```bash npm install -g @stdlib/utils-parallel-cli ```
### Usage ```text Usage: parallel [options] ... Options: -h, --help Print this message. -V, --version Print the package version. --cmd cmd Executable file/command. --workers num Number of workers. --concurrency num Number of scripts to run concurrently. --ordered Preserve order of script output. --uid uid Process user identity. --gid gid Process group identity. --maxbuffer size Max buffer size for stdout and stderr. ```
### Examples ```bash $ parallel --cmd 'node' --workers 4 --concurrency 8 ./1.js ./2.js ./3.js ./4.js ./5.js ./6.js ./7.js ./8.js ./9.js ./10.js ```

* * * ## Notice This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. #### Community [![Chat][chat-image]][chat-url] --- ## License See [LICENSE][stdlib-license]. ## Copyright Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors].

Owner

  • Name: stdlib
  • Login: stdlib-js
  • Kind: organization

Standard library for JavaScript.

Citation (CITATION.cff)

cff-version: 1.2.0
title: stdlib
message: >-
  If you use this software, please cite it using the
  metadata from this file.

type: software

authors:
  - name: The Stdlib Authors
    url: https://github.com/stdlib-js/stdlib/graphs/contributors

repository-code: https://github.com/stdlib-js/stdlib
url: https://stdlib.io

abstract: |
  Standard library for JavaScript and Node.js.

keywords:
  - JavaScript
  - Node.js
  - TypeScript
  - standard library
  - scientific computing
  - numerical computing
  - statistical computing

license: Apache-2.0 AND BSL-1.0

date-released: 2016

GitHub Events

Total
  • Push event: 32
  • Fork event: 1
Last Year
  • Push event: 32
  • Fork event: 1

Committers

Last synced: 6 months ago

All Time
  • Total Commits: 77
  • Total Committers: 2
  • Avg Commits per committer: 38.5
  • Development Distribution Score (DDS): 0.065
Past Year
  • Commits: 10
  • Committers: 1
  • Avg Commits per committer: 10.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
stdlib-bot n****y@s****o 72
Philipp Burckhardt p****t@o****m 5
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • npm 17 last-month
  • Total dependent packages: 2
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 15
  • Total maintainers: 4
npmjs.org: @stdlib/utils-parallel

Execute scripts in parallel.

  • Homepage: https://stdlib.io
  • License: Apache-2.0
  • Latest release: 0.3.2
    published over 1 year ago
  • Versions: 12
  • Dependent Packages: 2
  • Dependent Repositories: 0
  • Downloads: 5 Last month
Rankings
Dependent packages count: 9.5%
Downloads: 12.9%
Average: 16.4%
Stargazers count: 16.8%
Forks count: 17.4%
Dependent repos count: 25.3%
Funding
  • type: opencollective
  • url: https://opencollective.com/stdlib
Last synced: 4 months ago
npmjs.org: @stdlib/utils-parallel-cli

Execute scripts in parallel.

  • Homepage: https://stdlib.io
  • License: Apache-2.0
  • Latest release: 0.3.2
    published over 1 year ago
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 12 Last month
Rankings
Dependent repos count: 33.9%
Average: 41.2%
Dependent packages count: 48.4%
Funding
  • type: opencollective
  • url: https://opencollective.com/stdlib
Last synced: 4 months ago

Dependencies

package.json npm
  • @stdlib/fs-unlink ^0.0.x development
  • @stdlib/fs-write-file ^0.0.x development
  • @stdlib/random-base-minstd ^0.0.x development
  • @stdlib/utils-next-tick ^0.0.x development
  • @stdlib/utils-noop ^0.0.x development
  • istanbul ^0.4.1 development
  • proxyquire ^2.0.0 development
  • tap-spec 5.x.x development
  • tape git+https://github.com/kgryte/tape.git#fix/globby development
  • @stdlib/assert-has-own-property ^0.0.x
  • @stdlib/assert-is-boolean ^0.0.x
  • @stdlib/assert-is-function ^0.0.x
  • @stdlib/assert-is-nonnegative-integer ^0.0.x
  • @stdlib/assert-is-plain-object ^0.0.x
  • @stdlib/assert-is-positive-integer ^0.0.x
  • @stdlib/assert-is-string ^0.0.x
  • @stdlib/assert-is-string-array ^0.0.x
  • @stdlib/cli-ctor ^0.0.x
  • @stdlib/fs-read-file ^0.0.x
  • @stdlib/os-num-cpus ^0.0.x
  • @stdlib/process-cwd ^0.0.x
  • @stdlib/process-env ^0.0.x
  • @stdlib/string-format ^0.0.x
  • @stdlib/utils-copy ^0.0.x
  • @stdlib/utils-keys ^0.0.x
  • debug ^2.6.9
.github/workflows/cancel.yml actions
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/close_pull_requests.yml actions
  • superbrothers/close-pull-request v3 composite
.github/workflows/examples.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/npm_downloads.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • actions/upload-artifact v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/productionize.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • stdlib-js/bundle-action main composite
  • stdlib-js/transform-errors-action main composite
.github/workflows/publish.yml actions
  • JS-DevTools/npm-publish v1 composite
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/test.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/test_bundles.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • denoland/setup-deno v1 composite
.github/workflows/test_coverage.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • codecov/codecov-action v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/test_install.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/publish_cli.yml actions
  • JS-DevTools/npm-publish v2 composite
  • act10ns/slack v2 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • styfle/cancel-workflow-action 0.11.0 composite