// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// This file simply implements an algorithm to compute the inner product of   //
// two vectors. The generated Abacus program is maybe of more value than the  //
// the very simple MiniC program.                                             //
// ************************************************************************** //

// -----------------------------------------------------------------------------
// This procedure is used to initialize the vectors a and b with some values.
// -----------------------------------------------------------------------------

procedure Initialize ([]nat a,b,nat n) {
    nat i;
    for(i=0..n-1) {
            a[i] = i+1;
            b[i] = i+1;
    }
    return;
}


// -----------------------------------------------------------------------------
// The function below computes the innerproduct with a single for loop.
// -----------------------------------------------------------------------------

function InnerProduct([]nat a,b,nat n) : nat {
    nat i,y;
    for(i=0..n-1)
		y = y + a[i]*b[i];
    return y;
}


// -----------------------------------------------------------------------------
// The main thread generates some test examples, and then calls the function.
// -----------------------------------------------------------------------------

thread main {
    [8]nat a,b;
    nat y;
    // first create some test matrices a and b
    Initialize(a,b,8);
    // now call one of the above procedures
    y = InnerProduct(a,b,8);
}