Example 1
In this step-by-step example, we'll create a short program and link to the library you compiled and installed in INSTALL.
More...
In this step-by-step example, we'll create a short program and link to the library you compiled and installed in INSTALL.
- Create a directory for this example.
$ mkdir example1
$ cd example1
- 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>
#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 };
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,
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 );
oski_MatMult( A_tunable, OP_NORMAL, -1, x_view, 1, y_view );
oski_DestroyMat( A_tunable );
oski_DestroyVecView( x_view );
oski_DestroyVecView( y_view );
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'.
- 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.
- 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, 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.