7.4. Assignment: NonLinearOp Component and Driver

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 $STUDENT_SRC/ports/sidl/arrayop.sidl, and is repeated here for convenience.

 /** 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);
   }

  1. Adding SIDL Specification

    1. Edit the file $STUDENT_SRC/components/sidl/arraydrivers.sidl to add specification for the nonlinear matrix operations driver.

      
      class NLinearDriver implements-all gov.cca.ports.GoPort,
                                         gov.cca.Component,
                                         gov.cca.ComponentRelease
      {}
      

    2. Edit the file $STUDENT_SRC/components/sidl/arrayops.sidl to add specification for the nonlinear matrix operations component.

      
      class NLinearOp implements-all arrayop.NonLinearOp,
                                     gov.cca.Component,
                                     gov.cca.ComponentRelease
      {}
      

  2. Adding your new components to the build system

    Edit the file $STUDENT_SRC/components/MakeIncl.components to add the specification of the two new components to the list of components in the COMPONENTS 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”).

  3. Generating code for the new components

    Run make in the directory $STUDENT_SRC/components to generate Impl 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.

  4. 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).

  5. 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.