< Linux > A simple way to run program with mult-thread
Applicable conditions
If you want to deal with thousands of cases in a same way, you can use this method to accelerate the processing speed.
For example, when you want to load millions of images and process them independently, you can apply this method which may accelerate your processing speed hugely,
Firstly, just write a bash file
1 | start_num=0 |
In this code snippet above, I take running python script as an example. You can modify the ‘all_num’ parameter according to the number of samples you want to deal with.
One important thing to mention is that ‘&’ could make your program running parallely which is the most important keyword in this code snippet.
Modify your code
You should modify your code in order to fit the bash code above. One thing to note is that your main function should take at least two input variables. The below code snippet is a python version.:
1 | def main(): |
The below code snippet is a C/C++ version:
1 | int main(int argc, char** argv) { |
< Linux > A simple way to run program with mult-thread