I have a c++ program that is multithreaded. I believe the throughput would increase if I could run it in the other computers connected by a switch. All of then are using the same OS(Ubuntu). Is there a way I can do it without changing the code? If I need to change the code what should I look for?


This is not generally possible without changing the code.

A multi-threaded program will make use of the processors on a single computer. As soon as you want to run the same program across a network of connected machines and have the various instances of the program communicate with each other, the code must do explicit message passing between the multiple copies of the program running on the different machines in the cluster.

There are libraries for doing this. A fairly well known standard is called Message Passing Interface, or MPI for short, and implementations of MPI exists for most free Unices.

If the processing that the program is doing is embarrassingly parallel, meaning multiple copies of the program would be able to process chunks of the input data without communicating with each other, then this may be an easier problem to solve and could possibly be done using GNU parallel.

In the end it comes down to what the program is actually doing.

  • Do I need to open the program in all computers manually? – Rafael Marinho Feb 23 '18 at 15:57
  • 1
    Hang on, isn't this exactly what GNU parallel is for? @RafaelMarinho do you have easy ssh access to all machines? – terdon Feb 23 '18 at 16:03
  • @RafaelMarinho If you're using MPI, the parallelized program is likely started with mpirun. See the manual for that command. – Kusalananda Feb 23 '18 at 16:03
  • @terdon You could possibly use GNU parallel, but only to start multiple copies of the same command. There would be no message passing in-between the processes running on the various machines. It totally depends on what the program is actually doing. – Kusalananda Feb 23 '18 at 16:05
  • 1
    GNU parallel seems interesting. I'll take a look – Rafael Marinho Feb 23 '18 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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