only one CPU at the end

General OpenMP discussion

only one CPU at the end

Postby pdupre » Wed Sep 27, 2017 4:30 pm

Hello,

I am running a loop
where I do allocate the memory for each thread:

for (unsigned short int i = 0 ; i < NB_THREAD ; i++) {
ptr_param_ [i] = &(param_ [i].param) ;
fcn_ [i].params = &param_ [i] ;
fcn_ [i].function = (function_gsl) &FM_stand_wave_TT ;
wksp_ [i] = gsl_integration_cquad_workspace_alloc (size_integ_impact) ;
FM_pre_init_delta_int_TT (&param_ [i], funct, funct_delta, size_integ, size_integ_impact, w_D, tt_broad, T1, waist, EMF_sqr, cutoff, rel_err_lim) ;
FM_init_delta_int_TT (ptr_param_ [i], lines, nb_lines, FM_freq, FM_deep, nb_sb) ;
}

#pragma omp parallel for private (i_thread)
for (unsigned int i = 0 ; i < nbpt ; i++) {
i_thread = omp_get_thread_num () ; //MP
FM_delta_int_set_w_TT (ptr_param_ [i_thread], x [i]) ; // MP
status = gsl_integration_cquad (&fcn_ [i_thread], 0, del_gam_max, 0, rel_err_lim, wksp_ [i_thread], &y [i], &abserr, &nevals) ; //MP
}

y is the final array

It there something that I did not declared right?

Thank for your help.

It run fine, except that at one point, the number of CPU used decreases down to 1 before the end.
Actually, it seems that the loop runs in series and not any more in parallel.
I do see 2 reasons:
1) The scheduling of the tasks is pre-established, and because some are slower than the other ones, they delay the final tasks
which are pre-affected to a designed CPU.
2) the number of available CPU decreases during the execution of the loop

I checked that the loop index was changing more or less randomly when only one CPU is still running at the close to the end.


To illustrate, what I said:
Here is the loop index and the thread number
As you can see, at the beginning, the 3 CPU are used,
then only 2 (0 and 2), and finally only one (1).
It seems that the threads are preaffected to a set of indexes:
0: 0 to 33
1: 34 to 67
2: 68 to 100
Since to some loop index requires a log more time, like 45, then the indexes,
46 to 67 are stocked while 2 other CPUs are available.
Can I have a random indexation of the loop index?

68 2
34 1
0 0
1 0
69 2
35 1
2 0
36 1
70 2
3 0
71 2
37 1
4 0
72 2
38 1
5 0
73 2
39 1
6 0
74 2
40 1
7 0
75 2
41 1
8 0
76 2
42 1
9 0
77 2
43 1
10 0
78 2
44 1
11 0
79 2
12 0
80 2
45 1
13 0
81 2
14 0
82 2
15 0
83 2
16 0
84 2
17 0
85 2
18 0
86 2
19 0
87 2
20 0
88 2
21 0
89 2
22 0
90 2
23 0
91 2
24 0
92 2
25 0
93 2
26 0
94 2
27 0
95 2
28 0
96 2
29 0
97 2
30 0
98 2
31 0
99 2
32 0
100 2
33 0
46 1
47 1
48 1
49 1
50 1
51 1
52 1
53 1
54 1
55 1
56 1
57 1
58 1
59 1
60 1
61 1
62 1
63 1
64 1
65 1
66 1
67 1
pdupre
 
Posts: 7
Joined: Wed Jan 11, 2017 7:21 am

Re: only one CPU at the end

Postby MarkB » Thu Sep 28, 2017 8:37 am

As you have observed, the default behaviour is to assign an equal sized block of iterations to each thread. You can change this with schedule clause on the parallel for directive. To start with you could try
Code: Select all
#pragma omp parallel for private (i_thread) schedule(static,1)

or
Code: Select all
#pragma omp parallel for private (i_thread) schedule(dynamic,1)

and see if that helps.
MarkB
 
Posts: 768
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: only one CPU at the end

Postby pdupre » Thu Sep 28, 2017 9:43 am

Thank you very much
Both help. dynamics is better than static
pdupre
 
Posts: 7
Joined: Wed Jan 11, 2017 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 3 guests

cron