In this section, you will use the LinearOp
components and driver described earlier as a template to develop a
driver and a component that provides the
NonLinearOp port. The specification of this port
can be found in the SIDL file
, and is repeated
here for convenience.
$STUDENT_SRC/ports/sidl/arrayop.sidl
/** This port can be used to evaluate a linear matrix operation
* of the form
* R = Sum[i=1, N] {Alpha_i log(A_i)} + Sum[j=1, N] {Beta_j A_j .* M_j}}
* Where:
* alpha_i, Beta_j Double scalar
* A_i, M_j Double array of size [m, n]
* log(A_i) Elementwise log (base 10) of matrix A_i
* A_j .* M_j Elementwise multiplication of A_j and M_j
*/
interface NonLinearOp extends gov.cca.Port
{
/** Initialize (or Re-Initialize) internal state in preparation
* for accumulation.
*/
void init();
/** Evaluate Acc = Acc + alpha log(A) where
* log(A) Elementwise log (base 10) of array A
* Acc The internal accumulator maintained by implementors
* of this interafce
* return the result in array R
*/
int logMat (in double alpha,
in rarray<double, 2> A(m, n),
inout rarray<double, 2> R(m, n),
in int m,
in int n);
/** Evaluate Acc = Acc + beta A .* M, where
* .* denotes elementwise multiplications of arrays
* Acc the internal accumulator maintained by implementors
* of this interafce
* return the result in array R
*/
int mulMatMat ( in double beta,
in array<double, 2> A,
in array<double, 2> M,
out array<, 2> R);
/** Get result of nonlinear operation accumulation.
*
int getResult (inout rarray<double, 2> R(m, n),
in int m,
in int n);
}
Adding SIDL Specification
Edit the file
to add specification for the nonlinear matrix operations driver.
$STUDENT_SRC/components/sidl/arraydrivers.sidl
class NLinearDriver implements-all gov.cca.ports.GoPort,
gov.cca.Component,
gov.cca.ComponentRelease
{}
Edit the file
to add specification for the nonlinear matrix operations component.
$STUDENT_SRC/components/sidl/arrayops.sidl
class NLinearOp implements-all arrayop.NonLinearOp,
gov.cca.Component,
gov.cca.ComponentRelease
{}
Adding your new components to the build system
Edit the file
to add the
specification of the two new components to the list of components in the
$STUDENT_SRC/components/MakeIncl.componentsCOMPONENTS macro. The new entries will be of the form
arrayDrivers.NLinearDriver-XX and
arrayOps.NLinearOp-YY, where
XX and YY are the language(s)
you will use to implement the components (lower case “c”, “cxx”, “f77”, “f90”, or
“python”).
Generating code for the new components
Run make in the directory to
generate $STUDENT_SRC/componentsImpl files and
Babel glue code for the newly added components. Note that this
code may be generated in the same language subdirectory that
contains code for the LinearOp driver or
components, if you choose the same language(s) for your new
components.
Editing Implementation Files
Edit the newly generated Impl
files to implement the methods in the driver and the
NonLinearOp component. Build the new
components (by running make in the directory
where the Impl files are
generated).
Running the New NonLinearOp Component
Application
You can run the application using one of the techniques outlined in Chapter 2, Assembling and Running a CCA Application. Note that you will need to assign matching port types in the driver and the component.