Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm working on a project where I need heavy numerical calculations to be real-time visualized with something flexible like D3.js. Are there frameworks out there that would let me painlessly achieve this? Or do I need to use some sort of "glue" code written in, say, Python?

share|improve this question
2  
Does it have to be D3.js? I would have imagined there would be other real-time visualization tools for C and Fortran. –  FrustratedWithFormsDesigner Nov 27 '12 at 18:42
    
if there is nothing else easier, websockets + node.js / write a small module for node.js to do your math, or accept the values in. –  rlemon Nov 27 '12 at 18:49
2  
@rlemon speaks of a viable approach but it's viable not because of node.js so much as the IPC technique he's referring to which you don't need node.js for. Node.js is a viable way of creating a service boundary like this, but there are a great deal of other ways in which you can create a service for your calculations. Here's a webservice framework for C wso2.com/products/web-services-framework/c There are surely others as well. The point is, you want to wrap your calculations in a web service for IPC, then javascript can interact with it easily via jquery or other js frameworks. –  Jimmy Hoffa Nov 27 '12 at 18:59
    
Thanks guys, going to read up on web services and possibly start learning node.js. Maybe I'll even get lucky and find a node.js wrapper for BLAS in which case I might get away with straight up Javascript coding. Basically I need a compiled language for numerically integrating linear equations... lot's of them. And visualizations that I want are quite ambitious as well, hence the preference for D3. –  pav3l Nov 27 '12 at 20:06

2 Answers 2

up vote 6 down vote accepted

What you're asking for is interoperation between C/Fortran and Javascript, interopation can be done in a great many ways, the most common two that come to mind however are:

Foreign Function Interface (FFI) bindings and Inter-Process Communication (IPC).

FFI is where a standard agreed upon protocol is built into the assembly at compile time which allows access to the assemblies facilities by foreign languages. There are a variety of FFI standard interfaces, but I am familiar with none that allows an interpreted language to interface with a compiled language or vice versa; the concept doesn't fit with using interpreters as their scripts are plain text with no assemblies to interface.

That said, the interpreter may have facilities for FFI access. Node.JS comes to mind as a javascript interpreter that likely has facilities for FFI access. Alternatively you could use your C program to host a javascript interpreter like Chrome's V8 engine to have your C execute the javascript directly if this would help you, though I don't suspect it would.

Inter-Process Communication (IPC) is where you run the process in one language, and the other process in the other language, and then use a form of IPC to communicate between the two. Commonly this is done via shared memory space where both processes can put data into that memory space and read from it to send messages back and forth. The same technique is used with files sometimes though this is a high-overhead technique due to the IO costs, it does however afford a durability in the event of either or both processes crashing, or even the machine losing power.

The shared memory technique for IPC often comes in a couple flavors:

  • A parent process calling a child process and using "pipes" to send messages directly to the child process. I believe Node.JS suggests this technique for it to interoperate with other languages
  • Named pipes which are system-wide shared memory spaces registered with the kernel and accessible by an identifier

Other than shared memory or disk, the other largely used IPC technique is network communication. Whenever your browser accesses a website it is communicating with another process, so this is IPC, and in this way web services have become a hugely common way of accomplishing IPC. Direct TCP techniques are still used as well as even UDP for certain tasks, but the point is the network may act as a communication layer between processes just as a memory space or disk space may.

All of this said, my suggestion is you use web services for IPC as your language interoperation technique, because you wish for visualization on a browser.

That's all. I hope you learned something, carry on :)

share|improve this answer
    
Excellent write-up! I am not strictly speaking a computer scientist by training, so this is very helpful. Thanks! –  pav3l Nov 27 '12 at 20:26

Write a CGI, make an HTTP server and a browser do the rest.
If you need more performance later, you can turn it into a FastCGI.

If you (your bosses) are really that desperate into making it look like there isn't a browser doing the heavy hauling, look into including a WebKit widget (cross platform) or embedding an MSIE frame (all-around easier and faster, but only available on Windows, and might raise issue with MSIE versions) into your windowed app.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.