Add OpenMP data

parent 550b68a3
......@@ -139,8 +139,30 @@ you should be changing them is if/when you spawn a new process. All keys and val
are strings.
### print
This is just here temporarily until I add "proper" support for stdout. It's
like `console.log`.
This is just here temporarily until I add "proper" support for `stdout` or a proper `console.log` implementation.
## Parallel Computing
By default, Dukboot will start as many physical threads as you have logical cores.
This makes it very easy to spin up stateless services that take full advantage of
the hardware. Unlike Node's `cluster` module which uses multiple processes, dukboot uses multiple
threads. This way the core duktape engine only has to be loaded once into memory, and
messages can be passed between workers much faster than regular IPC. Running
one thread per core makes it easy to reason about low-level behavior, such as
L1 cache misses and power consumption. This multiprocessing is achieved using the
OpenMP standard which is natively supported by most C compilers, rather than using
a non-portable threading library.
### OpenMP.numThreads
This is the number of physical threads that are active. Right now, that is fixed
and equal to the number of logical cores.
### OpenMP.id
Each thread is assigned an `id`, which runs from 0 to OpenMP.numThreads - 1.
If for some reason you don't want to run multiple instances (e.g.
for a command line utility that reads from stdin and writes to stdout) add a
check at the beginning of your function and only run it if `OpenMP.id == 0`.
## Event Loop
......@@ -214,9 +236,16 @@ on the underlying C library implementation of `nanosleep`.
## Networking I/O
### socket - TBD
### supersocket - TBD
I would like to have some kind of suped up socket like zeromq or nanomsg built into dukboot, so that you can start building advanced network topologies right away without worrying about protocols. However, I can't get either of them to compile yet.
### netLib
> The [netLib Network Communication Library](https://github.com/IanSeyler/netLib) is a free, open-source C library for network communication over TCP/IP. It currently compiles on Windows, Unix (Linux, *BSD, Mac OS X) and BeOS. The netLib Network Communication Library was designed for simplicity, portability, and ease of use.
>
> -Ian Seyler
This will probably be some kind of suped up socket like zeromq, so that you can start building advanced network topologies right away without worrying about protocols.
This is a pretty sweet library. It's a single C file, and does enough to make a basic HTTP server. I'm still working on the bindings, but the netLib library itself is well documented in `deps/netLib/docs/manual.html`. You can see which functions I've written bindings for in `examples/net/webserver.js`.
## Disk I/O
......
function (o) {
o.modules.print(o.OpenMP.id + '/' + o.OpenMP.numThreads)
}
......@@ -58,6 +58,12 @@ int main(int argc, char *argv[] /* char *environ[] */) {
// Construct the prime argument
duk_push_object(ctx);
duk_push_object(ctx);
duk_push_int(ctx, omp_get_thread_num());
duk_put_prop_string(ctx, -2, "id");
duk_push_int(ctx, omp_get_num_threads());
duk_put_prop_string(ctx, -2, "numThreads");
duk_put_prop_string(ctx, -2, "OpenMP");
// Create argv object
app_push_argv(ctx, argc, argv);
duk_put_prop_string(ctx, -2, "argv");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment