GCD Test
   HOME

TheInfoList



OR:

In
compiler theory In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
, a
greatest common divisor In mathematics, the greatest common divisor (GCD), also known as greatest common factor (GCF), of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers , , the greatest co ...
test (GCD test) is the test used in study of
loop optimization In compiler theory, loop optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capa ...
and
loop dependence analysis In computer science, loop dependence analysis is a process which can be used to find dependencies within iterations of a loop with the goal of determining different relationships between statements. These dependent relationships are tied to the or ...
to test the dependency between loop statements.


Description

A
greatest common divisor In mathematics, the greatest common divisor (GCD), also known as greatest common factor (GCF), of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers , , the greatest co ...
(GCD) test is a test used in computer science
compiler theory In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
to study of
loop optimization In compiler theory, loop optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capa ...
and
loop dependence analysis In computer science, loop dependence analysis is a process which can be used to find dependencies within iterations of a loop with the goal of determining different relationships between statements. These dependent relationships are tied to the or ...
to test the dependency between loop statements.


Use

Whenever a sequential loop like
for loop In computer science, a for-loop or for loop is a control flow Statement (computer science), statement for specifying iteration. Specifically, a for-loop functions by running a section of code repeatedly until a certain condition has been satisfi ...
is made to be parallel so that it can be executed on more than one processor—as in case of
grid computing Grid computing is the use of widely distributed computer resources to reach a common goal. A computing grid can be thought of as a distributed system with non-interactive workloads that involve many files. Grid computing is distinguished fro ...
or
cluster computing A computer cluster is a set of computers that work together so that they can be viewed as a single system. Unlike Grid computing, grid computers, computer clusters have each Node (networking), node set to perform the same task, controlled an ...
—then certain dependencies (e.g., testing the flow (true) dependence of a statement) are checked to know whether the loop can be parallelized. According to this test, by comparing the indices of two
arrays An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
present in two or more
statements Statement or statements may refer to: Common uses *Statement (computer science), the smallest standalone element of an imperative programming language * Statement (logic and semantics), declarative sentence that is either true or false *Statement, ...
, it can be calculated whether it is legal to parallelize the loop or not.


Rationale


Theorem

A linear Diophantine equation a1*x1 + a2*x2 +... + an*xn =c has an integer solution x1, x2,..., xn iff GCD (a1,a2,.., an) divides c. E.g. 2*x1 -2*x2 =1 GCD(2,-2) =2, 2 cannot divide 1. So, there is no integer solution for the equation above.


Dependency analysis

It is difficult to analyze array references in compile time to determine data dependency (whether they point to same address or not). A simple and sufficient test for the absence of a dependence is the greatest common divisor (GCD) test. It is based on the observation that if a loop carried dependency exists between X *i + band X *i + d(where X is the array; a, b, c and d are integers, and i is the loop variable), then GCD (c, a) must divide (d – b). The assumption is that the loop must be
normalized Normalization or normalisation refers to a process that makes something more normal or regular. Science * Normalization process theory, a sociological theory of the implementation of new technologies or innovations * Normalization model, used in ...
– written so that the loop index/variable starts at 1 and gets incremented by 1 in every iteration. For example, in the following loop, a=2, b=3, c=2, d=0 and GCD(a,c)=2 and (d-b) is -3. Since 2 does not divide -3, no dependence is possible. for (i=1; i<=100; i++)


Process

Loop code in general: for (int i=0; i*i+kand a *i+m one usually needs to solve the equation x*i1 +k = y*i2+m (Or x*i1 -y*i2 = m -k) Where 0<=i1, i2 for (int i=0; i<100; i++) { s1 a *i= b s2 c = a *i+1 } The GCD of (2,4) is 2 and dividend is 1. As 2 can not divide 1 properly (leaving remainder zero), there is no dependency between s1 and s2 and various other
loop transformation In compiler theory, loop optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capab ...
methods can be applied.


See also

*
Automatic parallelization Automatic parallelization, also auto parallelization, or autoparallelization refers to converting sequential code into multi-threaded and/or vectorized code in order to use multiple processors simultaneously in a shared-memory multiprocessor ( S ...
*
Banerjee test In compiler theory In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name ...
*
Dependence analysis In compiler theory, dependence analysis produces execution-order constraints between statements/instructions. Broadly speaking, a statement ''S2'' depends on ''S1'' if ''S1'' must be executed before ''S2''. Broadly, there are two classes of depend ...
*
Loop dependence analysis In computer science, loop dependence analysis is a process which can be used to find dependencies within iterations of a loop with the goal of determining different relationships between statements. These dependent relationships are tied to the or ...


References

* ''Advanced Compiler Design and Implementation'' by Steven S Muchnick Compilers