Example 1

  1. Create a directory for this example.
      $  mkdir example1
      $  cd example1
    


  2. Enter in or copy the following short program in a file called, say, 'example1.c'. This example creates a lower triangular 3x3 matrix, multiplies it by the vectors shown, and prints the result.
    #include <stdio.h>
    #include <oski/oski.h>
    
    /* Declare a 3x3 lower triangular matrix,
    
             /  1   0   0  \
        A = |  -2   1   0   | ,
             \  .5  0   1  /
    
     in CSR format with 0-based indices and
     an implicitly stored unit diagonal.
    */
    #define DIM 3
    #define NUM_STORED_NZ 2
    
    int Aptr[ DIM+1 ] = { 0, 0, 1, 2 };
    int Aind[ NUM_STORED_NZ ] = { 0, 0 };
    double Aval[ NUM_STORED_NZ ] = { -2, 0.5 };
    
    /* Some dummy vectors, for multiplication later */
    double x[ DIM ] = { .25, .45, .65 };
    double y[ DIM ] = { 1, 1, 1 };
    
    int
    main( int argc, char** argv )
    {
        oski_matrix_t A_tunable;
        oski_vecview_t x_view, y_view;
    
        oski_Init();
    
        A_tunable = oski_CreateMatCSR( Aptr, Aind, Aval, DIM, DIM, SHARE_INPUTMAT,
            /* properties: */
            3, INDEX_ZERO_BASED, MAT_TRI_LOWER, MAT_UNIT_DIAG_IMPLICIT );
    
        x_view = oski_CreateVecView( x, DIM, STRIDE_UNIT );
        y_view = oski_CreateVecView( y, DIM, STRIDE_UNIT );
    
        /* Perform y <-- y - A*x */
        oski_MatMult( A_tunable, OP_NORMAL, -1, x_view, 1, y_view );
    
        /* Clean-up */
        oski_DestroyMat( A_tunable );
        oski_DestroyVecView( x_view );
        oski_DestroyVecView( y_view );
    
        /* Print result */
        printf( "Answer: y = [ %f ; %f ; %f ]\n", y[0], y[1], y[2] );
    
        oski_Close();
        return 0;
    }
    

    This example is similar to Listing 1 in OSKI Design Document, except we include explicit calls to 'oski_Init()' to initialize the BeBOP-OSKI library, and a close to 'oski_Close()' on exit. The call to 'oski_Init()' is required for correct execution, while the call to 'oski_Close()' is optional but good form.

    Also note the inclusion of the OSKI system header file, 'oski/oski.h'.

  3. Compile this file. Here, we assume the Intel icc compiler. You should replace '${OSKIDIR}' with the directory in which your library is installed, as specified in Step 3 of INSTALL.
      $  icc -I${OSKIDIR}/include -O3 -o example1 example1.c \
             -L${OSKIDIR}/lib/oski -Wl,-rpath ${OSKIDIR}/lib/oski \
             -loski_Tid -loski -loski_core_Tid -loski_core -loskilt
    

    For the installation example in INSTALL, we would replace ${OSKIDIR} above with ${HOME}/oski.

    The link flags include three libraries: -loski, -loski_Tid, and -loskilt. The second library is needed because we are using the default scalar value types of 'int' for indices and 'double' for non-zero values (hence, 'Tid' == 'Type int double'). Refer to Mixing Scalar Types for more information on how to use different scalar types.

    Try to correct any compile-time errors, and refer to the Frequently Asked Questions (FAQ) if you are having trouble resolving any linking issues.

  4. Execute the example program, which should display the output shown below:
      $  ./example1
      Answer: y = [ 0.75 ; 1.05 ; 0.225 ]
    

    If your program does not appear to be running correctly, you can enable additional diagnostic information at run-time by setting the OSKI_DEBUG_LEVEL environment variable to some integer greater than or equal to 1, and then re-run your program. For example,
      $  env OSKI_DEBUG_LEVEL=10 ./example1
    
    will rerun your application with extremely verbose debugging output from the BeBOP-OSKI library. If you are reporting something you think is a bug in the library, this output will help us determine the problem.


Generated on Wed Sep 19 16:41:23 2007 for BeBOP Optimized Sparse Kernel Interface Library by  doxygen 1.4.6