(1). I am wondering how I can speed up the time-consuming computation in the loop of my code below using MPI?
Expand|Select|Wrap|Line Numbers
- int main(int argc, char ** argv)
- {
- // some operations
- f(size);
- // some operations
- return 0;
- }
- void f(int size)
- {
- // some operations
- int i;
- double * array = new double [size];
- for (i = 0; i < size; i++) // how can I use MPI to speed up this loop to compute all elements in the array?
- {
- array[i] = complicated_computation(); // time comsuming computation
- }
- // some operations using all elements in array
- delete [] array;
- }
(2) My current code is using OpenMP to speed up the comutation.
Expand|Select|Wrap|Line Numbers
- void f(int size)
- {
- // some operations
- int i;
- double * array = new double [size];
- omp_set_num_threads(_nb_threads);
- #pragma omp parallel shared(array) private(i)
- {
- #pragma omp for schedule(dynamic) nowait
- for (i = 0; i < size; i++) // how can I use MPI to speed up this loop to compute all elements in the array?
- {
- array[i] = complicated_computation(); // time comsuming computation
- }
- }
- // some operations using all elements in array
- }
(3) Our cluster has three versions of MPI: mvapich-1.0.1, mvapich2-1.0.3, openmpi-1.2.6. Are their usage same? Especially in my case. Which one is best for me to use?
Thanks and regards!