2015年9月25日 星期五

An easy way to parallel your c code by using openmp

if your code has low dependencies between each others, you can just use openmp to parallelize your code.
In ubuntu, openmp is installed defaultly, so we don't need to install anything.
In your code, add
#include <omp.h>
in headers.
And add
#pragma omp parallel for
before your for loop.
like

And compile with flag -fopenmp.
gcc ctest.c -fopenmp .....
Then it would run like this.