On Wed, Sep 5, 2012 at 5:09 PM, Iyer, Balaji V <balaji.v.i...@intel.com> wrote: > Hello Everyone, > Attached, please find the 1st of ~22 patches that implements Cilk > Plus. This patch will implement Elemental Functions into the C compiler. > Please check it in to the trunk if it looks OK. > > Below, I will give you a small example about what elemental function > is and how it can be useful. Details about elemental function can be found in > the following link > (http://software.intel.com/en-us/articles/elemental-functions-writing-data-parallel-code-in-cc-using-intel-cilk-plus) > > Let's say we have two for loops like this: > > int my_func (int x, int y); > > For (ii = 0; ii < 10000; ii++) > X[ii] = my_func (Y[ii], Z[ii]); > > For (jj = 1; jj < 10000; jj++) { > A[jj] = my_func (B[ii], A[jj-1]) + A[jj-1]; > > > Assume that my_func's body is not visible during this compilation (e.g it is > in some library). > > If a vectorized version for my_func is available, then the first for loop can > be vectorized. However, even if such a version of my_func is available, the > 2nd for loop cannot be vectorized. It would be beneficial if there is a > vectorized version and a scalar version of my_func. This is where an > elemental function comes to play. If we annotate *both* the function > declaration and the function with the following attribute, the compiler will > create a vector and scalar version of the function. > > __attribute__((vector)) my_func (int x, int y); > > __attribute__((vector)) my_func (int x, int y) > { > ... /* Body of the function. */ > }
1. You should consider a different name for the attribute. 2. Considering this example, won't you get the same behaviour if my_func was declared with "pure" attribute? If not, why? -- Gaby