Interfacing JavaScript and MPI

Abstract

In order to interpret the Javsacript code, Node.js was chosen. Node.js is a modified version of the Javascript engine from the Chrome web browser and it runs like any other C/C++ program in the console. You feed it the name of a Javascript file as an argument and it simply begins with the first line for execution instead of requiring a main function. It also includes a module loader called require.js which is used to pull in more Javascript files for executing on the fly. There is no compile or linking process, so all files must be present and in their expected file paths in order for the it execute. Node does offer a nice feature, however. It has it’s own package manager called “Node Package Manager” or NPM that allows you to download dependencies from their repo. With this, it creates a folder called node_modules that acts like the /bin folder so Node always knows to check it for any files that require.js is requesting. Open MPI (short of “Open Message Passing Interface”) is a library written in both C and Fortran that is designed for moving data between processes of a program via “messages”. These messages are implemented in the form of function calls. The sending process calls a send function and the receiving process calls a receive function. The receiving process must know/expect messages to be sent to it at any time. “Foreign Function Interface” or FFI is a Nodejs module that acts as the “glue” layer between Javascript and native C. It is provided the name of a C shared object file and it dlopen’s it at runtime. There is not a way to statically link C libraries; however, it does allow for full compatibility between the two languages. C functions can be called from Javascript no problem. The returnable data is also passed back into Javascript with ease. FFI even has additional smaller modules that allow for pointers to be used in Javascript so as to allow any C code to work out of the box.

Publication
Technical Report, Oak Ridge National Laboratory
Kalyan Perumalla
Kalyan Perumalla

Kalyan Perumalla is Founder and President of Discrete Computing, Inc. He led advanced research and development at ORNL and holds senior faculty appointments at UTK, GT, and UNL.

Next
Previous

Related