title: Continuous Simulation - Performance tuning - GPU/CPU
body: <p>I constructed a continuous simulation model (state based) for the mining industry.  Equipment is tracked for engineering and production purposes, where equipment states are updated when events happen, such as breakdowns, production events etc.  Many statistical distributions are used.  For illustration purposes, see below code to get an idea of how the simulation works.</p>
  
  <p>I'm trying to optimize performance.  Basically thousands of 'cases' need to be run.  I can run x amount of cases in parallel, based on the amount of physical threads available to me.  Thus the CPU works at 100%.</p>
  
  <p>A 1000 cases can take more than a day to run.  </p>
  
  <p>From the structure of the application, is there an opportunity to introduce GPU calculations?  I have never programmed with a GPU and would like to know if there is opportunity for me to include the GPU in my calculations somehow.  Any other advice will also be appreciated.</p>
  
  <pre><code>public static void RunAll()
  {
     //This list contains thousands cases
     List&lt;SimCase&gt; simCases = ImportCases()
  
     //List which contains simulation results
     ConcurrentBag&lt;Results&gt; resultsList = new ConcurrentBag&lt;Results&gt;();
  
     //Runs cases in parallel (consumes all threads)
     Parallel.ForEach(simCases, simCase =&gt;
     {
        var results = RunSimulation(simCase);
        resultsList.Add(results);
     });
  
    //Interpret results and build report
  }
  
  public static Results RunSimulation(SimCase simCase)
  {
     Results results = new Results();
  
     DateTime currentDate = new DateTime(2018,1,1);
     DateTime finalDate= new DateTime(2018,12,31);
  
     while (currentDate &lt; finalDate)
     {
        //Many if statements
  
        //Many object updates
  
        //Many functions calls to libraries for statistical calcs
  
        //Updates simulation time
        currentDate = currentDate.addSeconds(1);
     }
  
     return(results);
  }
  </code></pre>