From 901955e1653ccccea2239de66253271c6a3aaedb Mon Sep 17 00:00:00 2001 From: jzhou Date: Mon, 18 Aug 2008 22:22:22 +0000 Subject: [PATCH] latest bug fixing and new benchmarks --- .../Analysis/Scheduling/SchedulingUtil.java | 1 + .../Scheduling/FilterBank/FilterBank.java | 166 +++++++ .../Scheduling/JGFMonteCarlo/AppDemo.java | 223 +++++++++ .../JGFMonteCarlo/AppDemoRunner.java | 65 +++ .../JGFMonteCarlo/JGFMonteCarloBench.java | 70 +++ .../JGFMonteCarlo/MonteCarloPath.java | 455 ++++++++++++++++++ .../Scheduling/JGFMonteCarlo/MyRandom.java | 61 +++ .../Scheduling/JGFMonteCarlo/PathId.java | 179 +++++++ .../Scheduling/JGFMonteCarlo/PriceStock.java | 152 ++++++ .../Scheduling/JGFMonteCarlo/RatePath.java | 417 ++++++++++++++++ .../Scheduling/JGFMonteCarlo/ReturnPath.java | 357 ++++++++++++++ .../JGFMonteCarlo/ToInitAllTasks.java | 273 +++++++++++ .../Scheduling/JGFMonteCarlo/ToResult.java | 167 +++++++ .../Scheduling/JGFSeries/JGFSeriesBench.java | 2 +- .../Scheduling/JGFSeries/SeriesRunner.java | 1 - .../Scheduling/JGFSeries/c/JGFSeriesBench.c | 2 +- Robust/src/ClassLibrary/Math.java | 3 +- Robust/src/IR/Flat/BuildCodeMultiCore.java | 106 ++-- Robust/src/Main/Main.java | 11 +- Robust/src/Runtime/math.c | 4 + Robust/src/Runtime/multicoretask.c | 419 ++++++++++++++-- Robust/src/buildscript | 10 + 22 files changed, 3070 insertions(+), 74 deletions(-) create mode 100644 Robust/src/Benchmarks/Scheduling/FilterBank/FilterBank.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemo.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemoRunner.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/JGFMonteCarloBench.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MonteCarloPath.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MyRandom.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PathId.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PriceStock.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/RatePath.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ReturnPath.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToInitAllTasks.java create mode 100644 Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToResult.java diff --git a/Robust/src/Analysis/Scheduling/SchedulingUtil.java b/Robust/src/Analysis/Scheduling/SchedulingUtil.java index 37ff1981..2a629edc 100644 --- a/Robust/src/Analysis/Scheduling/SchedulingUtil.java +++ b/Robust/src/Analysis/Scheduling/SchedulingUtil.java @@ -235,6 +235,7 @@ public class SchedulingUtil { edgedotnodeparams+=", "+newoption; } edgelabel+=":[" + ((FEdge)edge).getExeTime() + "]"; + edgelabel+=":(" + ((FEdge)edge).getProbability() + "%)"; Hashtable hashtable = ((FEdge)edge).getNewObjInfoHashtable(); if(hashtable != null) { Set keys = hashtable.keySet(); diff --git a/Robust/src/Benchmarks/Scheduling/FilterBank/FilterBank.java b/Robust/src/Benchmarks/Scheduling/FilterBank/FilterBank.java new file mode 100644 index 00000000..4392e613 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/FilterBank/FilterBank.java @@ -0,0 +1,166 @@ +task t1(StartupObject s{initialstate}) { + //System.printString("task t1\n"); + + int N_sim=1200; + int N_samp=8; + int N_ch=16; + int N_col=256; + int i,j; + + float r[] = new float[N_sim]; + for (i=0;i=0)); k++) { + this.vH[j]+=this.H[k]*this.r[j-k]; + } + } + + //Down Samplin + for (j=0; j < this.N_sim/this.N_samp; j++) { + this.vDn[j]=this.vH[j*this.N_samp]; + } + + //Up Sampling + for (j=0; j < this.N_sim; j++) { + this.vUp[j]=0; + } + for (j=0; j < this.N_sim/this.N_samp; j++) { + this.vUp[j*this.N_samp]=this.vDn[j]; + } + + //convolving F + for (j=0; j< this.N_sim; j++) { + this.vF[j]=0; + for (k=0; ((k=0)); k++) { + this.vF[j]+=this.F[k]*this.vUp[j-k]; + } + } + } +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemo.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemo.java new file mode 100644 index 00000000..d261aa84 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemo.java @@ -0,0 +1,223 @@ +/** Banboo Version **/ + +/************************************************************************** + * * + * Java Grande Forum Benchmark Suite - Thread Version 1.0 * + * * + * produced by * + * * + * Java Grande Benchmarking Project * + * * + * at * + * * + * Edinburgh Parallel Computing Centre * + * * + * email: epcc-javagrande@epcc.ed.ac.uk * + * * + * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * + * * + * This version copyright (c) The University of Edinburgh, 2001. * + * All rights reserved. * + * * + **************************************************************************/ + + +/** + * Code, a test-harness for invoking and driving the Applications + * Demonstrator classes. + * + *

To do: + *

    + *
  1. Very long delay prior to connecting to the server.
  2. + *
  3. Some text output seem to struggle to get out, without + * the user tapping ENTER on the keyboard!
  4. + *
+ * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:20 $ + */ +public class AppDemo { + flag merge; + flag validate; + + //------------------------------------------------------------------------ + // Class variables. + //------------------------------------------------------------------------ + + public float JGFavgExpectedReturnRateMC; + + public int Serial; + //------------------------------------------------------------------------ + // Instance variables. + //------------------------------------------------------------------------ + /** + * The number of time-steps which the Monte Carlo simulation should + * run for. + */ + public int nTimeStepsMC; + /** + * The number of Monte Carlo simulations to run. + */ + public int nRunsMC; + + public int group; + /** + * The default duration between time-steps, in units of a year. + */ + private float dTime; + /** + * Flag to determine whether initialisation has already taken place. + */ + private boolean initialised; + /** + * Variable to determine which deployment scenario to run. + */ + private int runMode; + + public Vector results; + + PriceStock psMC; + public float pathStartValue; + float avgExpectedReturnRateMC; + float avgVolatilityMC; + + int counter; + + RatePath avgMCrate; + + public ToInitAllTasks initAllTasks; + + public AppDemo(int nTimeStepsMC, int nRunsMC, int group) { + this.JGFavgExpectedReturnRateMC = (float)0.0; + this.Serial = 1; + + this.nTimeStepsMC = nTimeStepsMC; + this.nRunsMC = nRunsMC; + this.group = group; + this.initialised = false; + + this.dTime = (float)1.0/(float)365.0; + this.pathStartValue = (float)100.0; + this.avgExpectedReturnRateMC = (float)0.0; + this.avgVolatilityMC = (float)0.0; + + this.counter = 0; + + this.avgMCrate = new RatePath(this.nTimeStepsMC, "MC", 19990109, 19991231, this.dTime); + + this.initAllTasks = null; + } + /** + * Single point of contact for running this increasingly bloated + * class. Other run modes can later be defined for whether a new rate + * should be loaded in, etc. + * Note that if the hostname is set to the string "none", + * then the demonstrator runs in purely serial mode. + */ + + /** + * Initialisation and Run methods. + */ + public void initSerial() { + // + // Measure the requested path rate. + //System.printI(0xf0); + RatePath rateP = new RatePath(); + //System.printI(0xf1); + //rateP.dbgDumpFields(); + ReturnPath returnP = rateP.getReturnCompounded(); + //System.printI(0xf2); + returnP.estimatePath(); + //System.printI(0xf3); + //returnP.dbgDumpFields(); + float expectedReturnRate = returnP.get_expectedReturnRate(); + float volatility = returnP.get_volatility(); + initAllTasks = new ToInitAllTasks(returnP, nTimeStepsMC, pathStartValue); + this.counter = 0; + //System.printI(0xf4); + return; + } + + //------------------------------------------------------------------------ + /** + * Method for doing something with the Monte Carlo simulations. + * It's probably not mathematically correct, but shall take an average over + * all the simulated rate paths. + * + * @exception DemoException thrown if there is a problem with reading in + * any values. + */ + boolean processResults(Vector returnMCs) { + for(int i = 0; i < returnMCs.size(); i++) { + ToResult returnMC = (ToResult)returnMCs.elementAt(i); + avgMCrate.inc_pathValue(returnMC.get_pathValue()); + avgExpectedReturnRateMC += returnMC.get_expectedReturnRate(); + avgVolatilityMC += returnMC.get_volatility(); + } + + this.counter++; + if(this.counter == this.group) { + avgMCrate.inc_pathValue((float)1.0/((float)nRunsMC)); + avgExpectedReturnRateMC /= nRunsMC; + avgVolatilityMC /= nRunsMC; + JGFavgExpectedReturnRateMC = avgExpectedReturnRateMC; + } + + return (this.counter == this.group); + } + // + //------------------------------------------------------------------------ + // Accessor methods for class AppDemo. + // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999. + //------------------------------------------------------------------------ + /** + * Accessor method for private instance variable nTimeStepsMC. + * + * @return Value of instance variable nTimeStepsMC. + */ + public int get_nTimeStepsMC() { + return(this.nTimeStepsMC); + } + /** + * Set method for private instance variable nTimeStepsMC. + * + * @param nTimeStepsMC the value to set for the instance variable nTimeStepsMC. + */ + public void set_nTimeStepsMC(int nTimeStepsMC) { + this.nTimeStepsMC = nTimeStepsMC; + } + /** + * Accessor method for private instance variable nRunsMC. + * + * @return Value of instance variable nRunsMC. + */ + public int get_nRunsMC() { + return(this.nRunsMC); + } + /** + * Set method for private instance variable nRunsMC. + * + * @param nRunsMC the value to set for the instance variable nRunsMC. + */ + public void set_nRunsMC(int nRunsMC) { + this.nRunsMC = nRunsMC; + } + /** + * Accessor method for private instance variable results. + * + * @return Value of instance variable results. + */ + public Vector get_results() { + return(this.results); + } + /** + * Set method for private instance variable results. + * + * @param results the value to set for the instance variable results. + */ + public void set_results(Vector results) { + this.results = results; + } + //------------------------------------------------------------------------ +} + diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemoRunner.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemoRunner.java new file mode 100644 index 00000000..54cb43a7 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/AppDemoRunner.java @@ -0,0 +1,65 @@ +class AppDemoRunner { + flag run; + flag turnin; + + public String header; + public String name; + public int startDate; + public int endDate; + public float dTime; + public int returnDefinition; + public float expectedReturnRate; + public float volatility; + public int nTimeSteps; + public float pathStartValue; + + int id, nRunsMC, group; + ToInitAllTasks toinitalltasks; + public Vector results; + + public AppDemoRunner(int id,int nRunsMC, int group, ToInitAllTasks initalltask) { + this.id = id; + this.nRunsMC=nRunsMC; + this.group = group; + this.results = new Vector(); + + this.header = initalltask.get_header(); + this.name = initalltask.get_name(); + this.startDate = initalltask.get_startDate(); + this.endDate = initalltask.get_endDate(); + this.dTime = initalltask.get_dTime(); + this.returnDefinition = initalltask.get_returnDefinition(); + this.expectedReturnRate = initalltask.get_expectedReturnRate(); + this.volatility = initalltask.get_volatility(); + this.nTimeSteps = initalltask.get_nTimeSteps(); + this.pathStartValue = initalltask.get_pathStartValue(); + } + + public void run() { + // Now do the computation. + int ilow, iupper, slice; + + slice = (nRunsMC + this.group-1)/this.group; + + ilow = id*slice; + iupper = (id+1)*slice; + if (id==this.group-1) { + iupper=nRunsMC; + } + //System.printI(0xba0); + + for(int iRun=ilow; iRun < iupper; iRun++ ) { + //System.printI(0xba1); + String header="MC run "+String.valueOf(iRun); + PriceStock ps = new PriceStock(); + //System.printI(0xba2); + ps.setInitAllTasks(this); + ps.setTask(header, (long)iRun*11); + //System.printI(0xba3); + ps.run(); + //System.printI(0xba4); + results.addElement(ps.getResult()); + //System.printI(0xba5); + } + } +} \ No newline at end of file diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/JGFMonteCarloBench.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/JGFMonteCarloBench.java new file mode 100644 index 00000000..9d99b955 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/JGFMonteCarloBench.java @@ -0,0 +1,70 @@ +/** Banboo Version **/ + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ + +task t1(StartupObject s{initialstate}) { + //System.printString("task t1\n"); + + int datasize = 1000; //should be times of 2 + int nruns = 64 * 16; + int group = 16; + + AppDemo ad = new AppDemo(datasize, nruns, group){merge}; + + ad.initSerial(); + + for(int i = 0; i < group; i++) { + AppDemoRunner adr = new AppDemoRunner(i, nruns, group, ad.initAllTasks){run}; + } + + taskexit(s{!initialstate}); +} + +task t2(AppDemoRunner adr{run}) { + //System.printString("task t2\n"); + + // Now do the computation. + adr.run(); + + taskexit(adr{!run, turnin}); +} + +task t3(AppDemo ad{merge}, AppDemoRunner adr{turnin}) { + //System.printString("task t3\n"); + boolean isFinish = ad.processResults(adr.results); + + if(isFinish) { + taskexit(ad{!merge, validate}, adr{!turnin}); + } + taskexit(adr{!turnin}); +} + +task t5(AppDemo ad{validate}) { + //System.printString("task t5\n"); + float refval = (float)(-0.0333976656762814); + float dev = Math.abs(ad.JGFavgExpectedReturnRateMC - refval); + if (dev > 1.0e-12 ){ + //System.printString("Validation failed"); + //System.printString(" expectedReturnRate= " + (int)(ad.JGFavgExpectedReturnRateMC*10000) + " " + (int)(dev*10000) + "\n"); + } + taskexit(ad{!validate}); +} + diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MonteCarloPath.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MonteCarloPath.java new file mode 100644 index 00000000..b925236c --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MonteCarloPath.java @@ -0,0 +1,455 @@ +/** Banboo Version **/ + +/************************************************************************** + * * + * Java Grande Forum Benchmark Suite - Thread Version 1.0 * + * * + * produced by * + * * + * Java Grande Benchmarking Project * + * * + * at * + * * + * Edinburgh Parallel Computing Centre * + * * + * email: epcc-javagrande@epcc.ed.ac.uk * + * * + * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * + * * + * This version copyright (c) The University of Edinburgh, 2001. * + * All rights reserved. * + * * + **************************************************************************/ + +/** + * Class representing the paths generated by the Monte Carlo engine. + * + *

To do list: + *

    + *
  1. double[] pathDate is not simulated.
  2. + *
+ * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:20 $ + */ +public class MonteCarloPath extends PathId { + + //------------------------------------------------------------------------ + // Instance variables. + //------------------------------------------------------------------------ + /** + * Random fluctuations generated as a series of random numbers with + * given distribution. + */ + private float[] fluctuations; + /** + * The path values from which the random fluctuations are used to update. + */ + private float[] pathValue; + /** + * Integer flag for determining how the return was calculated, when + * used to calculate the mean drift and volatility parameters. + */ + private int returnDefinition; + /** + * Value for the mean drift, for use in the generation of the random path. + */ + private float expectedReturnRate; + /** + * Value for the volatility, for use in the generation of the random path. + */ + private float volatility; + /** + * Number of time steps for which the simulation should act over. + */ + private int nTimeSteps; + /** + * The starting value for of the security. + */ + private float pathStartValue; + //------------------------------------------------------------------------ + // Constructors. + //------------------------------------------------------------------------ + /** + * Default constructor. Needed by the HPT library to start create + * new instances of this class. The instance variables for this should + * then be initialised with the setInitAllTasks() method. + */ + public MonteCarloPath() { + super(); + this.expectedReturnRate = (float)0.0; + this.volatility = (float)0.0; + this.pathStartValue = (float)0.0; + this.returnDefinition=1; + this.nTimeSteps=0; + } + + /** + * Constructor, using the ReturnPath object to initialise + * the necessary instance variables. + * + * @param returnPath Object used to define the instance variables in + * this object. + * @param nTimeSteps The number of time steps for which to generate the + * random path. + * @exception DemoException Thrown if there is a problem initialising the + * object's instance variables. + */ + public MonteCarloPath(ReturnPath returnPath, int nTimeSteps) { + /** + * These instance variables are members of PathId class. + */ + this.expectedReturnRate = (float)0.0; + this.volatility = (float)0.0; + this.pathStartValue = (float)0.0; + this.returnDefinition=1; + + copyInstanceVariables(returnPath); + this.nTimeSteps = nTimeSteps; + this.pathValue = new float[nTimeSteps]; + this.fluctuations = new float[nTimeSteps]; + } + /** + * Constructor, where the PathId objects is used to ease + * the number of instance variables to pass in. + * + * @param pathId Object used to define the identity of this Path. + * @param returnDefinition How the statistic variables were defined, + * according to the definitions in + * ReturnPath's two class variables + * COMPOUNDED and + * NONCOMPOUNDED. + * @param expectedReturnRate The measured expected return rate for which to generate. + * @param volatility The measured volatility for which to generate. + * @param nTimeSteps The number of time steps for which to generate. + * @exception DemoException Thrown if there is a problem initialising the + * object's instance variables. + */ + public MonteCarloPath(PathId pathId, int returnDefinition, float expectedReturnRate, + float volatility, int nTimeSteps) { + /** + * These instance variables are members of PathId class. + * Invoking with this particular signature should point to the + * definition in the PathId class. + */ + this.pathStartValue = (float)0.0; + + copyInstanceVariables(pathId); + this.returnDefinition = returnDefinition; + this.expectedReturnRate = expectedReturnRate; + this.volatility = volatility; + this.nTimeSteps = nTimeSteps; + this.pathValue = new float[nTimeSteps]; + this.fluctuations = new float[nTimeSteps]; + } + /** + * Constructor, for when the user wishes to define each of the instance + * variables individually. + * + * @param name The name of the security which this Monte Carlo path + * should represent. + * @param startDate The date when the path starts, in 'YYYYMMDD' format. + * @param endDate The date when the path ends, in 'YYYYMMDD' format. + * @param dTime The interval in the data between successive data points + * in the generated path. + * @param returnDefinition How the statistic variables were defined, + * according to the definitions in + * ReturnPath's two class variables + * COMPOUNDED and + * NONCOMPOUNDED. + * @param expectedReturnRate The measured mean drift for which to generate. + * @param volatility The measured volatility for which to generate. + * @param nTimeSteps The number of time steps for which to generate. + */ + public MonteCarloPath(String name, int startDate, int endDate, float dTime, + int returnDefinition, float expectedReturnRate, float volatility, + int nTimeSteps) { + /** + * These instance variables are members of PathId class. + */ + set_name(name); + set_startDate(startDate); + set_endDate(endDate); + set_dTime(dTime); + this.returnDefinition = returnDefinition; + this.expectedReturnRate = expectedReturnRate; + this.volatility = volatility; + this.nTimeSteps = nTimeSteps; + this.pathValue = new float[nTimeSteps]; + this.fluctuations = new float[nTimeSteps]; + } + + //------------------------------------------------------------------------ + // Methods. + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + // Accessor methods for class MonteCarloPath. + // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999. + //------------------------------------------------------------------------ + /** + * Accessor method for private instance variable fluctuations. + * + * @return Value of instance variable fluctuations. + * @exception DemoException thrown if instance variable fluctuations + * is undefined. + */ + public float[] get_fluctuations() { + return(this.fluctuations); + } + /** + * Set method for private instance variable fluctuations. + * + * @param fluctuations the value to set for the instance variable + * fluctuations. + */ + public void set_fluctuations(float[] fluctuations) { + this.fluctuations = fluctuations; + } + /** + * Accessor method for private instance variable pathValue. + * + * @return Value of instance variable pathValue. + * @exception DemoException thrown if instance variable pathValue + * is undefined. + */ + public float[] get_pathValue() { + return(this.pathValue); + } + /** + * Set method for private instance variable pathValue. + * + * @param pathValue the value to set for the instance variable pathValue. + */ + public void set_pathValue(float[] pathValue) { + this.pathValue = pathValue; + } + /** + * Accessor method for private instance variable returnDefinition. + * + * @return Value of instance variable returnDefinition. + * @exception DemoException thrown if instance variable returnDefinition + * is undefined. + */ + public int get_returnDefinition() { + return(this.returnDefinition); + } + /** + * Set method for private instance variable returnDefinition. + * + * @param returnDefinition the value to set for the instance variable + * returnDefinition. + */ + public void set_returnDefinition(int returnDefinition) { + this.returnDefinition = returnDefinition; + } + /** + * Accessor method for private instance variable expectedReturnRate. + * + * @return Value of instance variable expectedReturnRate. + * @exception DemoException thrown if instance variable expectedReturnRate + * is undefined. + */ + public float get_expectedReturnRate() { + return(this.expectedReturnRate); + } + /** + * Set method for private instance variable expectedReturnRate. + * + * @param expectedReturnRate the value to set for the instance variable + * expectedReturnRate. + */ + public void set_expectedReturnRate(float expectedReturnRate) { + this.expectedReturnRate = expectedReturnRate; + } + /** + * Accessor method for private instance variable volatility. + * + * @return Value of instance variable volatility. + * @exception DemoException thrown if instance variable volatility + * is undefined. + */ + public float get_volatility() { + return(this.volatility); + } + /** + * Set method for private instance variable volatility. + * + * @param volatility the value to set for the instance variable + * volatility. + */ + public void set_volatility(float volatility) { + this.volatility = volatility; + } + /** + * Accessor method for private instance variable nTimeSteps. + * + * @return Value of instance variable nTimeSteps. + * @exception DemoException thrown if instance variable nTimeSteps + * is undefined. + */ + public int get_nTimeSteps() { + return(this.nTimeSteps); + } + /** + * Set method for private instance variable nTimeSteps. + * + * @param nTimeSteps the value to set for the instance variable + * nTimeSteps. + */ + public void set_nTimeSteps(int nTimeSteps) { + this.nTimeSteps = nTimeSteps; + } + /** + * Accessor method for private instance variable pathStartValue. + * + * @return Value of instance variable pathStartValue. + * @exception DemoException thrown if instance variable pathStartValue + * is undefined. + */ + public float get_pathStartValue() { + return(this.pathStartValue); + } + /** + * Set method for private instance variable pathStartValue. + * + * @param pathStartValue the value to set for the instance variable + * pathStartValue. + */ + public void set_pathStartValue(float pathStartValue) { + this.pathStartValue = pathStartValue; + } + //------------------------------------------------------------------------ + /** + * Method for copying the suitable instance variable from a + * ReturnPath object. + * + * @param obj Object used to define the instance variables which + * should be carried over to this object. + * @exception DemoException thrown if there is a problem accessing the + * instance variables from the target objetct. + */ + private void copyInstanceVariables(ReturnPath obj) { + // + // Instance variables defined in the PathId object. + set_name(obj.get_name()); + set_startDate(obj.get_startDate()); + set_endDate(obj.get_endDate()); + set_dTime(obj.get_dTime()); + // + // Instance variables defined in this object. + this.returnDefinition = obj.get_returnDefinition(); + this.expectedReturnRate = obj.get_expectedReturnRate(); + this.volatility = obj.get_volatility(); + } + + /** + * Method for returning a RatePath object from the Monte Carlo data + * generated. + * + * @return a RatePath object representing the generated + * data. + * @exception DemoException thrown if there was a problem creating + * the RatePath object. + */ + public RatePath getRatePath() { + return(new RatePath(this)); + } + /** + * Method for calculating the sequence of fluctuations, based around + * a Gaussian distribution of given mean and variance, as defined + * in this class' instance variables. Mapping from Gaussian + * distribution of (0,1) to (mean-drift,volatility) is done via + * Ito's lemma on the log of the stock price. + * + * @param randomSeed The psuedo-random number seed value, to start off a + * given sequence of Gaussian fluctuations. + * @exception DemoException thrown if there are any problems with + * the computation. + */ + public boolean computeFluctuationsGaussian(long randomSeed) { + if( nTimeSteps > fluctuations.length ) { + return false; + } + //System.printI(0xc0); + // + // First, make use of the passed in seed value. + MyRandom rnd; + float v1,v2, r; + v1 = (float)0.0; + v2 = (float)0.0; + if( randomSeed == -1 ) { + rnd = new MyRandom(0, v1, v2); + } else { + rnd = new MyRandom((int)randomSeed, v1, v2); + } + //System.printI(0xc1); + // + // Determine the mean and standard-deviation, from the mean-drift and volatility. + float mean = (expectedReturnRate-(float)0.5*volatility*volatility)*get_dTime(); + //System.printI(0xc2); + float sd = volatility*Math.sqrtf(get_dTime()); + //System.printI(0xc3); + float gauss, meanGauss=(float)0.0, variance=(float)0.0; + //System.printI(0xc4); + for( int i=0; i < nTimeSteps; i += 2 ) { + //System.printI(0xc5); + r = rnd.seed(); + gauss = r*rnd.v1; + //System.printI(0xc6); + meanGauss+= gauss; + variance+= (gauss*gauss); + // + // Now map this onto a general Gaussian of given mean and variance. + fluctuations[i] = mean + sd*gauss; + // dbgPrintln("gauss="+gauss+" fluctuations="+fluctuations[i]); + + gauss = r*rnd.v2; + meanGauss+= gauss; + variance+= (gauss*gauss); + // + // Now map this onto a general Gaussian of given mean and variance. + fluctuations[i+1] = mean + sd*gauss; + } + //System.printI(0xc7); + meanGauss/=(float)nTimeSteps; + //System.printI(0xc8); + variance /=(float)nTimeSteps; + //System.printI(0xc9); + // dbgPrintln("meanGauss="+meanGauss+" variance="+variance); + } + /** + * Method for calculating the sequence of fluctuations, based around + * a Gaussian distribution of given mean and variance, as defined + * in this class' instance variables. Mapping from Gaussian + * distribution of (0,1) to (mean-drift,volatility) is done via + * Ito's lemma on the log of the stock price. This overloaded method + * is for when the random seed should be decided by the system. + * + * @exception DemoException thrown if there are any problems with + * the computation. + */ + public void computeFluctuationsGaussian() { + computeFluctuationsGaussian((long)-1); + } + /** + * Method for calculating the corresponding rate path, given the + * fluctuations and starting rate value. + * + * @param startValue the starting value of the rate path, to be + * updated with the precomputed fluctuations. + * @exception DemoException thrown if there are any problems with + * the computation. + */ + public void computePathValue(float startValue) { + pathValue[0] = startValue; + //System.printI(0xca0); + if( returnDefinition == 1 || + returnDefinition == 2) { + //System.printI(0xca1); + for(int i=1; i < nTimeSteps; i++ ) { + //System.printI(0xca2); + pathValue[i] = pathValue[i-1] * Math.expf(fluctuations[i]); + } + } + } +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MyRandom.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MyRandom.java new file mode 100644 index 00000000..3fdb7e47 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/MyRandom.java @@ -0,0 +1,61 @@ +public class MyRandom { + + public int iseed; + public float v1,v2; + + public MyRandom(int iseed, float v1, float v2) { + this.iseed = iseed; + this.v1 = v1; + this.v2 = v2; + } + + public float update() { + + float rand; + float scale= (float)4.656612875e-10; + + int is1,is2,iss2; + int imult= 16807; + int imod = 2147483647; + + if (iseed<=0) { + iseed = 1; + } + + is2 = iseed % 32768; + is1 = (iseed-is2)/32768; + iss2 = is2 * imult; + is2 = iss2 % 32768; + is1 = (is1 * imult+(iss2-is2) / 32768) % (65536); + + iseed = (is1 * 32768 + is2) % imod; + + rand = scale * iseed; + + return rand; + + } + + public float seed() { + + float s,u1,u2,r; + s = (float)1.0; + //do { + //System.printI(0xb1); + u1 = update(); + u2 = update(); + + //System.printI(0xb2); + v1 = (float)2.0 * u1 - (float)1.0; + v2 = (float)2.0 * u2 - (float)1.0; + s = v1*v1 + v2*v2; + //System.printI(0xb3); + //} while (s >= (float)1.0); + s = s - (int)s; + //System.printI(0xb4); + r = Math.sqrtf((float)(-2.0*Math.logf(s))/(float)s); + //System.printI(0xb5); + return r; + + } +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PathId.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PathId.java new file mode 100644 index 00000000..131d40aa --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PathId.java @@ -0,0 +1,179 @@ +/** Banboo Version **/ + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ + +/** + * Base class for all the security objects, namely in terms of + * providing a consistent means of identifying each such object. + * Also provides some methods for writing out debug messages. + * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $ + */ +public class PathId { + + //------------------------------------------------------------------------ + // Instance variables. + //------------------------------------------------------------------------ + /** + * Simple string name. + */ + private String name; + + /** + * The start date for the path, in YYYYMMDD format. + */ + private int startDate; + /** + * The end date for the path, in YYYYMMDD format. + */ + private int endDate; + /** + * The change in time between two successive data values. + */ + private float dTime; + + //------------------------------------------------------------------------ + // Constructors. + //------------------------------------------------------------------------ + /** + * Default constructor. + */ + public PathId() { + this.startDate=0; + this.endDate=0; + this.dTime=(float)0.0; + } + + /** + * Another constructor. + * + * @param name The name for the security to record. + */ + public PathId(String name) { + this.name = name; + this.startDate=0; + this.endDate=0; + this.dTime=(float)0.0; + } + + //------------------------------------------------------------------------ + // Methods. + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + // Accessor methods for class PathId. + // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999. + //------------------------------------------------------------------------ + /** + * Accessor method for private instance variable name. + * + * @return Value of instance variable name. + * @exception DemoException thrown if instance variable name is undefined. + */ + public String get_name() { + return(this.name); + } + /** + * Set method for private instance variable name. + * + * @param name the value to set for the instance variable name. + */ + public void set_name(String name) { + this.name = name; + } + /** + * Accessor method for private instance variable startDate. + * + * @return Value of instance variable startDate. + * @exception DemoException thrown if instance variable startDate is undefined. + */ + public int get_startDate() { + return(this.startDate); + } + /** + * Set method for private instance variable startDate. + * + * @param startDate the value to set for the instance variable startDate. + */ + public void set_startDate(int startDate) { + this.startDate = startDate; + } + /** + * Accessor method for private instance variable endDate. + * + * @return Value of instance variable endDate. + * @exception DemoException thrown if instance variable endDate is undefined. + */ + public int get_endDate() { + return(this.endDate); + } + /** + * Set method for private instance variable endDate. + * + * @param endDate the value to set for the instance variable endDate. + */ + public void set_endDate(int endDate) { + this.endDate = endDate; + } + /** + * Accessor method for private instance variable dTime. + * + * @return Value of instance variable dTime. + * @exception DemoException thrown if instance variable dTime is undefined. + */ + public float get_dTime() { + return(this.dTime); + } + /** + * Set method for private instance variable dTime. + * + * @param dTime the value to set for the instance variable dTime. + */ + public void set_dTime(float dTime) { + this.dTime = dTime; + } + //------------------------------------------------------------------------ + /** + * Clone the instance variables in this class, from another instance + * of this class. + * + * @param obj the PathId object from which to copy. + * @exception DemoException thrown if the values to be copied contain + * any undefined objects. + */ + public void copyInstanceVariables(PathId obj) { + this.name = obj.get_name(); + this.startDate = obj.get_startDate(); + this.endDate = obj.get_endDate(); + this.dTime = obj.get_dTime(); + } + /** + * Dumps the contents of the fields, to standard-out, for debugging. + */ + public void dbgDumpFields() { +// dbgPrintln("name=" +this.name); +// dbgPrintln("startDate="+this.startDate); +// dbgPrintln("endDate=" +this.endDate); +// dbgPrintln("dTime=" +this.dTime); + } +} + diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PriceStock.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PriceStock.java new file mode 100644 index 00000000..997be057 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/PriceStock.java @@ -0,0 +1,152 @@ +/** Banboo Version **/ + +/************************************************************************** + * * + * Java Grande Forum Benchmark Suite - Thread Version 1.0 * + * * + * produced by * + * * + * Java Grande Benchmarking Project * + * * + * at * + * * + * Edinburgh Parallel Computing Centre * + * * + * email: epcc-javagrande@epcc.ed.ac.uk * + * * + * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * + * * + * This version copyright (c) The University of Edinburgh, 2001. * + * All rights reserved. * + * * + **************************************************************************/ + +/** + * Class to do the work in the Application demonstrator, in particular + * the pricing of the stock path generated by Monte Carlo. The run + * method will generate a single sequence with the required statistics, + * estimate its volatility, expected return rate and final stock price + * value. + * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $ + */ +public class PriceStock{ + + //------------------------------------------------------------------------ + // Instance variables. + //------------------------------------------------------------------------ + /** + * The Monte Carlo path to be generated. + */ + private MonteCarloPath mcPath; + /** + * String identifier for a given task. + */ + private String taskHeader; + /** + * Random seed from which the Monte Carlo sequence is started. + */ + private long randomSeed; + /** + * Initial stock price value. + */ + private float pathStartValue; + /** + * Object which represents the results from a given computation task. + */ + private ToResult result; + private float expectedReturnRate; + private float volatility; + private float volatility2; + private float finalStockPrice; + private float[] pathValue; + + //------------------------------------------------------------------------ + // Constructors. + //------------------------------------------------------------------------ + /** + * Default constructor. + */ + public PriceStock() { + this.taskHeader = ""; + this.randomSeed=-1; + this.pathStartValue=(float)0.0; + this.expectedReturnRate=(float)0.0; + this.volatility=(float)0.0; + this.volatility2=(float)0.0; + this.finalStockPrice=(float)0.0; + + mcPath = new MonteCarloPath(); + } + //------------------------------------------------------------------------ + // Methods. + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + // Methods which implement the Slaveable interface. + //------------------------------------------------------------------------ + /** + * Method which is passed in the initialisation data common to all tasks, + * and then unpacks them for use by this object. + * + * @param obj Object representing data which are common to all tasks. + */ + public void setInitAllTasks(AppDemoRunner obj) { + mcPath.set_name(obj.name); + mcPath.set_startDate(obj.startDate); + mcPath.set_endDate(obj.endDate); + mcPath.set_dTime(obj.dTime); + mcPath.set_returnDefinition(obj.returnDefinition); + mcPath.set_expectedReturnRate(obj.expectedReturnRate); + mcPath.set_volatility(obj.volatility); + int nTimeSteps = obj.nTimeSteps; + mcPath.set_nTimeSteps(nTimeSteps); + this.pathStartValue = obj.pathStartValue; + mcPath.set_pathStartValue(pathStartValue); + mcPath.set_pathValue(new float[nTimeSteps]); + mcPath.set_fluctuations(new float[nTimeSteps]); + } + /** + * Method which is passed in the data representing each task, which then + * unpacks it for use by this object. + * + * @param obj Object representing the data which defines a given task. + */ + public void setTask(String header, long randomSeed) { + this.taskHeader = header; + this.randomSeed = randomSeed; + } + /** + * The business end. Invokes the necessary computation routine, for a + * a given task. + */ + public void run() { + mcPath.computeFluctuationsGaussian(randomSeed); + //System.printI(0xa0); + mcPath.computePathValue(pathStartValue); + //System.printI(0xa1); + RatePath rateP = new RatePath(mcPath); + //System.printI(0xa2); + ReturnPath returnP = rateP.getReturnCompounded(); + //System.printI(0xa3); + returnP.estimatePath(); + //System.printI(0xa4); + expectedReturnRate = returnP.get_expectedReturnRate(); + volatility = returnP.get_volatility(); + volatility2 = returnP.get_volatility2(); + finalStockPrice = rateP.getEndPathValue(); + pathValue = mcPath.get_pathValue(); + //System.printI(0xa5); + } + /* + * Method which returns the results of a computation back to the caller. + * + * @return An object representing the computed results. + */ + public ToResult getResult() { + String resultHeader = "Result of task with Header="+taskHeader+": randomSeed="+randomSeed+": pathStartValue="+(int)pathStartValue; + ToResult res = new ToResult(resultHeader,expectedReturnRate,volatility, + volatility2,finalStockPrice,pathValue); + return res; + } +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/RatePath.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/RatePath.java new file mode 100644 index 00000000..2c99130b --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/RatePath.java @@ -0,0 +1,417 @@ +/** Banboo Version **/ + +/************************************************************************** + * * + * Java Grande Forum Benchmark Suite - Thread Version 1.0 * + * * + * produced by * + * * + * Java Grande Benchmarking Project * + * * + * at * + * * + * Edinburgh Parallel Computing Centre * + * * + * email: epcc-javagrande@epcc.ed.ac.uk * + * * + * Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * + * * + * This version copyright (c) The University of Edinburgh, 2001. * + * All rights reserved. * + * * + **************************************************************************/ + +/** + * Class for recording the values in the time-dependent path of a security. + * + *

To Do list: + *

    + *
  1. None! + *
+ * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $ + */ +public class RatePath extends PathId { + + //------------------------------------------------------------------------ + // Class variables. + //------------------------------------------------------------------------ + /** + * Class variable to represent the minimal date, whence the stock prices + * appear. Used to trap any potential problems with the data. + */ + public int MINIMUMDATE; + /** + * Class variable for defining what is meant by a small number, small enough + * to cause an arithmetic overflow when dividing. According to the + * Java Nutshell book, the actual range is +/-4.9406564841246544E-324 + */ + public float EPSILON; + + //------------------------------------------------------------------------ + // Instance variables. + //------------------------------------------------------------------------ + /** + * An instance variable, for storing the rate's path values itself. + */ + private float[] pathValue; + /** + * An instance variable, for storing the corresponding date of the datum, + * in 'YYYYMMDD' format. + */ + private int[] pathDate; + /** + * The number of accepted values in the rate path. + */ + private int nAcceptedPathValue; + + //------------------------------------------------------------------------ + // Constructors. + //------------------------------------------------------------------------ + /** + * Constructor, where the user specifies the directory and filename in + * from which the data should be read. + * + * @param String dirName + * @param String filename + * @exception DemoException thrown if there is a problem reading in + * the data file. + */ + public RatePath() { + this.MINIMUMDATE = 19000101; + this.EPSILON= (float)10.0 * (float)(4.9E-324); + this.nAcceptedPathValue = 0; + //System.printI(0xaa0); + readRatesFile(); + //System.printI(0xaa1); + } + /** + * Constructor, for when the user specifies simply an array of values + * for the path. User must also include information for specifying + * the other characteristics of the path. + * + * @param pathValue the array containing the values for the path. + * @param name the name to attach to the path. + * @param startDate date from which the path is supposed to start, in + * 'YYYYMMDD' format. + * @param startDate date from which the path is supposed to end, in + * 'YYYYMMDD' format. + * @param dTime the time interval between successive path values, in + * fractions of a year. + */ + public RatePath(float[] pathValue, String name, int startDate, int endDate, float dTime) { + this.MINIMUMDATE = 19000101; + this.EPSILON= (float)10.0 * (float)(4.9E-324); + + set_name(name); + set_startDate(startDate); + set_endDate(endDate); + set_dTime(dTime); + this.pathValue = pathValue; + this.nAcceptedPathValue = pathValue.length; + } + /** + * Constructor, for use by the Monte Carlo generator, when it wishes + * to represent its findings as a RatePath object. + * + * @param mc the Monte Carlo generator object, whose data are to + * be copied over. + * @exception DemoException thrown if there is an attempt to access + * an undefined variable. + */ + public RatePath(MonteCarloPath mc) { + this.MINIMUMDATE = 19000101; + this.EPSILON= (float)10.0 * (float)(4.9E-324); + + // + // Fields pertaining to the parent PathId object: + set_name(mc.get_name()); + set_startDate(mc.get_startDate()); + set_endDate(mc.get_endDate()); + set_dTime(mc.get_dTime()); + // + // Fields pertaining to RatePath object itself. + pathValue=mc.get_pathValue(); + nAcceptedPathValue=mc.get_nTimeSteps(); + // + // Note that currently the pathDate is neither declared, defined, + // nor used in the MonteCarloPath object. + pathDate=new int[nAcceptedPathValue]; + } + /** + * Constructor, for when there is no actual pathValue with which to + * initialise. + * + * @param pathValueLegth the length of the array containing the values + * for the path. + * @param name the name to attach to the path. + * @param startDate date from which the path is supposed to start, in + * 'YYYYMMDD' format. + * @param startDate date from which the path is supposed to end, in + * 'YYYYMMDD' format. + * @param dTime the time interval between successive path values, in + * fractions of a year. + */ + public RatePath(int pathValueLength, String name, int startDate, int endDate, float dTime) { + this.MINIMUMDATE = 19000101; + this.EPSILON= (float)10.0 * (float)(4.9E-324); + + set_name(name); + set_startDate(startDate); + set_endDate(endDate); + set_dTime(dTime); + this.pathValue = new float[pathValueLength]; + this.nAcceptedPathValue = pathValue.length; + } + //------------------------------------------------------------------------ + // Methods. + //------------------------------------------------------------------------ + /** + * Routine to update this rate path with the values from another rate + * path, via its pathValue array. + * + * @param operandPath the path value array to use for the update. + * @exception DemoException thrown if there is a mismatch between the + * lengths of the operand and target arrays. + */ + public boolean inc_pathValue(float[] operandPath) { + if( pathValue.length != operandPath.length ) { + return false; + } + for(int i=0; ipathValue. + * + * @return Value of instance variable pathValue. + * @exception DemoException thrown if instance variable pathValue is undefined. + */ + public float[] get_pathValue() { + return(this.pathValue); + } + /** + * Set method for private instance variable pathValue. + * + * @param pathValue the value to set for the instance variable pathValue. + */ + public void set_pathValue(float[] pathValue) { + this.pathValue = pathValue; + } + /** + * Accessor method for private instance variable pathDate. + * + * @return Value of instance variable pathDate. + * @exception DemoException thrown if instance variable pathDate is undefined. + */ + public int[] get_pathDate() { + return(this.pathDate); + } + /** + * Set method for private instance variable pathDate. + * + * @param pathDate the value to set for the instance variable pathDate. + */ + public void set_pathDate(int[] pathDate) { + this.pathDate = pathDate; + } + //------------------------------------------------------------------------ + /** + * Method to return the terminal value for a given rate path, as used + * in derivative calculations. + * + * @return The last value in the rate path. + */ + public float getEndPathValue() { + return( getPathValue(pathValue.length-1) ); + } + /** + * Method to return the value for a given rate path, at a given index. + * One may want to index this in a more user friendly manner! + * + * @param index the index on which to return the path value. + * @return The value of the path at the designated index. + */ + public float getPathValue(int index) { + return(pathValue[index]); + } + /** + * Method for calculating the returns on a given rate path, via the + * definition for the instantaneous compounded return. + * u_i = \ln{\frac{S_i}{S_{i-1}}} + * + * @return the return, as defined. + * @exception DemoException thrown if there is a problem with the + * calculation. + */ + public ReturnPath getReturnCompounded() { + if( pathValue == null || nAcceptedPathValue == 0 ) { + return null; + } + float[] returnPathValue = new float[nAcceptedPathValue]; + returnPathValue[0] = (float)0.0; + for(int i=1; i< nAcceptedPathValue; i++ ) { + returnPathValue[i] = Math.logf(pathValue[i] / pathValue[i-1]); + } + + ReturnPath rPath = new ReturnPath(returnPathValue, nAcceptedPathValue, 1); + // + // Copy the PathId information to the ReturnPath object. + rPath.copyInstanceVariables(this); + rPath.estimatePath(); + return(rPath); + } + /** + * Method for calculating the returns on a given rate path, via the + * definition for the instantaneous non-compounded return. + * u_i = \frac{S_i - S_{i-1}}{S_i} + * + * @return the return, as defined. + * @exception DemoException thrown if there is a problem with the + * calculation. + */ + public ReturnPath getReturnNonCompounded() { + if( pathValue == null || nAcceptedPathValue == 0 ) { + return null; + } + float[] returnPathValue = new float[nAcceptedPathValue]; + returnPathValue[0] = (float)0.0; + for(int i=1; i< nAcceptedPathValue; i++ ) { + returnPathValue[i] = (pathValue[i] - pathValue[i-1])/pathValue[i]; + } + + ReturnPath rPath = new ReturnPath(returnPathValue, nAcceptedPathValue, 2); + // + // Copy the PathId information to the ReturnPath object. + rPath.copyInstanceVariables(this); + rPath.estimatePath(); + return(rPath); + } + //------------------------------------------------------------------------ + // Private methods. + //------------------------------------------------------------------------ + /** + * Method for reading in data file, in a given format. + * Namely: +
+      881003,0.0000,14.1944,13.9444,14.0832,2200050,0
+      881004,0.0000,14.1668,14.0556,14.1668,1490850,0
+      ...
+      990108,35.8125,36.7500,35.5625,35.8125,4381200,0
+      990111,35.8125,35.8750,34.8750,35.1250,3920800,0
+      990112,34.8750,34.8750,34.0000,34.0625,3577500,0
+      
+ *

Where the fields represent, one believes, the following: + *

    + *
  1. The date in 'YYMMDD' format
  2. + *
  3. Open
  4. + *
  5. High
  6. + *
  7. Low
  8. + *
  9. Last
  10. + *
  11. Volume
  12. + *
  13. Open Interest
  14. + *
+ * One will probably make use of the closing price, but this can be + * redefined via the class variable DATUMFIELD. Note that + * since the read in data are then used to compute the return, this would + * be a good place to trap for zero values in the data, which will cause + * all sorts of problems. + * + * @param dirName the directory in which to search for the data file. + * @param filename the data filename itself. + * @exception DemoException thrown if there was a problem with the data + * file. + */ + private void readRatesFile(){ + // + // Now create an array to store the rates data. + int nLines = 200; + int year = 88; + int month = 10; + int day = 3; + //System.printI(0xab0); + this.pathValue = new float[nLines]; + this.pathDate = new int[nLines]; + nAcceptedPathValue=0; + int iLine=0; + for(int k = 0; k < 40; k++ ) { + //System.printI(0xab1); + for(int j = 0; j < 5; j++) { + //System.printI(0xab2); + String date = "19"+String.valueOf(year); + if(month < 10) { + date += "0"; + } + date += String.valueOf(month); + if(day < 10) { + date += "0"; + } + date += String.valueOf(day); + int aDate = Integer.parseInt(date); + day++; + if(month == 2) { + if(day == 29) { + day = 1; + month++; + } + } else { + if(day == 31) { + day = 1; + month++; + if(month == 13) { + month = 1; + year++; + } + } + } + // + // static float float.parsefloat() method is a feature of JDK1.2! + float aPathValue = (float)(121.7500 - k - j); + //System.printI(0xab3); + if( (aDate <= MINIMUMDATE) || (Math.abs(aPathValue) < EPSILON) ) { + //System.printString("Skipped erroneous data indexed by date="+date+"."); + } else { + pathDate[iLine] = aDate; + pathValue[iLine] = aPathValue; + iLine++; + } + //System.printI(0xab4); + } + } + //System.printI(0xab5); + // + // Record the actual number of accepted data points. + nAcceptedPathValue = iLine; + // + // Now to fill in the structures from the 'PathId' class. + set_name("rate"); + set_startDate(pathDate[0]); + set_endDate(pathDate[nAcceptedPathValue-1]); + set_dTime((float)(1.0/365.0)); + //System.printI(0xab6); + } +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ReturnPath.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ReturnPath.java new file mode 100644 index 00000000..a682c151 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ReturnPath.java @@ -0,0 +1,357 @@ +/** Banboo Version **/ + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ + + +/** + * Class for representing the returns of a given security. + * + *

To do list: + *

    + *
  1. Define a window over which the mean drift and volatility + * are calculated.
  2. + *
  3. Hash table to reference {DATE}->{pathValue-index}.
  4. + *
+ * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $ + */ +public class ReturnPath extends PathId { + /** + * Flag for indicating one of the return definitions, via: + * u_i = \ln{\frac{S_i}{S_{i-1}}} + * corresponding to the instantaneous compounded return. + */ + public int COMPOUNDED; + + /** + * Flag for indicating one of the return definitions, via: + * u_i = \frac{S_i - S_{i-1}}{S_i} + * corresponding to the instantaneous non-compounded return. + */ + public int NONCOMPOUNDED; + + //------------------------------------------------------------------------ + // Instance variables. + //------------------------------------------------------------------------ + /** + * An instance variable, for storing the return values. + */ + private float[] pathValue; + /** + * The number of accepted values in the rate path. + */ + private int nPathValue; + /** + * Integer flag for indicating how the return was calculated. + */ + private int returnDefinition; + /** + * Value for the expected return rate. + */ + private float expectedReturnRate; + /** + * Value for the volatility, calculated from the return data. + */ + private float volatility; + /** + * Value for the volatility-squared, a more natural quantity + * to use for many of the calculations. + */ + private float volatility2; + /** + * Value for the mean of this return. + */ + private float mean; + /** + * Value for the variance of this return. + */ + private float variance; + + //------------------------------------------------------------------------ + // Constructors. + //------------------------------------------------------------------------ + /** + * Default constructor. + */ + public ReturnPath() { + super(); + + this.COMPOUNDED = 1; + this.NONCOMPOUNDED = 2; + this.nPathValue=-1; + this.returnDefinition = -1; + this.expectedReturnRate = (float)0.0; + this.volatility = (float)0.0; + this.volatility2 = (float)0.0; + this.mean = (float)0.0; + this.variance = (float)0.0; + } + + /** + * Another constructor. + * + * @param pathValue for creating a return path with a precomputed path + * value. Indexed from 1 to nPathArray-1. + * @param nPathValue the number of accepted data points in the array. + * @param returnDefinition to tell this class how the return path values + * were computed. + */ + public ReturnPath(float[] pathValue, int nPathValue, int returnDefinition) { + this.pathValue = pathValue; + this.nPathValue = nPathValue; + this.returnDefinition = returnDefinition; + + this.COMPOUNDED = 1; + this.NONCOMPOUNDED = 2; + this.expectedReturnRate = (float)0.0; + this.volatility = (float)0.0; + this.volatility2 = (float)0.0; + this.mean = (float)0.0; + this.variance = (float)0.0; + } + + //------------------------------------------------------------------------ + // Methods. + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + // Accessor methods for class ReturnPath. + // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999. + //------------------------------------------------------------------------ + /** + * Accessor method for private instance variable pathValue. + * + * @return Value of instance variable pathValue. + * @exception DemoException thrown if instance variable pathValue is undefined. + */ + public float[] get_pathValue(){ + return(this.pathValue); + } + /** + * Set method for private instance variable pathValue. + * + * @param pathValue the value to set for the instance variable pathValue. + */ + public void set_pathValue(float[] pathValue) { + this.pathValue = pathValue; + } + /** + * Accessor method for private instance variable nPathValue. + * + * @return Value of instance variable nPathValue. + * @exception DemoException thrown if instance variable nPathValue is undefined. + */ + public int get_nPathValue() { + return(this.nPathValue); + } + /** + * Set method for private instance variable nPathValue. + * + * @param nPathValue the value to set for the instance variable nPathValue. + */ + public void set_nPathValue(int nPathValue) { + this.nPathValue = nPathValue; + } + /** + * Accessor method for private instance variable returnDefinition. + * + * @return Value of instance variable returnDefinition. + * @exception DemoException thrown if instance variable returnDefinition is undefined. + */ + public int get_returnDefinition() { + return(this.returnDefinition); + } + /** + * Set method for private instance variable returnDefinition. + * + * @param returnDefinition the value to set for the instance variable returnDefinition. + */ + public void set_returnDefinition(int returnDefinition) { + this.returnDefinition = returnDefinition; + } + /** + * Accessor method for private instance variable expectedReturnRate. + * + * @return Value of instance variable expectedReturnRate. + * @exception DemoException thrown if instance variable expectedReturnRate is undefined. + */ + public float get_expectedReturnRate() { + return(this.expectedReturnRate); + } + /** + * Set method for private instance variable expectedReturnRate. + * + * @param expectedReturnRate the value to set for the instance variable expectedReturnRate. + */ + public void set_expectedReturnRate(float expectedReturnRate) { + this.expectedReturnRate = expectedReturnRate; + } + /** + * Accessor method for private instance variable volatility. + * + * @return Value of instance variable volatility. + * @exception DemoException thrown if instance variable volatility is undefined. + */ + public float get_volatility() { + return(this.volatility); + } + /** + * Set method for private instance variable volatility. + * + * @param volatility the value to set for the instance variable volatility. + */ + public void set_volatility(float volatility) { + this.volatility = volatility; + } + /** + * Accessor method for private instance variable volatility2. + * + * @return Value of instance variable volatility2. + * @exception DemoException thrown if instance variable volatility2 is undefined. + */ + public float get_volatility2() { + return(this.volatility2); + } + /** + * Set method for private instance variable volatility2. + * + * @param volatility2 the value to set for the instance variable volatility2. + */ + public void set_volatility2(float volatility2) { + this.volatility2 = volatility2; + } + /** + * Accessor method for private instance variable mean. + * + * @return Value of instance variable mean. + * @exception DemoException thrown if instance variable mean is undefined. + */ + public float get_mean() { + return(this.mean); + } + /** + * Set method for private instance variable mean. + * + * @param mean the value to set for the instance variable mean. + */ + public void set_mean(float mean) { + this.mean = mean; + } + /** + * Accessor method for private instance variable variance. + * + * @return Value of instance variable variance. + * @exception DemoException thrown if instance variable variance is undefined. + */ + public float get_variance() { + return(this.variance); + } + /** + * Set method for private instance variable variance. + * + * @param variance the value to set for the instance variable variance. + */ + public void set_variance(float variance) { + this.variance = variance; + } + //------------------------------------------------------------------------ + /** + * Method to calculate the expected return rate from the return data, + * using the relationship: + * \mu = \frac{\bar{u}}{\Delta t} + \frac{\sigma^2}{2} + * + * @exception DemoException thrown one tries to obtain an undefined variable. + */ + public void computeExpectedReturnRate() { + this.expectedReturnRate = mean/(float)get_dTime() + (float)0.5*volatility2; + } + /** + * Method to calculate volatility and volatility2 + * from the return path data, using the relationship, based on the + * precomputed variance. + * \sigma^2 = s^2\Delta t + * + * @exception DemoException thrown if one of the quantites in the + * computation are undefined. + */ + public void computeVolatility() { + this.volatility2 = this.variance / (float)get_dTime(); + this.volatility = Math.sqrtf(volatility2); + } + /** + * Method to calculate the mean of the return, for use by other + * calculations. + * + * @exception DemoException thrown if nPathValue is + * undefined. + */ + public void computeMean() { + this.mean = (float)0.0; + for( int i=1; i < nPathValue; i++ ) { + mean += pathValue[i]; + } + this.mean /= ((float)(nPathValue - (float)1.0)); + } + /** + * Method to calculate the variance of the retrun, for use by other + * calculations. + * + * @exception DemoException thrown if the mean or + * nPathValue values are undefined. + */ + public void computeVariance() { + this.variance = (float)0.0; + for( int i=1; i < nPathValue; i++ ) { + variance += (pathValue[i] - mean)*(pathValue[i] - mean); + } + this.variance /= ((float)(nPathValue - (float)1.0)); + } + /** + * A single method for invoking all the necessary methods which + * estimate the parameters. + * + * @exception DemoException thrown if there is a problem reading any + * variables. + */ + public void estimatePath() { + computeMean(); + //System.printI(0xb0); + computeVariance(); + //System.printI(0xb1); + computeExpectedReturnRate(); + //System.printI(0xb2); + computeVolatility(); + //System.printI(0xb3); + } + /** + * Dumps the contents of the fields, to standard-out, for debugging. + */ + public void dbgDumpFields() { + super.dbgDumpFields(); +// dbgPrintln("nPathValue=" +this.nPathValue); +// dbgPrintln("expectedReturnRate="+this.expectedReturnRate); +// dbgPrintln("volatility=" +this.volatility); +// dbgPrintln("volatility2=" +this.volatility2); +// dbgPrintln("mean=" +this.mean); +// dbgPrintln("variance=" +this.variance); + } +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToInitAllTasks.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToInitAllTasks.java new file mode 100644 index 00000000..41fe33e6 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToInitAllTasks.java @@ -0,0 +1,273 @@ +/** Banboo Version **/ + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ + +/** + * Class for defining the initialisation data for all tasks. + * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $ + */ +public class ToInitAllTasks { + private String header; + private String name; + private int startDate; + private int endDate; + private float dTime; + private int returnDefinition; + private float expectedReturnRate; + private float volatility; + private int nTimeSteps; + private float pathStartValue; + + /** + * Constructor, for initialisation data which are common to all + * computation tasks. + * + * @param header Simple header string. + * @param name The name of the security which this Monte Carlo path + * should represent. + * @param startDate The date when the path starts, in 'YYYYMMDD' format. + * @param endDate The date when the path ends, in 'YYYYMMDD' format. + * @param dTime The interval in the data between successive data points + * in the generated path. + * @param returnDefinition How the statistic variables were defined, + * according to the definitions in + * ReturnPath's two class variables + * COMPOUNDED and + * NONCOMPOUNDED. + * @param expectedReturnRate The measured expected return rate for which + * to generate. + * @param volatility The measured volatility for which to generate. + * @param nTimeSteps The number of time steps for which to generate. + * @param pathStartValue The stock price value to use at the start of each + * Monte Carlo simulation path. + */ + public ToInitAllTasks(String header, String name, int startDate, int endDate, + float dTime, int returnDefinition, float expectedReturnRate, float volatility, + float pathStartValue) { + this.header = header; + this.name = name; + this.startDate = startDate; + this.endDate = endDate; + this.dTime = dTime; + this.returnDefinition = returnDefinition; + this.expectedReturnRate = expectedReturnRate; + this.volatility = volatility; + this.nTimeSteps = nTimeSteps; + this.pathStartValue = pathStartValue; + } + /** + * Another constructor, slightly easier to use by having slightly + * fewer arguments. Makes use of the "ReturnPath" object to + * accomplish this. + * + * @param obj Object used to define the instance variables which + * should be carried over to this object. + * @param nTimeSteps The number of time steps which the Monte + * Carlo generator should make. + * @param pathStartValue The stock price value to use at the start of each + * Monte Carlo simulation path. + * @exception DemoException thrown if there is a problem accessing the + * instance variables from the target objetct. + */ + public ToInitAllTasks(ReturnPath obj, int nTimeSteps, float pathStartValue) { + // + // Instance variables defined in the PathId object. + this.name = obj.get_name(); + this.startDate = obj.get_startDate(); + this.endDate = obj.get_endDate(); + this.dTime = obj.get_dTime(); + // + // Instance variables defined in ReturnPath object. + this.returnDefinition = obj.get_returnDefinition(); + this.expectedReturnRate = obj.get_expectedReturnRate(); + this.volatility = obj.get_volatility(); + this.nTimeSteps = nTimeSteps; + this.pathStartValue = pathStartValue; + } + //------------------------------------------------------------------------ + // Accessor methods for class ToInitAllTasks. + // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999. + //------------------------------------------------------------------------ + /** + * Accessor method for private instance variable header. + * + * @return Value of instance variable header. + */ + public String get_header() { + return(this.header); + } + /** + * Set method for private instance variable header. + * + * @param header the value to set for the instance variable header. + */ + public void set_header(String header) { + this.header = header; + } + /** + * Accessor method for private instance variable name. + * + * @return Value of instance variable name. + */ + public String get_name() { + return(this.name); + } + /** + * Set method for private instance variable name. + * + * @param name the value to set for the instance variable name. + */ + public void set_name(String name) { + this.name = name; + } + /** + * Accessor method for private instance variable startDate. + * + * @return Value of instance variable startDate. + */ + public int get_startDate() { + return(this.startDate); + } + /** + * Set method for private instance variable startDate. + * + * @param startDate the value to set for the instance variable startDate. + */ + public void set_startDate(int startDate) { + this.startDate = startDate; + } + /** + * Accessor method for private instance variable endDate. + * + * @return Value of instance variable endDate. + */ + public int get_endDate() { + return(this.endDate); + } + /** + * Set method for private instance variable endDate. + * + * @param endDate the value to set for the instance variable endDate. + */ + public void set_endDate(int endDate) { + this.endDate = endDate; + } + /** + * Accessor method for private instance variable dTime. + * + * @return Value of instance variable dTime. + */ + public float get_dTime() { + return(this.dTime); + } + /** + * Set method for private instance variable dTime. + * + * @param dTime the value to set for the instance variable dTime. + */ + public void set_dTime(float dTime) { + this.dTime = dTime; + } + /** + * Accessor method for private instance variable returnDefinition. + * + * @return Value of instance variable returnDefinition. + */ + public int get_returnDefinition() { + return(this.returnDefinition); + } + /** + * Set method for private instance variable returnDefinition. + * + * @param returnDefinition the value to set for the instance variable returnDefinition. + */ + public void set_returnDefinition(int returnDefinition) { + this.returnDefinition = returnDefinition; + } + /** + * Accessor method for private instance variable expectedReturnRate. + * + * @return Value of instance variable expectedReturnRate. + */ + public float get_expectedReturnRate() { + return(this.expectedReturnRate); + } + /** + * Set method for private instance variable expectedReturnRate. + * + * @param expectedReturnRate the value to set for the instance variable expectedReturnRate. + */ + public void set_expectedReturnRate(float expectedReturnRate) { + this.expectedReturnRate = expectedReturnRate; + } + /** + * Accessor method for private instance variable volatility. + * + * @return Value of instance variable volatility. + */ + public float get_volatility() { + return(this.volatility); + } + /** + * Set method for private instance variable volatility. + * + * @param volatility the value to set for the instance variable volatility. + */ + public void set_volatility(float volatility) { + this.volatility = volatility; + } + /** + * Accessor method for private instance variable nTimeSteps. + * + * @return Value of instance variable nTimeSteps. + */ + public int get_nTimeSteps() { + return(this.nTimeSteps); + } + /** + * Set method for private instance variable nTimeSteps. + * + * @param nTimeSteps the value to set for the instance variable nTimeSteps. + */ + public void set_nTimeSteps(int nTimeSteps) { + this.nTimeSteps = nTimeSteps; + } + /** + * Accessor method for private instance variable pathStartValue. + * + * @return Value of instance variable pathStartValue. + */ + public float get_pathStartValue() { + return(this.pathStartValue); + } + /** + * Set method for private instance variable pathStartValue. + * + * @param pathStartValue the value to set for the instance variable pathStartValue. + */ + public void set_pathStartValue(float pathStartValue) { + this.pathStartValue = pathStartValue; + } + //------------------------------------------------------------------------ +} diff --git a/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToResult.java b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToResult.java new file mode 100644 index 00000000..cd0396c0 --- /dev/null +++ b/Robust/src/Benchmarks/Scheduling/JGFMonteCarlo/ToResult.java @@ -0,0 +1,167 @@ +/** Banboo Version **/ + +/************************************************************************** +* * +* Java Grande Forum Benchmark Suite - Thread Version 1.0 * +* * +* produced by * +* * +* Java Grande Benchmarking Project * +* * +* at * +* * +* Edinburgh Parallel Computing Centre * +* * +* email: epcc-javagrande@epcc.ed.ac.uk * +* * +* Original version of this code by Hon Yau (hwyau@epcc.ed.ac.uk) * +* * +* This version copyright (c) The University of Edinburgh, 2001. * +* All rights reserved. * +* * +**************************************************************************/ + +/** + * Class for defining the results of a task. Currently, this is simply + * the Monte Carlo generate rate path. + * + * @author H W Yau + * @version $Revision: 1.1 $ $Date: 2008/08/18 22:22:21 $ + */ +public class ToResult { + private String header; + private float expectedReturnRate; + private float volatility; + private float volatility2; + private float finalStockPrice; + private float[] pathValue; + + /** + * Constructor, for the results from a computation. + * + * @param header Simple header string. + * @param pathValue Data computed by the Monte Carlo generator. + */ + public ToResult(String header, float expectedReturnRate, float volatility, + float volatility2, float finalStockPrice, float[] pathValue) { + this.header=header; + this.expectedReturnRate = expectedReturnRate; + this.volatility = volatility; + this.volatility2 = volatility2; + this.finalStockPrice = finalStockPrice; + this.pathValue = pathValue; + } + /** + * Gives a simple string representation of this object. + * + * @return String representation of this object. + */ + public String toString(){ + return(header); + } + //------------------------------------------------------------------------ + // Accessor methods for class ToResult. + // Generated by 'makeJavaAccessor.pl' script. HWY. 20th January 1999. + //------------------------------------------------------------------------ + /** + * Accessor method for private instance variable header. + * + * @return Value of instance variable header. + */ + public String get_header() { + return(this.header); + } + /** + * Set method for private instance variable header. + * + * @param header the value to set for the instance variable header. + */ + public void set_header(String header) { + this.header = header; + } + /** + * Accessor method for private instance variable expectedReturnRate. + * + * @return Value of instance variable expectedReturnRate. + */ + public float get_expectedReturnRate() { + return(this.expectedReturnRate); + } + /** + * Set method for private instance variable expectedReturnRate. + * + * @param expectedReturnRate the value to set for the instance variable + * expectedReturnRate. + */ + public void set_expectedReturnRate(float expectedReturnRate) { + this.expectedReturnRate = expectedReturnRate; + } + /** + * Accessor method for private instance variable volatility. + * + * @return Value of instance variable volatility. + */ + public float get_volatility() { + return(this.volatility); + } + /** + * Set method for private instance variable volatility. + * + * @param volatility the value to set for the instance variable volatility. + */ + public void set_volatility(float volatility) { + this.volatility = volatility; + } + /** + * Accessor method for private instance variable volatility2. + * + * @return Value of instance variable volatility2. + */ + public float get_volatility2() { + return(this.volatility2); + } + /** + * Set method for private instance variable volatility2. + * + * @param volatility2 the value to set for the instance variable volatility2. + */ + public void set_volatility2(float volatility2) { + this.volatility2 = volatility2; + } + /** + * Accessor method for private instance variable finalStockPrice. + * + * @return Value of instance variable finalStockPrice. + */ + public float get_finalStockPrice() { + return(this.finalStockPrice); + } + /** + * Set method for private instance variable finalStockPrice. + * + * @param finalStockPrice the value to set for the instance variable + * finalStockPrice. + */ + public void set_finalStockPrice(float finalStockPrice) { + this.finalStockPrice = finalStockPrice; + } + /** + * Accessor method for private instance variable pathValue. + * + * @return Value of instance variable pathValue. + */ + public float[] get_pathValue() { + return(this.pathValue); + } + /** + * Set method for private instance variable pathValue. + * + * @param pathValue the value to set for the instance variable pathValue. + */ + public void set_pathValue(float[] pathValue) { + this.pathValue = pathValue; + } + //------------------------------------------------------------------------ +} + + diff --git a/Robust/src/Benchmarks/Scheduling/JGFSeries/JGFSeriesBench.java b/Robust/src/Benchmarks/Scheduling/JGFSeries/JGFSeriesBench.java index adb5e0ce..f3090f7d 100644 --- a/Robust/src/Benchmarks/Scheduling/JGFSeries/JGFSeriesBench.java +++ b/Robust/src/Benchmarks/Scheduling/JGFSeries/JGFSeriesBench.java @@ -23,7 +23,7 @@ task t1(StartupObject s{initialstate}) { //System.printString("task t1\n"); - int datasize = 16; + int datasize = 32; for(int i = 0; i < datasize; ++i) { SeriesRunner sr = new SeriesRunner(i){!finish}; } diff --git a/Robust/src/Benchmarks/Scheduling/JGFSeries/SeriesRunner.java b/Robust/src/Benchmarks/Scheduling/JGFSeries/SeriesRunner.java index 25ac2ba6..d8dcd6da 100644 --- a/Robust/src/Benchmarks/Scheduling/JGFSeries/SeriesRunner.java +++ b/Robust/src/Benchmarks/Scheduling/JGFSeries/SeriesRunner.java @@ -59,7 +59,6 @@ public class SeriesRunner { // Calculate the fundamental frequency. // ( 2 * pi ) / period...and since the period // is 2, omega is simply pi. - //float omega = (float) 3.1415926535897932; // Fundamental frequency. float omega = (float) 3.1415926535897932; // Fundamental frequency. // Calculate A[i] terms. Note, once again, that we diff --git a/Robust/src/Benchmarks/Scheduling/JGFSeries/c/JGFSeriesBench.c b/Robust/src/Benchmarks/Scheduling/JGFSeries/c/JGFSeriesBench.c index 94659c44..7a012d2f 100644 --- a/Robust/src/Benchmarks/Scheduling/JGFSeries/c/JGFSeriesBench.c +++ b/Robust/src/Benchmarks/Scheduling/JGFSeries/c/JGFSeriesBench.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) { #endif void begin(void) { - int datasize = 16; + int datasize = 32; int i = 0; /* Main loop: */ for(i = 0; i < datasize; ++i) { diff --git a/Robust/src/ClassLibrary/Math.java b/Robust/src/ClassLibrary/Math.java index e9d790a8..cd38a2e8 100644 --- a/Robust/src/ClassLibrary/Math.java +++ b/Robust/src/ClassLibrary/Math.java @@ -28,7 +28,8 @@ public class Math { public static native float sinf(float a); public static native float cosf(float a); + public static native float expf(float a); public static native float sqrtf(float a); - public static native double logf(float a); + public static native float logf(float a); public static native float powf(float a, float b); } diff --git a/Robust/src/IR/Flat/BuildCodeMultiCore.java b/Robust/src/IR/Flat/BuildCodeMultiCore.java index 2b9691af..c737b5fc 100644 --- a/Robust/src/IR/Flat/BuildCodeMultiCore.java +++ b/Robust/src/IR/Flat/BuildCodeMultiCore.java @@ -612,6 +612,10 @@ public class BuildCodeMultiCore extends BuildCode { output.println("for(;tmpindex < tmplen; tmpindex++) {"); output.println(" tmpsum = tmpsum * 10 + *(taskname + tmpindex) - '0';"); output.println("}"); + output.println("#ifdef RAWPATH"); + output.println("raw_test_pass(0xAAAA);"); + output.println("raw_test_pass_reg(tmpsum);"); + output.println("#endif"); output.println("#ifdef RAWDEBUG"); output.println("raw_test_pass(0xAAAA);"); output.println("raw_test_pass_reg(tmpsum);"); @@ -968,7 +972,7 @@ public class BuildCodeMultiCore extends BuildCode { output.println("}"); } - Vector sendto = new Vector(); + Vector sendto = new Vector(); Queue queue = null; if(targetCoreTbl != null) { queue = targetCoreTbl.get(tmpFState); @@ -1017,20 +1021,26 @@ public class BuildCodeMultiCore extends BuildCode { // enqueue this object and its destinations for later process // all the possible queues QueueInfo qinfo = null; + TranObjInfo tmpinfo = new TranObjInfo(); + tmpinfo.name = super.generateTemp(fm, temp, lb); + tmpinfo.targetcore = targetcore; FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); if(targetFS != null) { - qinfo = outputtransqueues(targetFS, targetcore, output); + tmpinfo.fs = targetFS; } else { - qinfo = outputtransqueues(tmpFState, targetcore, output); + tmpinfo.fs = tmpFState; + } + if(!contains(sendto, tmpinfo)){ + qinfo = outputtransqueues(tmpinfo.fs, targetcore, output); + output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); + output.println("tmpObjInfo->objptr = (void *)" + tmpinfo.name + ";"); + output.println("tmpObjInfo->targetcore = "+targetcore.toString()+";"); + output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); + output.println("tmpObjInfo->length = " + qinfo.length + ";"); + output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); + sendto.add(tmpinfo); } - output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); - output.println("tmpObjInfo->objptr = (void *)" + super.generateTemp(fm, temp, lb) + ";"); - output.println("tmpObjInfo->targetcore = "+targetcore.toString()+";"); - output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); - output.println("tmpObjInfo->length = " + qinfo.length + ";"); - output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); output.println("}"); - sendto.add(targetcore); } output.println("break;"); } @@ -1047,20 +1057,26 @@ public class BuildCodeMultiCore extends BuildCode { // enqueue this object and its destinations for later process // all the possible queues QueueInfo qinfo = null; + TranObjInfo tmpinfo = new TranObjInfo(); + tmpinfo.name = super.generateTemp(fm, temp, lb); + tmpinfo.targetcore = targetcore; FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); if(targetFS != null) { - qinfo = outputtransqueues(targetFS, targetcore, output); + tmpinfo.fs = targetFS; } else { - qinfo = outputtransqueues(tmpFState, targetcore, output); + tmpinfo.fs = tmpFState; + } + if(!contains(sendto, tmpinfo)){ + qinfo = outputtransqueues(tmpinfo.fs, targetcore, output); + output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); + output.println("tmpObjInfo->objptr = (void *)" + tmpinfo.name + ";"); + output.println("tmpObjInfo->targetcore = "+targetcore.toString()+";"); + output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); + output.println("tmpObjInfo->length = " + qinfo.length + ";"); + output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); + sendto.add(tmpinfo); } - output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); - output.println("tmpObjInfo->objptr = (void *)" + super.generateTemp(fm, temp, lb) + ";"); - output.println("tmpObjInfo->targetcore = "+targetcore.toString()+";"); - output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); - output.println("tmpObjInfo->length = " + qinfo.length + ";"); - output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); output.println("}"); - sendto.add(targetcore); } output.println("/* increase index*/"); output.println("++" + queueins + ".index;"); @@ -1089,26 +1105,33 @@ public class BuildCodeMultiCore extends BuildCode { for(int k = 0; k < targetcores.size(); ++k) { // TODO // add the information of exactly which queue - if(!sendto.contains(targetcores.elementAt(i))) { + //if(!sendto.contains(targetcores.elementAt(i))) { // previously not sended to this target core // enqueue this object and its destinations for later process output.println("{"); // all the possible queues QueueInfo qinfo = null; + TranObjInfo tmpinfo = new TranObjInfo(); + tmpinfo.name = super.generateTemp(fm, temp, lb); + tmpinfo.targetcore = targetcores.elementAt(i); FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); if(targetFS != null) { - qinfo = outputtransqueues(targetFS, targetcores.elementAt(i), output); + tmpinfo.fs = targetFS; } else { - qinfo = outputtransqueues(tmpFState, targetcores.elementAt(i), output); + tmpinfo.fs = tmpFState; + } + if(!contains(sendto, tmpinfo)){ + qinfo = outputtransqueues(tmpinfo.fs, targetcores.elementAt(i), output); + output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); + output.println("tmpObjInfo->objptr = (void *)" + tmpinfo.name + ";"); + output.println("tmpObjInfo->targetcore = "+targetcores.elementAt(i).toString()+";"); + output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); + output.println("tmpObjInfo->length = " + qinfo.length + ";"); + output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); + sendto.add(tmpinfo); } - output.println("tmpObjInfo = RUNMALLOC(sizeof(struct transObjInfo));"); - output.println("tmpObjInfo->objptr = (void *)" + super.generateTemp(fm, temp, lb) + ";"); - output.println("tmpObjInfo->targetcore = "+targetcores.elementAt(i).toString()+";"); - output.println("tmpObjInfo->queues = " + qinfo.qname + ";"); - output.println("tmpObjInfo->length = " + qinfo.length + ";"); - output.println("addNewItem(totransobjqueue, (void*)tmpObjInfo);"); output.println("}"); - } + //} } } } @@ -1251,4 +1274,29 @@ public class BuildCodeMultiCore extends BuildCode { output.println("return;"); } } + + class TranObjInfo { + public String name; + public int targetcore; + public FlagState fs; + } + + private boolean contains(Vector sendto, TranObjInfo t) { + if(sendto.size() == 0) { + return false; + } + for(int i = 0; i < sendto.size(); i++) { + TranObjInfo tmp = sendto.elementAt(i); + if(!tmp.name.equals(t.name)) { + return false; + } + if(tmp.targetcore != t.targetcore) { + return false; + } + if(tmp.fs != t.fs) { + return false; + } + } + return true; + } } diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index e218d333..8f0d548a 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -308,13 +308,14 @@ public class Main { int newRate = 1; String cdname = cd.getSymbol(); if((cdname.equals("SeriesRunner")) || - (cdname.equals("MDRunner"))) { + (cdname.equals("MDRunner")) || + (cdname.equals("Stage")) || + (cdname.equals("AppDemoRunner")) || + (cdname.equals("FilterBankAtom"))) { newRate = 16; } else if(cdname.equals("SentenceParser")) { newRate = 4; - } /*else if(cdname.equals("ReduceWorker")) { - newRate = 3; - }*/ + } /*do { tint = r.nextInt()%100; } while(tint <= 0); @@ -418,7 +419,7 @@ public class Main { if(state.MULTICORE) { //it_scheduling = scheduleAnalysis.getSchedulingsIter(); //Vector scheduling = (Vector)it_scheduling.next(); - Vector scheduling = scheduleAnalysis.getSchedulings().elementAt(selectedScheduling.elementAt(0)); + Vector scheduling = scheduleAnalysis.getSchedulings().elementAt(selectedScheduling.lastElement()); BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, bf.getMap(), tu, sa, scheduling, scheduleAnalysis.getCoreNum(), pa); bcm.buildCode(); } diff --git a/Robust/src/Runtime/math.c b/Robust/src/Runtime/math.c index 7a54d283..6d5369ca 100644 --- a/Robust/src/Runtime/math.c +++ b/Robust/src/Runtime/math.c @@ -50,6 +50,10 @@ float CALL11(___Math______sinf____F, float ___a___, float ___a___) { return sinf(___a___); } +float CALL11(___Math______expf____F, float ___a___, float ___a___) { + return expf(___a___); +} + float CALL11(___Math______sqrtf____F, float ___a___, float ___a___) { return sqrtf(___a___); } diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 01516953..2ca150d2 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -72,6 +72,12 @@ int msgdata[30]; int msgtype; int msgdataindex; int msglength; +int outmsgdata[30]; +int outmsgindex; +int outmsglast; +int outmsgleft; +bool isMsgHanging; +bool isMsgSending; void calCoords(int core_num, int* coordY, int* coordX); #elif defined THREADSIMULATE static struct RuntimeHash* locktbl; @@ -144,6 +150,15 @@ int main(int argc, char **argv) { msgtype = -1; msgdataindex = 0; msglength = 30; + + for(i = 0; i < 30; ++i) { + outmsgdata[i] = -1; + } + outmsgindex = 0; + outmsglast = 0; + outmsgleft = 0; + isMsgHanging = false; + isMsgSending = false; #ifdef RAWDEBUG raw_test_pass(0xee02); #endif @@ -381,7 +396,7 @@ void run(void* arg) { if(grount == 1) { int k = 0; - raw_invalidate_cache_range(obj, classsize[((struct ___Object___ *)obj)->type]); + raw_invalidate_cache_range((int)obj, classsize[((struct ___Object___ *)obj)->type]); // flush the obj /*for(k = 0; k < classsize[((struct ___Object___ *)obj)->type]; ++k) { invalidateAddr(obj + k); @@ -1292,6 +1307,8 @@ void transferObject(struct transObjInfo * transObj) { msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. self_y, self_x, target_y, target_x); + // start sending msg, set sand msg flag + isMsgSending = true; gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG raw_test_pass(0xbbbb); @@ -1325,6 +1342,48 @@ void transferObject(struct transObjInfo * transObj) { raw_test_pass(0xffff); #endif ++(self_numsendobjs); + // end of sending this msg, set sand msg flag false + isMsgSending = false; + // check if there are pending msgs + while(isMsgHanging) { + // get the msg from outmsgdata[] + // length + target + msg + outmsgleft = outmsgdata[outmsgindex++]; + targetcore = outmsgdata[outmsgindex++]; + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + isMsgSending = true; + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). +#ifdef RAWDEBUG + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore +#endif + while(outmsgleft-- > 0) { + gdn_send(outmsgdata[outmsgindex++]); +#ifdef RAWDEBUG + raw_test_pass_reg(outmsgdata[outmsgindex - 1]); +#endif + } +#ifdef RAWDEBUG + raw_test_pass(0xffff); +#endif + isMsgSending = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // check if there are still msg hanging + if(outmsgindex == outmsglast) { + // no more msgs + outmsgindex = outmsglast = 0; + isMsgHanging = false; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); @@ -1406,6 +1465,8 @@ bool transStallMsg(int targetcore) { msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. self_y, self_x, target_y, target_x); + // start sending msgs, set msg sending flag + isMsgSending = true; gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG raw_test_pass(0xbbbb); @@ -1428,6 +1489,48 @@ bool transStallMsg(int targetcore) { raw_test_pass_reg(self_numreceiveobjs); raw_test_pass(0xffff); #endif + // end of sending this msg, set sand msg flag false + isMsgSending = false; + // check if there are pending msgs + while(isMsgHanging) { + // get the msg from outmsgdata[] + // length + target + msg + outmsgleft = outmsgdata[outmsgindex++]; + targetcore = outmsgdata[outmsgindex++]; + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + isMsgSending = true; + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). +#ifdef RAWDEBUG + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore +#endif + while(outmsgleft-- > 0) { + gdn_send(outmsgdata[outmsgindex++]); +#ifdef RAWDEBUG + raw_test_pass_reg(outmsgdata[outmsgindex - 1]); +#endif + } +#ifdef RAWDEBUG + raw_test_pass(0xffff); +#endif + isMsgSending = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // check if there are still msg hanging + if(outmsgindex == outmsglast) { + // no more msgs + outmsgindex = outmsglast = 0; + isMsgHanging = false; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } return true; #elif defined THREADSIMULATE struct ___Object___ *newobj = RUNMALLOC(sizeof(struct ___Object___)); @@ -1595,8 +1698,27 @@ msg: raw_test_pass_reg(transObj->queues[2*k+1]); #endif } + // check if there is an existing duplicate item + { + struct QueueItem * qitem = getTail(&objqueue); + struct QueueItem * prev = NULL; + while(qitem != NULL) { + struct transObjInfo * tmpinfo = (struct transObjInfo *)(qitem->objectptr); + if(tmpinfo->objptr == transObj->objptr) { + // the same object, remove outdate one + removeItem(&objqueue, qitem); + } else { + prev = qitem; + } + if(prev == NULL) { + qitem = getTail(&objqueue); + } else { + qitem = getNext(prev); + } + } //memcpy(transObj->queues, msgdata[3], sizeof(int)*(msglength - 3)); addNewItem_I(&objqueue, (void *)transObj); + } ++(self_numreceiveobjs); #ifdef RAWDEBUG raw_test_pass(0xe881); @@ -1679,39 +1801,62 @@ msg: #endif } targetcore = data3; - calCoords(corenum, &self_y, &self_x); - calCoords(targetcore, &target_y, &target_x); - // Build the message header - msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. - self_y, self_x, - target_y, target_x); - gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). + // check if there is still some msg on sending + if(isMsgSending) { #ifdef RAWDEBUG - raw_test_pass(0xbbbb); - raw_test_pass(0xb000 + targetcore); // targetcore + raw_test_pass(0xe885); #endif - if(deny == true) { - // deny the lock request - gdn_send(4); // lock request + isMsgHanging = true; + // cache the msg in outmsgdata and send it later + // msglength + target core + msg + outmsgdata[outmsglast++] = msgsize; + outmsgdata[outmsglast++] = targetcore; + if(deny == true) { + outmsgdata[outmsglast++] = 4; + } else { + outmsgdata[outmsglast++] = 3; + } + outmsgdata[outmsglast++] = data1; + outmsgdata[outmsglast++] = data2; + } else { #ifdef RAWDEBUG - raw_test_pass(4); + raw_test_pass(0xe886); #endif - } else { - // grount the lock request - gdn_send(3); // lock request + // no msg on sending, send it out + calCoords(corenum, &self_y, &self_x); + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG - raw_test_pass(3); + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore #endif - } - gdn_send(data1); // lock type + if(deny == true) { + // deny the lock request + gdn_send(4); // lock request #ifdef RAWDEBUG - raw_test_pass_reg(data1); + raw_test_pass(4); #endif - gdn_send(data2); // lock target + } else { + // grount the lock request + gdn_send(3); // lock request #ifdef RAWDEBUG - raw_test_pass_reg(data2); - raw_test_pass(0xffff); + raw_test_pass(3); #endif + } + gdn_send(data1); // lock type +#ifdef RAWDEBUG + raw_test_pass_reg(data1); +#endif + gdn_send(data2); // lock target +#ifdef RAWDEBUG + raw_test_pass_reg(data2); + raw_test_pass(0xffff); +#endif + } break; } case 3: { @@ -1757,7 +1902,7 @@ msg: int rwlock_obj = 0; RuntimeHashget(locktbl, data2, &rwlock_obj); #ifdef RAWDEBUG - raw_test_pass(0xe885); + raw_test_pass(0xe887); raw_test_pass_reg(rwlock_obj); #endif if(data1 == 0) { @@ -1785,7 +1930,7 @@ msg: //msgdataindex = 0; msglength = 30; #ifdef RAWDEBUG - raw_test_pass(0xe886); + raw_test_pass(0xe888); #endif if(gdn_input_avail() != 0) { goto msg; @@ -1794,7 +1939,7 @@ msg: } else { // not a whole msg #ifdef RAWDEBUG - raw_test_pass(0xe887); + raw_test_pass(0xe889); #endif return -2; } @@ -1862,10 +2007,18 @@ bool getreadlock(void * ptr) { #ifdef RAW unsigned msgHdr; int self_y, self_x, target_y, target_x; - int targetcore = ((int)ptr >> 5) % TOTALCORE; + int targetcore = 0; //((int)ptr >> 5) % TOTALCORE; // for 32 bit machine, the size is always 4 words //int msgsize = sizeof(int) * 4; int msgsize = 4; + int tc = TOTALCORE; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + targetcore = ((int)ptr >> 5) % tc; +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif lockobj = (int)ptr; lockflag = false; @@ -1923,6 +2076,8 @@ bool getreadlock(void * ptr) { msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. self_y, self_x, target_y, target_x); + // start sending the msg, set send msg flag + isMsgSending = true; gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG raw_test_pass(0xbbbb); @@ -1945,6 +2100,48 @@ bool getreadlock(void * ptr) { raw_test_pass_reg(corenum); raw_test_pass(0xffff); #endif + // end of sending this msg, set sand msg flag false + isMsgSending = false; + // check if there are pending msgs + while(isMsgHanging) { + // get the msg from outmsgdata[] + // length + target + msg + outmsgleft = outmsgdata[outmsgindex++]; + targetcore = outmsgdata[outmsgindex++]; + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + isMsgSending = true; + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). +#ifdef RAWDEBUG + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore +#endif + while(outmsgleft-- > 0) { + gdn_send(outmsgdata[outmsgindex++]); +#ifdef RAWDEBUG + raw_test_pass_reg(outmsgdata[outmsgindex - 1]); +#endif + } +#ifdef RAWDEBUG + raw_test_pass(0xffff); +#endif + isMsgSending = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // check if there are still msg hanging + if(outmsgindex == outmsglast) { + // no more msgs + outmsgindex = outmsglast = 0; + isMsgHanging = false; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } return true; #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); @@ -2007,10 +2204,18 @@ void releasereadlock(void * ptr) { #ifdef RAW unsigned msgHdr; int self_y, self_x, target_y, target_x; - int targetcore = ((int)ptr >> 5) % TOTALCORE; + int targetcore = 0; //((int)ptr >> 5) % TOTALCORE; // for 32 bit machine, the size is always 3 words //int msgsize = sizeof(int) * 3; int msgsize = 3; + int tc = TOTALCORE; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + targetcore = ((int)ptr >> 5) % tc; +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif if(targetcore == corenum) { #ifdef INTERRUPT @@ -2039,6 +2244,8 @@ void releasereadlock(void * ptr) { msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. self_y, self_x, target_y, target_x); + // start sending the msg, set send msg flag + isMsgSending = true; gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG raw_test_pass(0xbbbb); @@ -2057,6 +2264,48 @@ void releasereadlock(void * ptr) { raw_test_pass_reg(ptr); raw_test_pass(0xffff); #endif + // end of sending this msg, set sand msg flag false + isMsgSending = false; + // check if there are pending msgs + while(isMsgHanging) { + // get the msg from outmsgdata[] + // length + target + msg + outmsgleft = outmsgdata[outmsgindex++]; + targetcore = outmsgdata[outmsgindex++]; + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + isMsgSending = true; + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). +#ifdef RAWDEBUG + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore +#endif + while(outmsgleft-- > 0) { + gdn_send(outmsgdata[outmsgindex++]); +#ifdef RAWDEBUG + raw_test_pass_reg(outmsgdata[outmsgindex - 1]); +#endif + } +#ifdef RAWDEBUG + raw_test_pass(0xffff); +#endif + isMsgSending = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // check if there are still msg hanging + if(outmsgindex == outmsglast) { + // no more msgs + outmsgindex = outmsglast = 0; + isMsgHanging = false; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); int rc = pthread_rwlock_rdlock(&rwlock_tbl); @@ -2213,17 +2462,17 @@ bool getwritelock(void * ptr) { #ifdef RAW unsigned msgHdr; int self_y, self_x, target_y, target_x; - int targetcore = ((int)ptr >> 5) % TOTALCORE; + int targetcore = 0; //((int)ptr >> 5) % TOTALCORE; // for 32 bit machine, the size is always 4 words //int msgsize = sizeof(int) * 4; int msgsize= 4; int tc = TOTALCORE; #ifdef INTERRUPT - //raw_user_interrupts_off(); + raw_user_interrupts_off(); #endif - //targetcore = ((int)ptr) % tc; + targetcore = ((int)ptr >> 5) % tc; #ifdef INTERRUPT - //raw_user_interrupts_on(); + raw_user_interrupts_on(); #endif #ifdef RAWDEBUG @@ -2309,6 +2558,8 @@ bool getwritelock(void * ptr) { msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. self_y, self_x, target_y, target_x); + // start sending the msg, set send msg flag + isMsgSending = true; gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG raw_test_pass(0xbbbb); @@ -2331,6 +2582,48 @@ bool getwritelock(void * ptr) { raw_test_pass_reg(corenum); raw_test_pass(0xffff); #endif + // end of sending this msg, set sand msg flag false + isMsgSending = false; + // check if there are pending msgs + while(isMsgHanging) { + // get the msg from outmsgdata[] + // length + target + msg + outmsgleft = outmsgdata[outmsgindex++]; + targetcore = outmsgdata[outmsgindex++]; + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + isMsgSending = true; + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). +#ifdef RAWDEBUG + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore +#endif + while(outmsgleft-- > 0) { + gdn_send(outmsgdata[outmsgindex++]); +#ifdef RAWDEBUG + raw_test_pass_reg(outmsgdata[outmsgindex - 1]); +#endif + } +#ifdef RAWDEBUG + raw_test_pass(0xffff); +#endif + isMsgSending = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // check if there are still msg hanging + if(outmsgindex == outmsglast) { + // no more msgs + outmsgindex = outmsglast = 0; + isMsgHanging = false; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } return true; #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); @@ -2396,10 +2689,18 @@ void releasewritelock(void * ptr) { #ifdef RAW unsigned msgHdr; int self_y, self_x, target_y, target_x; - int targetcore = ((int)ptr >> 5) % TOTALCORE; + int targetcore = 0; //((int)ptr >> 5) % TOTALCORE; // for 32 bit machine, the size is always 3 words //int msgsize = sizeof(int) * 3; int msgsize = 3; + int tc = TOTALCORE; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + targetcore = ((int)ptr >> 5) % tc; +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif if(targetcore == corenum) { #ifdef INTERRUPT @@ -2440,6 +2741,8 @@ void releasewritelock(void * ptr) { msgHdr = construct_dyn_hdr(0, msgsize, 0, // msgsize word sent. self_y, self_x, target_y, target_x); + // start sending the msg, set send msg flag + isMsgSending = true; gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). #ifdef RAWDEBUG raw_test_pass(0xbbbb); @@ -2458,6 +2761,48 @@ void releasewritelock(void * ptr) { raw_test_pass_reg(ptr); raw_test_pass(0xffff); #endif + // end of sending this msg, set sand msg flag false + isMsgSending = false; + // check if there are pending msgs + while(isMsgHanging) { + // get the msg from outmsgdata[] + // length + target + msg + outmsgleft = outmsgdata[outmsgindex++]; + targetcore = outmsgdata[outmsgindex++]; + calCoords(targetcore, &target_y, &target_x); + // Build the message header + msgHdr = construct_dyn_hdr(0, outmsgleft, 0, // msgsize word sent. + self_y, self_x, + target_y, target_x); + isMsgSending = true; + gdn_send(msgHdr); // Send the message header to EAST to handle fab(n - 1). +#ifdef RAWDEBUG + raw_test_pass(0xbbbb); + raw_test_pass(0xb000 + targetcore); // targetcore +#endif + while(outmsgleft-- > 0) { + gdn_send(outmsgdata[outmsgindex++]); +#ifdef RAWDEBUG + raw_test_pass_reg(outmsgdata[outmsgindex - 1]); +#endif + } +#ifdef RAWDEBUG + raw_test_pass(0xffff); +#endif + isMsgSending = false; +#ifdef INTERRUPT + raw_user_interrupts_off(); +#endif + // check if there are still msg hanging + if(outmsgindex == outmsglast) { + // no more msgs + outmsgindex = outmsglast = 0; + isMsgHanging = false; + } +#ifdef INTERRUPT + raw_user_interrupts_on(); +#endif + } #elif defined THREADSIMULATE int numofcore = pthread_getspecific(key); int rc = pthread_rwlock_rdlock(&rwlock_tbl); @@ -3105,8 +3450,10 @@ execute: #endif #ifdef RAWDEBUG raw_test_pass(0xe99a); - raw_test_pass_reg(lock); - #endif +#endif +#ifdef RAWPATH + raw_test_pass(0xe99a); +#endif } } diff --git a/Robust/src/buildscript b/Robust/src/buildscript index a257d8ea..3ba69925 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -21,6 +21,7 @@ echo "-numcore set the number of cores (should be used together with -multicore) echo "-raw generate raw version binary (should be used together with -multicore)" echo "-interrupt generate raw version binary with interruption (should be used togethere with -raw)" echo "-rawconfig config raw simulator as 4xn (should be used together with -raw)" +echo "-rawpath print out execute path information for raw version (should be used together with -raw)" echo -threadsimulate generate multi-thread simulate version binary echo -optional enable optional echo -debug generate debug symbols @@ -54,6 +55,7 @@ TRANSSTATSFLAG=false RAWFLAG=false RAWCONFIG='' RAWDEBUGFLAG=false +RAWPATHFLAG=false INTERRUPTFLAG=false THREADSIMULATEFLAG=false; USEDMALLOC=false @@ -189,6 +191,9 @@ elif [[ $1 = '-debug' ]] then RAWDEBUGFLAG=true EXTRAOPTIONS="$EXTRAOPTIONS -g" +elif [[ $1 = '-rawpath' ]] +then +RAWPATHFLAG=true elif [[ $1 = '-runtimedebug' ]] then EXTRAOPTIONS="$EXTRAOPTIONS -DCHECKTA" @@ -299,6 +304,11 @@ rm ./* export RAWRGCCFLAGS="-DTASK -DMULTICORE -DRAW" +if $RAWPATHFLAG +then # print path +RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWPATH" +fi + if $RAWDEBUGFLAG then #debug version RAWRGCCFLAGS="${RAWRGCCFLAGS} -DRAWDEBUG" -- 2.34.1