The presentation can be downloaded here.
(рис 4.1)
In most of the cases, the loops are "
That's why
For example, Loop Stream
In a compiler, there are many optimizations provided specially for the loop processing.
for(i=0;i<U;i++) for(i=0;i<U;i++) {
a[i]=b[i]; a[j]=b[i];
j+=c*i; }
i=0; i=0;
do { do {
a[i]=b[i]; a[i]=b[i];
i++;} while(i<U); if(i++>=n) break;
while(1);
for(i=0;i<3*i-n;i++)
a[i]=i;
for(i=0;i<n;i++) {
a[i]=i;
if(i<t) break;}
for(i=0;i<n;i++) {
a[i]=i;
if(i==t) goto loop_skip;}
for(i=0;i<n;i++) {
a[i]=i;
t=g(i);}
Consider the complexity of the used structures.
Avoid loops with an uncertain number of iterations.
Loop invariant code motion is an optimization, which finds and brings outside of the loop expressions, independent of the loop index variables. Such expressions are constant on each iteration.
(рис 4.2)
Loop unswitching is an optimization which takes
(рис 4.3)
Some example estimation for
int main() {
float x[1000],y[1000];
int i,repeat,p;
for(i=0;i<1000;i++) { y[i] = i; x[i] = 1; }
for(repeat=0;repeat<3000000;repeat++) {
p=repeat%10>5;
#ifdef PERF
if(p) {
for(i=0;i<1000;i++) {
x[i]=x[i]+y[i];
y[i]++; }
}
else {
for(i=0;i<1000;i++) {
x[i]=x[i]+y[i]; }
}
#else
for(i=0;i<1000;i++) {
x[i]=x[i]+y[i];
if(p) {
y[i]++; } }
#endif
}
printf("x[123]= %f\n",x[123]);
}
(рис 4.4)
(рис 4.5) Comparison of branch missprediction events for original and modified tests
(рис 4.6) Binding processor events to lines of source code
Loop distribution and loop fusion are inverse optimizations. The compiler must have
If there are a lot of different invariants inside the loop than
(рис 4.7)
Different
(рис 4.8)
Loop peeling (splitting) is an optimization, which tries to
This optimization can be useful for
(рис 4.9)
Loop unrolling is an optimization designed to reduce the
(рис 4.10)
Complete unrolling is applied to small loops and can be very effective. As a general rule in the case of nested loops, inner loops are unrolled.
Loop interchange is a
(рис 4.11)
INTEGER,PARAMETER :: N=100
INTEGER,PARAMETER :: REPEAT=1000
INTEGER :: A(N,N,N), B(N,N,N)
INTEGER :: REP,I,J,K
A=1
B=1
DO REP=1,REPEAT
DO I=1,N
DO J=1,N
DO K=1,N
A(J,K,I) = A(J,K,I)+B(J,K,I)
END DO
END DO
END DO
END DO
PRINT *,A(1,1,1)
END
(рис 4.12) The example of the effectiveness of optimization of loop interchange
(рис 4.13)
(рис 4.14)
Loop blocking is a
(рис 4.15)
INTEGER, PARAMETER :: N=2000
INTEGER :: BF,BN,I,J,K,I1,J1,K1
DOUBLE PRECISION, ALLOCATABLE :: A(:,:),B(:,:),C(:,:)
ALLOCATE(A(N,N),B(N,N),C(N,N))
A=1
B=-1
#ifdef PERF
BF=8
BN=N/BF
DO I1=1,BF
DO J1=1,BF
DO K1=1,BF
DO I=1+BN*(I1-1),MIN(BN*I1,N)
DO J=1+BN*(J1-1),MIN(BN*J1,N)
DO K=1+BN*(K1-1),MIN(BN*K1,N)
C(J,I) = C(J,I) + A(I,K)*B(K,J)
END DO
END DO
END DO
END DO
END DO
END DO
#else
DO I=1,N
DO J=1,N
DO K=1,N
C(J,I) = C(J,I) + A(I,K)*B(K,J)
END DO
END DO
END DO
#endif
PRINT *,C(1:100,700:800)
END
(рис 4.16) Loop blocking
(рис 4.17)
(рис 4.18)
Expressions, which are a
(рис 4.19)
In addition to these optimizations, there are other, sometimes very complex:
The compiler in each case should
The calculations are equivalent if they calculate the same data and output the same values in the same order.
Each task can be calculated with different sequences of instructions (some of which may be more effective than the others) if they are equivalent. Optimization which change sequence of instructions is called
What features of the task instructions could cause wrong results because of instruction
Dependence is a connection between the statement of the program. A couple of statements <S1,S2> are dependent, if S2 should be performed after S1 in order to
S1 PI = 3.14 S2 R = 5 S3 AREA = PI * R ** 2
<S1,S2,S3> Equivalent <S2,S1,S3>
So there are two dependencies. <S1,S3>, <S2,S3>
The concept of
DO I = 1, N S1 A (I) = B (I) + 1 S2 B (I +1) = A (I) - 5 END DO
There is a dependence <S2,S1> <S1,S2> for all iterations except the first.
These dependencies are an example of data dependences.
S1 IF (T.NE.0) THEN S2 A = A / T S3 ENDIF
This is an example of S2 can not be evaluated before S1.
Definition:
There is a S1 and S2 if and only if
S1 to S2.Dependencies are
True dependence (flow dependence) S1 X = ... S2 ... = X Represented as S1?S2 (? - delta)
Antidependence S1 ... = X S2 X = ... S1?-S2
Output dependence S1 X = ... S2 X = ... S1?0S2
Loop dependencies can be more complicated
DO I = 1, N S1 A (I +1) = A (I) + B (I) END DO
S1 depends on itself at the previous iteration
DO I = 1, N S1 A (I +2) = A (I) + B (I) END DO
Normalized loop is usually used for analysis. Such loop starts from 1 to N with step 1. Any loop can be normalized (converted to normalized form).
If we have a
I = {i1, i2, ..., in}
There is a loop dependency between the statements S1 and S2 in the set of
i and j for the set, such that i <j or i = j and a path from S1 to S2 in the loop exists;i S1 and S2 to the approval of iteration j refer to the same memory area;Now our task is to link the equivalence of two
Each optimization which preserves the dependencies in the program (i.e. does not change the order of the dependent claims) produces equivalent calculation.
Accordingly, some transformation is valid in this program if it preserves all the dependencies in the program.
How to determine the dependences in the case of a single array?
Assume that we have a set of
DO i1 = 1, N1
DO i2 = 1, N2
...
DO in = 1, Nn
S1 A (f1 (i1, ..., in), ..., fm (i1, ..., in)) =
A (g1 (i1, ..., in), ..., gm (i1, ..., in))
END DO
...
END DO
END DO
Dependence exists if and only if there are iteration vectors I and J, such that
I <J and the following system of equations:
fi (I) = gi (J)
can be solved
Example:
DO I = 1, N A (I +1) = A (I) + B END DO I +1 = I + x
Dependency evaluation is complicated computational task even for single array usage.
Alias analysis is a technique used to determine if a storage location may be accessed in more than one way. Two pointers are said to be aliased if they point to the same location.
In order to
If there are objects which compiler can not
File sub.c
int sub(int *a, float *b, int n) {
int i;
for(i=0;i<n;i++) {
a[i]=0;
}
for(i=0;i<n;i++){
b[i]=0.0;
}
}
File main.c
#include <stdio.h>
#include <stdlib.h>
extern void sub(int *a,float *b, int n);
int main(){
int *a;
float *b;
a=(int*)malloc(100*sizeof(int));
b=(float*)malloc(100*sizeof(int));
sub(a,b,100);
printf("%d;%f\n",a[0],b[0]);
}
(рис 4.20)
icc main.c 2.c –O3 2.c(3): (col. 1) remark: LOOP WAS VECTORIZED. 2.c(6): (col. 1) remark: LOOP WAS VECTORIZED. icc main.c 2.c –O3 –ansi-alias 2.c(3): (col. 1) remark: FUSED LOOP WAS VECTORIZED.
What's the difference?
-[no-]ansi-alias enable/disable(DEFAULT) use of ANSI aliasing rules in optimizations; user asserts that the program adheres to these rules.
ANSI aliasing rules require that the pointers can refer only to the objects of the same or compatible type. This means in practice that the pointers of
Using –anti-alias option at
There are special attributes in C/C++ language to
int sub (int * a, float * b, int n) => int sub (int * restrict a, float * restrict b, int n)
Fortran language has stronger rules for pointers. Although the language has pointers to arrays, but each array, which can be referenced through the pointer must be TARGET. By default,
Compiler contains special option to show the results of different optimizations /Qopt-report[:n]
stderr0 disable optimization report output1 minimum report output2 medium output (DEFAULT when enabled)3 maximum report outputExample:
LOOP INTERCHANGE in loops at line: 8 9 Loopnest permutation ( 1 2 ) --< ( 2 1 ) Fusion loop partitions: (loop line numbers) Fused Loops: ( 9 14 )
The presentation can be downloaded here.
(рис 4.1)
In most of the cases, the loops are "
That's why
For example, Loop Stream
In a compiler, there are many optimizations provided specially for the loop processing.
for(i=0;i<U;i++) for(i=0;i<U;i++) {
a[i]=b[i]; a[j]=b[i];
j+=c*i; }
i=0; i=0;
do { do {
a[i]=b[i]; a[i]=b[i];
i++;} while(i<U); if(i++>=n) break;
while(1);
for(i=0;i<3*i-n;i++)
a[i]=i;
for(i=0;i<n;i++) {
a[i]=i;
if(i<t) break;}
for(i=0;i<n;i++) {
a[i]=i;
if(i==t) goto loop_skip;}
for(i=0;i<n;i++) {
a[i]=i;
t=g(i);}
Consider the complexity of the used structures.
Avoid loops with an uncertain number of iterations.
Loop invariant code motion is an optimization, which finds and brings outside of the loop expressions, independent of the loop index variables. Such expressions are constant on each iteration.
(рис 4.2)
Loop unswitching is an optimization which takes
(рис 4.3)
Some example estimation for
int main() {
float x[1000],y[1000];
int i,repeat,p;
for(i=0;i<1000;i++) { y[i] = i; x[i] = 1; }
for(repeat=0;repeat<3000000;repeat++) {
p=repeat%10>5;
#ifdef PERF
if(p) {
for(i=0;i<1000;i++) {
x[i]=x[i]+y[i];
y[i]++; }
}
else {
for(i=0;i<1000;i++) {
x[i]=x[i]+y[i]; }
}
#else
for(i=0;i<1000;i++) {
x[i]=x[i]+y[i];
if(p) {
y[i]++; } }
#endif
}
printf("x[123]= %f\n",x[123]);
}
(рис 4.4)
(рис 4.5) Comparison of branch missprediction events for original and modified tests
(рис 4.6) Binding processor events to lines of source code
Loop distribution and loop fusion are inverse optimizations. The compiler must have
If there are a lot of different invariants inside the loop than
(рис 4.7)
Different
(рис 4.8)
Loop peeling (splitting) is an optimization, which tries to
This optimization can be useful for
(рис 4.9)
Loop unrolling is an optimization designed to reduce the
(рис 4.10)
Complete unrolling is applied to small loops and can be very effective. As a general rule in the case of nested loops, inner loops are unrolled.
Loop interchange is a
(рис 4.11)
INTEGER,PARAMETER :: N=100
INTEGER,PARAMETER :: REPEAT=1000
INTEGER :: A(N,N,N), B(N,N,N)
INTEGER :: REP,I,J,K
A=1
B=1
DO REP=1,REPEAT
DO I=1,N
DO J=1,N
DO K=1,N
A(J,K,I) = A(J,K,I)+B(J,K,I)
END DO
END DO
END DO
END DO
PRINT *,A(1,1,1)
END
(рис 4.12) The example of the effectiveness of optimization of loop interchange
(рис 4.13)
(рис 4.14)
Loop blocking is a
(рис 4.15)
INTEGER, PARAMETER :: N=2000
INTEGER :: BF,BN,I,J,K,I1,J1,K1
DOUBLE PRECISION, ALLOCATABLE :: A(:,:),B(:,:),C(:,:)
ALLOCATE(A(N,N),B(N,N),C(N,N))
A=1
B=-1
#ifdef PERF
BF=8
BN=N/BF
DO I1=1,BF
DO J1=1,BF
DO K1=1,BF
DO I=1+BN*(I1-1),MIN(BN*I1,N)
DO J=1+BN*(J1-1),MIN(BN*J1,N)
DO K=1+BN*(K1-1),MIN(BN*K1,N)
C(J,I) = C(J,I) + A(I,K)*B(K,J)
END DO
END DO
END DO
END DO
END DO
END DO
#else
DO I=1,N
DO J=1,N
DO K=1,N
C(J,I) = C(J,I) + A(I,K)*B(K,J)
END DO
END DO
END DO
#endif
PRINT *,C(1:100,700:800)
END
(рис 4.16) Loop blocking
(рис 4.17)
(рис 4.18)
Expressions, which are a
(рис 4.19)
In addition to these optimizations, there are other, sometimes very complex:
The compiler in each case should
The calculations are equivalent if they calculate the same data and output the same values in the same order.
Each task can be calculated with different sequences of instructions (some of which may be more effective than the others) if they are equivalent. Optimization which change sequence of instructions is called
What features of the task instructions could cause wrong results because of instruction
Dependence is a connection between the statement of the program. A couple of statements <S1,S2> are dependent, if S2 should be performed after S1 in order to
S1 PI = 3.14 S2 R = 5 S3 AREA = PI * R ** 2
<S1,S2,S3> Equivalent <S2,S1,S3>
So there are two dependencies. <S1,S3>, <S2,S3>
The concept of
DO I = 1, N S1 A (I) = B (I) + 1 S2 B (I +1) = A (I) - 5 END DO
There is a dependence <S2,S1> <S1,S2> for all iterations except the first.
These dependencies are an example of data dependences.
S1 IF (T.NE.0) THEN S2 A = A / T S3 ENDIF
This is an example of S2 can not be evaluated before S1.
Definition:
There is a S1 and S2 if and only if
S1 to S2.Dependencies are
True dependence (flow dependence) S1 X = ... S2 ... = X Represented as S1?S2 (? - delta)
Antidependence S1 ... = X S2 X = ... S1?-S2
Output dependence S1 X = ... S2 X = ... S1?0S2
Loop dependencies can be more complicated
DO I = 1, N S1 A (I +1) = A (I) + B (I) END DO
S1 depends on itself at the previous iteration
DO I = 1, N S1 A (I +2) = A (I) + B (I) END DO
Normalized loop is usually used for analysis. Such loop starts from 1 to N with step 1. Any loop can be normalized (converted to normalized form).
If we have a
I = {i1, i2, ..., in}
There is a loop dependency between the statements S1 and S2 in the set of
i and j for the set, such that i <j or i = j and a path from S1 to S2 in the loop exists;i S1 and S2 to the approval of iteration j refer to the same memory area;Now our task is to link the equivalence of two
Each optimization which preserves the dependencies in the program (i.e. does not change the order of the dependent claims) produces equivalent calculation.
Accordingly, some transformation is valid in this program if it preserves all the dependencies in the program.
How to determine the dependences in the case of a single array?
Assume that we have a set of
DO i1 = 1, N1
DO i2 = 1, N2
...
DO in = 1, Nn
S1 A (f1 (i1, ..., in), ..., fm (i1, ..., in)) =
A (g1 (i1, ..., in), ..., gm (i1, ..., in))
END DO
...
END DO
END DO
Dependence exists if and only if there are iteration vectors I and J, such that
I <J and the following system of equations:
fi (I) = gi (J)
can be solved
Example:
DO I = 1, N A (I +1) = A (I) + B END DO I +1 = I + x
Dependency evaluation is complicated computational task even for single array usage.
Alias analysis is a technique used to determine if a storage location may be accessed in more than one way. Two pointers are said to be aliased if they point to the same location.
In order to
If there are objects which compiler can not
File sub.c
int sub(int *a, float *b, int n) {
int i;
for(i=0;i<n;i++) {
a[i]=0;
}
for(i=0;i<n;i++){
b[i]=0.0;
}
}
File main.c
#include <stdio.h>
#include <stdlib.h>
extern void sub(int *a,float *b, int n);
int main(){
int *a;
float *b;
a=(int*)malloc(100*sizeof(int));
b=(float*)malloc(100*sizeof(int));
sub(a,b,100);
printf("%d;%f\n",a[0],b[0]);
}
(рис 4.20)
icc main.c 2.c –O3 2.c(3): (col. 1) remark: LOOP WAS VECTORIZED. 2.c(6): (col. 1) remark: LOOP WAS VECTORIZED. icc main.c 2.c –O3 –ansi-alias 2.c(3): (col. 1) remark: FUSED LOOP WAS VECTORIZED.
What's the difference?
-[no-]ansi-alias enable/disable(DEFAULT) use of ANSI aliasing rules in optimizations; user asserts that the program adheres to these rules.
ANSI aliasing rules require that the pointers can refer only to the objects of the same or compatible type. This means in practice that the pointers of
Using –anti-alias option at
There are special attributes in C/C++ language to
int sub (int * a, float * b, int n) => int sub (int * restrict a, float * restrict b, int n)
Fortran language has stronger rules for pointers. Although the language has pointers to arrays, but each array, which can be referenced through the pointer must be TARGET. By default,
Compiler contains special option to show the results of different optimizations /Qopt-report[:n]
stderr0 disable optimization report output1 minimum report output2 medium output (DEFAULT when enabled)3 maximum report outputExample:
LOOP INTERCHANGE in loops at line: 8 9 Loopnest permutation ( 1 2 ) --< ( 2 1 ) Fusion loop partitions: (loop line numbers) Fused Loops: ( 9 14 )
Для получения официальных документов о завершении программы дополнительного профессионального образования (удостоверения о повышении квалификации, дипломов о профессиональной переподготовке и MBA) необходимо предоставить:
Внимание! Вы можете не заказывать доставку бумажной версии официального документы, а скачать его в электронном виде и распечатать самостоятельно. Информация о выданном документе в течение 1 месяца загружается в Федеральную информационную систему «Федеральный реестр сведений о документах об образовании и (или) о квалификации, документах об обучении» - ФИС ФРДО.
Доступ на новый сайт осуществляется с использованием адреса электронной почты, который был указан вами при регистрации на "старом". Мы постарались перенести все ваши данные с прежнего ресурса, однако не исключена вероятность потери части информации.
При возникновении проблемы со входом, воспользуйтесь функцией сброса пароля
Если вы обнаружите несоответствия, пожалуйста, сообщите нам.