
Analisis¿Que bucle es paralelizable?
Publicado por daniel (5 intervenciones) el 24/10/2015 00:31:47
Buenas a todos. Soy bastante novato en c++, y una de las preguntas del siguiente codigo, es que cual de ellos es paralelizable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
float pp1 ()
{
int i;
z=0.0;
for (i=0;i<N_ITER;i++)
{
z+=a[i]/4;
//z = (z+a[i])*a[i] ; // a longer dependence
//try this one if simple z+=a[i]/4; gives cycles/iteration very near from simple loop
}
return z;
}
float pp2 ()
{
int i;
for (i=0;i<N_ITER;i++)
{
a[i]=3/b[i];
}
return a[N_ITER-1 ];
}
float pp3 ()
{
int i;
for (i=0;i<N_ITER;i++)
{
a[i]=b[i]+c[i]+d[i]+e[i]+f[i]+g[i]+h[i]/4;
}
return a[N_ITER-1 ];
}
float pp4 ()
{
int i;
for (i=0;i<N_ITER;i++)
{
a[i]=b[i]+8;
}
return a[N_ITER-1 ];
}
float pp5a ()
{
int i;
for (i=0;i<N_ITER;i++)
{
if (cond1[i]!=0)
a[i]=b[i]+8;
}
return a[N_ITER-1 ];
}
float pp5b ()
{
int i;
for (i=0;i<N_ITER;i++)
{
if (cond2[i]!=0)
a[i]=b[i]+8;
}
return a[N_ITER-1 ];
}
float pp5c ()
{
int i;
for (i=0;i<N_ITER;i++)
{
if (cond3[i]!=0)
a[i]=b[i]/8;
}
return a[N_ITER-1 ];
}
float pp5d ()
{
int i;
for (i=0;i<N_ITER;i++)
{
int cond_true = (cond3[i]); // condition can be 1 or 0
float result_true = b[i]/8;
int *p_int = (int *)(&result_true );
int mask = (cond_true -1); // the mask can be 0 or 0xFFFFFFFF , that is ,
// a mask to perform AND operations
float result_false = -b[i] ;
int *p_int_false = (int *)(&result_false);
int temp = (*p_int & (~mask)) | (*p_int_false & mask);
// int temp = (*p_int & (~mask)) | (*p_int & mask);
float *p_float = (float *) & temp;
a[i] = * p_float ;
}
/*
// The above code is tricky due to the float/integer mixture.
// If vectors were integer , the integer version would be more understandable:
for (i=0;i<N_ITER;i++)
{
int cond_true = (cond3[i]); // condition can be 1 or 0
int result_true = a_int[i]/8;
int mask = (cond_true -1); // the mask can be 0 or 0xFFFFFFFF , that is , a mask to perform AND operations
a_int[i] = ( result_true & (~mask) ) | ( result_true & mask ) ;
}
*/
return a[N_ITER-1 ];
}
Valora esta pregunta


0