Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TParallel.For is slower than normal For !!!


This question is not answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 3 - Last Post: May 13, 2017 5:20 AM Last Post By: boualem Ait Mes...
boualem Ait Mes...

Posts: 12
Registered: 4/19/17
TParallel.For is slower than normal For !!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2017 6:04 AM
my TParallel.For is really slow comparing to my normal for loop and they execute the same program !
any ideas or help ?
thanks for anwring me
Jan Dijkstra

Posts: 206
Registered: 11/4/99
Re: TParallel.For is slower than normal For !!!
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2017 7:55 AM   in response to: boualem Ait Mes... in response to: boualem Ait Mes...
boualem Ait Messaoudene wrote:
my TParallel.For is really slow comparing to my normal for loop and they execute the same program !
any ideas or help ?
thanks for anwring me

Without seeing what you do inside your for loop, it's impossible to say for sure why. But some generic comments do apply. When utilising multiple threads to do computations in parallel, you create overhead. Quite a bit of overhead in fact. The threads must be created, stack memory needs to be claimed and initialised, and all these threads need to be loaded onto the CPU in order to execute, which requires task context switching. And, if the body of your for loop happens to be needing shared resources (claiming additional memory from the heaps, for example), then you introduce additional synchronisation delays between these parallel threads, as all must wait on each other to take turns in accessing such a shared resource.

If your for loop does something simple, like a = i + 1 where i is your for loop index, then it will be an order of magnitude slower than running your for loop serially, due to all this overhead.
boualem Ait Mes...

Posts: 12
Registered: 4/19/17
Re: TParallel.For is slower than normal For !!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 6, 2017 9:00 AM   in response to: Jan Dijkstra in response to: Jan Dijkstra
Jan Dijkstra wrote:
boualem Ait Messaoudene wrote:
my TParallel.For is really slow comparing to my normal for loop and they execute the same program !
any ideas or help ?
thanks for anwring me

Without seeing what you do inside your for loop, it's impossible to say for sure why. But some generic comments do apply. When utilising multiple threads to do computations in parallel, you create overhead. Quite a bit of overhead in fact. The threads must be created, stack memory needs to be claimed and initialised, and all these threads need to be loaded onto the CPU in order to execute, which requires task context switching. And, if the body of your for loop happens to be needing shared resources (claiming additional memory from the heaps, for example), then you introduce additional synchronisation delays between these parallel threads, as all must wait on each other to take turns in accessing such a shared resource.

If your for loop does something simple, like a = i + 1 where i is your for loop index, then it will be an order of magnitude slower than running your for loop serially, due to all this overhead.

my parallal loop is like this :

TParallel::For(Sender,0,donnees_initiales.gettab_points().size()-1,affectation_pts_sous_nuage);
 
void  __fastcall TForm66666::affectation_pts_sous_nuage(TObject *Sender,int AIndex)
	   {
		 int indice_I=(int) ((donnees_initiales.gettab_points()[AIndex].getx() - donnees_initiales.getxmin())/pas_x);
		 if(indice_I==nb_x) indice_I--;
 
		 int indice_J=(int) ((donnees_initiales.gettab_points()[AIndex].gety() - donnees_initiales.getymin())/pas_y);
		 if(indice_J==nb_y) indice_J--;
 
		 int indice_K=(int) ((donnees_initiales.gettab_points()[AIndex].getz() - donnees_initiales.getzmin())/pas_z);
		 if(indice_K==nb_z) indice_K--;
 
 
		 sous_nuages[indice_I][indice_J][indice_K].inserer_point(donnees_initiales.gettab_points()[AIndex]);
 
	   }
 


and i have :
class brut_parallele_T{
	private :
	double xmax;
	double xmin;
	double ymax;
	double ymin;
	double zmax;
	double zmin;
 
	vector<point_parallele_T> tab_points;
....
....}
brut_parallele_T   donnees_initiales;
boualem Ait Mes...

Posts: 12
Registered: 4/19/17
Re: TParallel.For is slower than normal For !!!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 13, 2017 5:20 AM   in response to: boualem Ait Mes... in response to: boualem Ait Mes...
boualem Ait Messaoudene wrote:
my TParallel.For is really slow comparing to my normal for loop and they execute the same program !
any ideas or help ?
thanks for anwring me

please can anyone help me !!!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02