Go to main content
Oracle® Developer Studio 12.6: Performance Library User's Guide

Exit Print View

Updated: July 2017
 
 

C Examples

Transforming user-written code sequences into calls to Oracle Developer Studio Performance Library routines increases application performance. The following code example adapted from LAPACK shows one example.

int    i; 
float a[n], b[n], largest;

largest = a[0]; 
for (i = 0; i < n; i++)
{
if (a[i] > largest)
    largest = a[i];
    if (b[i] > largest
    largest = b[i];
}

No Oracle Developer Studio Performance Library routine exactly replicates the functionality of this code example. However, the code can be accelerated by replacing it with several calls to the Oracle Developer Studio Performance Library routine isamax, as shown in the following code example.

int    i, large_index; 
float a[n], b[n], largest;

large_index = isamax (n, a, l) - 1; 
largest = a[large_index]; 
large_index = isamax (n, b, l) - 1; 
if (b[large_index] > largest) 
     largest = b[large_index];

Compare the differences between calling the native C isamax routine in Oracle Developer Studio Performance Library, shown in the previous code example, with calling the isamax routine in CLAPACK, shown in the following code example.

/* 1. Declare scratch variable to allow 1 to be passed by reference */ 
int one = l;
/* 2. Append underscore to conform to FORTRAN naming system     */
/* 3. Pass all arguments, even scalar input-only, by reference  */ 
/* 4. Subtract one to convert from FORTRAN indexing conventions */
large_index = isamax_ (&n, a, &one) - l; 
largest = a[large_index]; large_index = isamax_ (&n, b, &one) - l; 
if (b[large_index] > largest) 
     largest = b[large_index];