# HG changeset patch # User Me@portablequad # Date 1329166409 28800 # Node ID f70142c9dce20deb3373559a0028552d28c12664 # Parent 530cf00460637380254bf492522617b26736f33e deprecated default branch diff -r 530cf0046063 -r f70142c9dce2 DblHist.c --- a/DblHist.c Mon Feb 13 10:33:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright 2010 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#include -#include "Histogram.h" - - -/*This Histogram Abstract Data Type has a number of bins, the starting - * value, and the width of each bin, as a float, all chosen at creation. - * - *One creates a Histogram instance using the makeFloatHistogram function, then - * updates it with the addToFloatHist function, and prints it out with the - * printFloatHist function. - * - *Note, the bin width is an integer, so the end of the range is adjusted - * accordingly. Use the bin-width to calculate the bin boundaries. - */ - - -DblHist * -makeDblHistogram( int32 numBins, float64 startOfRange, float64 binWidth ) - { - DblHist *hist; - int i; - - hist = VMS_int__malloc( sizeof(DblHist) ); - hist->bins = VMS_int__malloc( numBins * sizeof(int) ); - - hist->numBins = numBins; - hist->binWidth = binWidth; - hist->endOfRange = startOfRange + hist->binWidth * numBins; - hist->startOfRange = startOfRange; - - for( i = 0; i < hist->numBins; i++ ) - { - hist->bins[ i ] = 0; - } - - return hist; - } - - -/*All values higher than or equal to a bin's start value and less than the - * start value of the next higher are put into that bin. - */ -void -addToDblHist( float64 value, DblHist *hist ) - { - int binIdx; - - if( value < hist->startOfRange ) - { binIdx = 0; - } - else if( value > hist->endOfRange ) - { binIdx = hist->numBins - 1; - } - else - { //truncate so bin holds: binStartVal =< values < nextBinStartVal - binIdx = (int32)((value - hist->startOfRange) / hist->binWidth); - } - - hist->bins[ binIdx ] += 1; - } - -void -printDblHist( DblHist *hist ) - { - int32 binIdx, i, numBars, maxHeight; - float64 barValue, binStart, binEnd; - - maxHeight = 0; - for( i = 0; i < hist->numBins; i++ ) - { - if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; - } - barValue = maxHeight / 40; //40 spaces across page for tallest bin - - printf( "histogram: \n" ); - if( barValue == 0 ) printf( "error printing histogram\n" ); - for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) - { - binStart = hist->startOfRange + hist->binWidth * binIdx; - binEnd = binStart + hist->binWidth; - printf( "bin range: %.6fl - %.6fl", binStart, binEnd ); - - numBars = hist->bins[ binIdx ] / barValue; - //print one bin, height of bar is num dashes across page - for( i = 0; i < numBars; i++ ) - { - printf("-"); - } - printf("\n"); - } - } - - -void -freeDblHist( DblHist *hist ) - { - VMS_int__free( hist->bins ); - VMS_int__free( hist ); - } diff -r 530cf0046063 -r f70142c9dce2 FloatHist.c --- a/FloatHist.c Mon Feb 13 10:33:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Copyright 2010 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ -#include -#include "Histogram.h" - -/*This Histogram Abstract Data Type has a number of bins, the starting - * value, and the width of each bin, as a float, all chosen at creation. - * - *One creates a Histogram instance using the makeFloatHistogram function, then - * updates it with the addToFloatHist function, and prints it out with the - * printFloatHist function. - * - *Note, the bin width is an integer, so the end of the range is adjusted - * accordingly. Use the bin-width to calculate the bin boundaries. - */ - - -FloatHist * -makeFloatHistogram( int32 numBins, float32 startOfRange, float32 binWidth ) - { - FloatHist *hist; - int i; - - hist = VMS_int__malloc( sizeof(FloatHist) ); - hist->bins = VMS_int__malloc( numBins * sizeof(int) ); - - hist->numBins = numBins; - hist->binWidth = binWidth; - hist->endOfRange = startOfRange + hist->binWidth * numBins; - hist->startOfRange = startOfRange; - - for( i = 0; i < hist->numBins; i++ ) - { - hist->bins[ i ] = 0; - } - - return hist; - } - - -/*All values higher than or equal to a bin's start value and less than the - * start value of the next higher are put into that bin. - */ -void -addToFloatHist( float32 value, FloatHist *hist ) - { - int binIdx; - - if( value < hist->startOfRange ) - { binIdx = 0; - } - else if( value > hist->endOfRange ) - { binIdx = hist->numBins - 1; - } - else - { //truncate so bin holds: binStartVal =< values < nextBinStartVal - binIdx = (int32)((value - hist->startOfRange) / hist->binWidth); - } - - hist->bins[ binIdx ] += 1; - } - -void -printFloatHist( FloatHist *hist ) - { - int32 binIdx, i, numBars, maxHeight; - float32 barValue, binStart, binEnd; - - maxHeight = 0; - for( i = 0; i < hist->numBins; i++ ) - { - if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; - } - barValue = maxHeight / 40; //40 spaces across page for tallest bin - - printf("histogram: \n"); - if( barValue == 0 ) printf("error printing histogram\n"); - for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) - { - binStart = hist->startOfRange + hist->binWidth * binIdx; - binEnd = binStart + hist->binWidth; - printf("bin range: %3f - %3f", binStart, binEnd ); - - numBars = hist->bins[ binIdx ] / barValue; - //print one bin, height of bar is num dashes across page - for( i = 0; i < numBars; i++ ) - { - printf("-"); - } - printf("\n"); - } - } - - -void -freeFloatHist( FloatHist *hist ) - { - VMS_int__free( hist->bins ); - VMS_int__free( hist ); - } diff -r 530cf0046063 -r f70142c9dce2 Histogram.c --- a/Histogram.c Mon Feb 13 10:33:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,358 +0,0 @@ -/* - * Copyright 2010 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ -#include -#include "Histogram.h" - -//External variables for saving of the histogram -//These have to be defined by to plugins in order to enable VMS to print this -//information to the histogram file -extern char __ProgrammName[]; //Defined in main.c -extern char __Scheduler[]; //Defined in VPThread_PluginFns.c -extern char __DataSet[255]; - -/*This Histogram Abstract Data Type has a number of bins plus a range of - * values that the bins span, both chosen at creation. - * - *One creates a Histogram instance using the makeHistogram function, then - * updates it with the addToHist function, and prints it out with the - * printHist function. - * - *Note, the bin width is an integer, so the end of the range is adjusted - * accordingly. Use the bin-width to calculate the bin boundaries. - */ - - -Histogram * -makeHistogram( int32 numBins, int32 startOfRange, int32 endOfRange ) - { - Histogram *hist; - int32 i; - - - hist = VMS_int__malloc( sizeof(Histogram) ); - hist->bins = VMS_int__malloc( numBins * sizeof(int32) ); - - hist->numBins = numBins; - hist->binWidth = (endOfRange - startOfRange) / numBins; - hist->endOfRange = startOfRange + hist->binWidth * numBins; - hist->startOfRange = startOfRange; - - for( i = 0; i < hist->numBins; i++ ) - { - hist->bins[ i ] = 0; - } - - hist->name = NULL; - return hist; - } - -inline void -makeHist_helper( Histogram *hist, int32 numBins, - int32 startOfRange, int32 binWidth, char *nameCopy ) - { - hist->numBins = numBins; - hist->binWidth = binWidth; - hist->endOfRange = startOfRange + hist->binWidth * numBins; - hist->startOfRange = startOfRange; - hist->name = nameCopy; - memset( hist->bins, 0, numBins * sizeof(int32) ); - } - - -Histogram * -makeFixedBinHist( int32 numBins, int32 startOfRange, int32 binWidth, - char *name ) - - { - Histogram *hist; - - hist = VMS_int__malloc( sizeof(Histogram) ); - hist->bins = VMS_int__malloc( numBins * sizeof(int32) ); - - makeHist_helper( hist, numBins, startOfRange, binWidth,VMS_int__strDup(name)); - - return hist; - } - -Histogram * -makeFixedBinHistExt( int32 numBins, int32 startOfRange, int32 binWidth, - char *name ) - - { - Histogram *hist; - - hist = malloc( sizeof(Histogram) ); - hist->bins = malloc( numBins * sizeof(int32) ); - - makeHist_helper( hist, numBins, startOfRange, binWidth, strdup(name)); - - return hist; - } - -void inline -addToHist( int32 value, Histogram *hist ) - { - int32 binIdx; - - if( value < hist->startOfRange ) - { binIdx = 0; - } - else if( value > hist->endOfRange ) - { binIdx = hist->numBins - 1; - } - else - { - binIdx = (value - hist->startOfRange) / hist->binWidth; - } - - hist->bins[ binIdx ] += 1; - } - -void inline -subFromHist( int32 value, Histogram *hist ) - { - int32 binIdx; - - if( value < hist->startOfRange ) - { binIdx = 0; - } - else if( value > hist->endOfRange ) - { binIdx = hist->numBins - 1; - } - else - { - binIdx = (value - hist->startOfRange) / hist->binWidth; - } - - hist->bins[ binIdx ] -= 1; - } - - -/*Inline because use with RDTSC in innermost code so need ultra-fast - */ -void inline -addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ) - { - int32 value; - - value = endIntvl - startIntvl; - if( value < 0 || value > 10000000 ) return; //sanity check - addToHist( value, hist ); - } - -void inline -subIntervalFromHist( int32 startIntvl, int32 endIntvl, Histogram *hist ) - { - int32 value; - - value = endIntvl - startIntvl; - if( value < 0 || value > 10000000 ) return; //sanity check - subFromHist( value, hist ); - } - -void -saveHistToFile(Histogram *hist) -{ - FILE *output; - int32 binIdx, binStart, binEnd, centerValue, width; - int32 maxHeight, i,n; - float32 total, total2, expectedValue1, expectedValue2; - - if(hist == NULL || hist->name == NULL) - return; - - //Calculate the average - //do all except the top bin - maxHeight = 0; total = 0.0; expectedValue1 = 0.0; - for( i = 0; i < hist->numBins -1; i++ ) - { - if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; - total += hist->bins[ i ]; - binStart = hist->startOfRange + hist->binWidth * i; - expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); - } - //copy and calc expected value minus the top bin - expectedValue2 = expectedValue1; - expectedValue2 /= total; - total2 = total; - //now do last iteration, to add the top bin - if(maxHeight < hist->bins[ i ]) - maxHeight = hist->bins[ i ]; - total += hist->bins[ i ]; - binStart = hist->startOfRange + hist->binWidth * i; - expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); - - expectedValue1 /= total; - - - - - //If a histogram directory does not exist, do not save to file. - //TODO change to argument - char filename[255]; - for(n=0;n<255;n++) - { - sprintf(filename, "./histograms/%s.%d.dat", hist->name,n); - output = fopen(filename,"r"); - if(output) - { - fclose(output); - }else{ - break; - } - } - printf("Saving Hist to File: %s ...\n", filename); - output = fopen(filename,"w+"); - if(output == NULL){ - printf("[!]No histogram was saved. To save histograms create folder 'histograms'.\n"); - return; - } - -/* - * Write the header of the measurement file. - */ -//-------------------------- -//Build Environment - fprintf(output, "# >> Build Environment <<\n"); - fprintf(output, "# Hardware Architecture: "); -#ifdef __x86_64 - fprintf(output, "x86_64"); -#endif //__x86_64 -#ifdef __i386 - fprintf(output, "x86"); -#endif //__i386 - fprintf(output, "\n"); - fprintf(output, "# GCC VERSION: %d.%d.%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__); - fprintf(output, "# Build Date: %s %s\n", __DATE__, __TIME__); - fprintf(output, "# Number of Cores: %d\n", NUM_CORES); -//-------------------------- - -//-------------------------- -//VMS Plugins - fprintf(output, "#\n# >> VMS Plugins <<\n"); - fprintf(output, "# Language : "); -#ifdef VPTHREAD - fprintf(output, "VPThread"); -#endif -#ifdef VCILK - fprintf(output, "VCilk"); -#endif -#ifdef SSR - fprintf(output, "SSR"); -#endif - fprintf(output, "\n"); - fprintf(output, "# Scheduler: %s\n", __Scheduler); - -//-------------------------- -//Application - fprintf(output, "#\n# >> Application <<\n"); - fprintf(output, "# Name: %s\n", __ProgrammName); - fprintf(output, "# Data Set:\n%s\n",__DataSet); - -//-------------------------- -//Histogram - fprintf(output, "#\n# Histogram Name: %s\n", hist->name); - fprintf(output, "# Expected Values\n"); - fprintf(output, "#\tnum samples: %d | expected value: %3.2f \n", - (int)total, expectedValue1 ); - fprintf(output, "#\tminus top bin, num samples: %d | expected value: %3.2f \n", - (int)total2, expectedValue2 ); - fprintf(output, "#\n# [Interval] [Center Value] [Count] [relative Count] [Width]\n"); - - for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) - { - binStart = hist->startOfRange + hist->binWidth * binIdx; - binEnd = binStart + hist->binWidth - 1; - centerValue = (binStart+binEnd)/2; - width = (binEnd-binStart)+1; - fprintf(output, "%d-%d\t%d\t%d\t%.4f\t%d\n", binStart, binEnd, centerValue, - hist->bins[ binIdx ], - hist->bins[ binIdx ]/total, width); - } - - fclose(output); - fflush(stdout); -} - -void -printHist( Histogram *hist ) - { - int32 binIdx, i, numBars, maxHeight, barValue, binStart, binEnd; - float32 total, total2, binPercent, expectedValue1, expectedValue2; - - if( hist == NULL ) return; - - //do all except the top bin - maxHeight = 0; total = 0.0; expectedValue1 = 0.0; - for( i = 0; i < hist->numBins -1; i++ ) - { - if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; - total += hist->bins[ i ]; - binStart = hist->startOfRange + hist->binWidth * i; - expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); - } - //copy and calc expected value minus the top bin - expectedValue2 = expectedValue1; - expectedValue2 /= total; - total2 = total; - //now do last iteration, to add the top bin - if( maxHeight < hist->bins[ i ] ) maxHeight = hist->bins[ i ]; - total += hist->bins[ i ]; - binStart = hist->startOfRange + hist->binWidth * i; - expectedValue1 += hist->bins[ i ] * (binStart + hist->binWidth/2.0); - - expectedValue1 /= total; - - printf( "histogram: " ); - if( hist->name != NULL ) printf( "%s\n", hist->name ); - else printf( "\n" ); - printf( " num samples: %d | expected value: %3.2f \n", - (int)total, expectedValue1 ); - printf( "minus top bin, num samples: %d | expected value: %3.2f \n", - (int)total2, expectedValue2 ); - - if(maxHeight < 60){ - barValue = 1; - printf("Single Bar Value: %i\n", barValue); - }else{ - barValue = maxHeight / 60; //60 spaces across page for tallest bin - printf("Single Bar Value: %0.3f\n", (float)maxHeight /60); - } - - if( barValue == 0 ) { printf("error: bar val zero\n"); return; } - for( binIdx = 0; binIdx < hist->numBins; binIdx++ ) - { - binStart = hist->startOfRange + hist->binWidth * binIdx; - binEnd = binStart + hist->binWidth - 1; - binPercent = 100 * hist->bins[ binIdx ] / total; - printf("bin range: %d - %d | %3.2f", binStart, binEnd, binPercent ); - - numBars = hist->bins[ binIdx ] / barValue; - //print one bin, height of bar is num dashes across page - for( i = 0; i < numBars; i++ ) - { - printf("-"); - } - printf("\n"); - } - } - -void -freeHist( Histogram *hist ) - { - VMS_int__free( hist->bins ); - VMS_int__free( hist->name ); - VMS_int__free( hist ); - } -void -freeHistExt( Histogram *hist ) - { - free( hist->bins ); - free( hist->name ); - free( hist ); - } diff -r 530cf0046063 -r f70142c9dce2 Histogram.h --- a/Histogram.h Mon Feb 13 10:33:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* - * Copyright 2010 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#include "../../VMS_Implementations/VMS_impl/VMS.h" -#include "../../VMS_Implementations/VMS_impl/vmalloc.h" -#include "../../VMS_Implementations/VMS_impl/vutilities.h" - -#ifndef _HISTOGRAM_H -#define _HISTOGRAM_H - -typedef struct - { - char *name; - int32 startOfRange; - int32 endOfRange; - int32 numBins; - int32 binWidth; - int32 *bins; - } -Histogram; - -typedef struct - { - float32 startOfRange; - float32 endOfRange; - int32 numBins; - float32 binWidth; - int32 *bins; - } -FloatHist; - -typedef struct - { - float64 startOfRange; - float64 endOfRange; - int32 numBins; - float64 binWidth; - int32 *bins; - } -DblHist; - -Histogram * -makeHistogram( int32 numBins, int32 startOfRange, int32 endOfRange ); - -Histogram * -makeFixedBinHist( int32 numBins, int32 startOfRange, int32 binWidth, - char *name ); - -Histogram * -makeFixedBinHistExt( int32 numBins, int32 startOfRange, int32 binWidth, - char *name ); - -void inline -addToHist( int32 value, Histogram *hist ); - -void inline -addIntervalToHist( uint32 startIntvl, uint32 endIntvl, Histogram *hist ); - -void inline -subIntervalFromHist( int32 startIntvl, int32 endIntvl, Histogram *hist ); - -void -saveHistToFile(Histogram *hist); - -void -printHist( Histogram *hist ); - -FloatHist * -makeFloatHistogram( int numBins, float32 startOfRange, float32 binWidth ); - -void -addToFloatHist( float32 value, FloatHist *hist ); - -void -printFloatHist( FloatHist *hist ); - -void -freeHistExt( Histogram *hist ); - -void -freeHist( Histogram *hist ); - -DblHist * -makeDblHistogram( int numBins, float64 startOfRange, float64 binWidth ); - -void -addToDblHist( float64 value, DblHist *hist ); - -void -printDblHist( DblHist *hist ); - -void -freeDblHist( DblHist *hist ); - -#endif /* _HISTOGRAM_H */ - diff -r 530cf0046063 -r f70142c9dce2 __brch__DEPRECATED_README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/__brch__DEPRECATED_README Mon Feb 13 12:53:29 2012 -0800 @@ -0,0 +1,8 @@ + +There are two versions of the library -- one for pure C use, the other for use inside VMS or within applications written in a VMS-based language (IE, inside a top-level function or a call descendant of a top-level function) -- but only when the VMS is the "MC_shared" version. + +The reason is that VMS that uses shared memory on multicores moves the SlaveVPs around among cores. But, the libC and glibC malloc stores info at the top of the stack (a "clever" hack), for a speed improvement. So, when VMS manipulates the stack pointer, and/or moves Slaves to different cores, the "free" seg faults (that was FUN to figure out ; ) So, this version of VMS implements its own malloc. + +It is anticipated that the MC_split version, where each core has separate data, and messages are sent between cores, can handle malloc and free to use the glibC version. + +For now, update to the version of the library you wish to use.. diff -r 530cf0046063 -r f70142c9dce2 __brch__MC_shared --- a/__brch__MC_shared Mon Feb 13 10:33:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -This branch is for the project structure defined Jan 2012.. the #includes reflect this directory structure. - -More importantly, the MC_shared version of VMS requires a separat malloc implemeted by VMS code.. so this branch has modified the library to use the VMS-specific malloc. -