Simple Performance Optimization Tool (SPOT) 2.0 User's Guide

Example of Compiling and Running an Application Under SPOT

The code shown in Using the spot Command is a program which has three routines, each of which targets a different kind of events:


Example 2–3 Example Test Code

#include <stdio.h>
#include <stdlib.h>

void fp_routine(double *out, double *in1, double *in2,int n)
{
  for (int i=0; i<n; i++) {out[i]=in1[i]+in2[i];}
}

int** cache_miss(int **array, int size, int step)
{
  for (int i=0; i<size-step; i++){array[i]=(int*)&array[i+step];}
  for (int i=size-step; i<size; i++)
     {array[i]=(int*)&array[i-size+step];}
  int ** cp=(int**)array[0];
  for (int i=0; i<size*16; i++) {cp= (int**)*cp;}
  return cp;
}

int** tlb_miss(int **array, int size, int step)
{
  for (int i=0; i<size-step; i++){array[i]=(int*)&array[i+step];}
  for (int i=size-step; i<size; i++)
    {array[i]=(int*)&array[i-size+step];}

  int ** cp=(int**)array[0];
  for (int i=0; i<size*16; i++) {cp= (int**)*cp;}
  return cp;
}

void main()
{
  double * out, *in1, *in2;
  int **array;
  out=(double*) calloc(sizeof(double),10*1024*1024);
  in1=(double*) calloc(sizeof(double),10*1024*1024);
  in2=(double*) calloc(sizeof(double),10*1024*1024);
  for (int rpt=0; rpt <100; rpt++)
    fp_routine(out,in1,in2,10*1024*1024);
  free(out);
  free(in1);
  free(in2);
  array=(int**)calloc(sizeof(int*),10*1024*1024);
  cache_miss(array,10*1024*1024,64/sizeof(int*));
  tlb_miss(array,10*1024*1024,8192/sizeof(int*));
  free (array);
}

The program is compiled, using Sun Studio 12, in the following way:


$ cc -g -O -xbinopt=prepare -o test test.c

The key compiler flags are: