473,382 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to speed up this problem by MPI

1
Hi,

(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
  1.  int main(int argc, char ** argv)   
  2.  {   
  3.  // some operations           
  4.  f(size);           
  5.  // some operations         
  6.  return 0;   
  7.  }   
  8.  
  9.  void f(int size)   
  10.  {   
  11.  // some operations          
  12.  int i;           
  13.  double * array =  new double [size];           
  14.  for (i = 0; i < size; i++) // how can I use MPI to speed up this loop to compute all elements in the array?   
  15.  {   
  16.  array[i] = complicated_computation(); // time comsuming computation   
  17.  }           
  18.  // some operations using all elements in array           
  19.  delete [] array;  
  20.  }
  21.  
As shown in the code, I want to do some operations before and after the part to be paralleled with MPI, but I don't know how to specify where the parallel part begins and ends.

(2) My current code is using OpenMP to speed up the comutation.
Expand|Select|Wrap|Line Numbers
  1.  void f(int size)   
  2.  {   
  3.  // some operations           
  4.  int i;           
  5.  double * array =  new double [size];   
  6.  omp_set_num_threads(_nb_threads);  
  7.  #pragma omp parallel shared(array) private(i)  
  8.  {
  9.  #pragma omp for schedule(dynamic) nowait          
  10.  for (i = 0; i < size; i++) // how can I use MPI to speed up this loop to compute all elements in the array?   
  11.  {   
  12.  array[i] = complicated_computation(); // time comsuming computation   
  13.  }          
  14.  } 
  15.  // some operations using all elements in array           
  16.  }
  17.  
I wonder if I change to use MPI, is it possible to have the code written both for OpenMP and MPI? If it is possible, how to write the code and how to compile and run the code?

(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!
Jan 28 '10 #1
2 1933
RedSon
5,000 Expert 4TB
I don't know anything about MPI but if you were looking to speed up the run time of this program I would think about running array[i] = complicated_computation(); each in their own thread or something like that. If each element of the array is independent of the other elements, then you could run the complicated_computation() in parallel.
Jan 28 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
I recommend that you use a proxy for your array elements. Let the proxy worry about intializing.

You would have a second array of short with all elements initialized to 0. This is a map where short array[10] corresponds to double array[10].

Then instead of access the array of double directly, you call the proxy function with the desired element number, like proxy(10) for the 11th double element.

The proxy function looks at the short array[10] and if it's zero the proxy function calls the complicated calculation, sets short array[10] to 1 and sets double array[10] to the return of the complication calculation and then returns the double.

If the proxy finds short array[10] is not 0 it just returns double array[10].

This way only the double elements that are actually accessed ever get initialized.
Jan 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Yang Li Ke | last post by:
Hi guys, Is it possible to know the internet speed of the visitors with php? Thanx -- Yang
34
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
28
by: Maboroshi | last post by:
Hi I am fairly new to programming but not as such that I am a total beginner From what I understand C and C++ are faster languages than Python. Is this because of Pythons ability to operate on...
8
by: ted | last post by:
How does the speed of the Scons build tool compare with Ant? Right now with out Ant builds take around an hour. Hoping to speed that up. TIA, Ted
16
by: raj | last post by:
Hi, I saw it mentioned that "int" is the fastest data-type for use in C ,that is data storage/retrieval would be the fastest if I use int among the following 4 situations in a 32 bit machine with...
7
by: YAZ | last post by:
Hello, I have a dll which do some number crunching. Performances (execution speed) are very important in my application. I use VC6 to compile the DLL. A friend of mine told me that in Visual...
6
by: Ham | last post by:
Yeah, Gotto work with my VB.Net graphic application for days, do any possible type of code optimization, check for unhandled errors and finally come up with sth that can't process 2D graphics and...
6
by: Jassim Rahma | last post by:
I want to detect the internet speed using C# to show the user on what speed he's connecting to internet?
2
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me...
4
by: nestle | last post by:
I have DSL with a download speed of 32MB/s and an upload speed of 8MB/s(according to my ISP), and I am using a router. My upload speed is always between 8MB/s and 9MB/s(which is above the max upload...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.