Changeset 6703


Ignore:
Timestamp:
Apr 2, 2009, 4:09:50 PM (16 years ago)
Author:
ole
Message:

Nariman's optimisations of compute_fluxes:

Using memset to initialise three arrays and precomputing denominators.
Simple profile improved compute_fluxes from 4.776s to 4.260s and the overall runtime of evolve from 11.513s to 10.985s. This is an overall speedup exceeding 5%.
Yeeehaha

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/shallow_water_ext.c

    r5967 r6703  
    1818#include "math.h"
    1919#include <stdio.h>
     20#include <string.h>
    2021
    2122// Shared code snippets
     
    2627
    2728// Computational function for rotation
     29// FIXME: Perhaps inline this and profile
    2830int _rotate(double *q, double n1, double n2) {
    2931  /*Rotate the momentum component q (q[1], q[2])
     
    164166// This is used by flux functions
    165167// Input parameters uh and h may be modified by this function.
     168
     169// FIXME: Perhaps inline this and profile
    166170double _compute_speed(double *uh,
    167171                      double *h,
     
    210214  double v_left, v_right; 
    211215  double s_min, s_max, soundspeed_left, soundspeed_right;
    212   double denom, z;
     216  double denom, inverse_denominator, z;
    213217
    214218  // Workspace (allocate once, use many)
     
    229233  _rotate(q_right_rotated, n1, n2);
    230234
    231   z = (z_left+z_right)/2; // Average elevation values.
    232                           // Even though this will nominally allow for discontinuities
    233                           // in the elevation data, there is currently no numerical
    234                           // support for this so results may be strange near jumps in the bed.
     235  z = 0.5*(z_left+z_right); // Average elevation values.
     236                            // Even though this will nominally allow for discontinuities
     237                            // in the elevation data, there is currently no numerical
     238                            // support for this so results may be strange near jumps in the bed.
    235239
    236240  // Compute speeds in x-direction
     
    280284    *max_speed = 0.0;
    281285  } else {
     286    inverse_denominator = 1.0/denom;
    282287    for (i=0; i<3; i++) {
    283288      edgeflux[i] = s_max*flux_left[i] - s_min*flux_right[i];
    284289      edgeflux[i] += s_max*s_min*(q_right_rotated[i]-q_left_rotated[i]);
    285       edgeflux[i] /= denom;
     290      edgeflux[i] *= inverse_denominator;
    286291    }
    287292
     
    16521657  // Start computation
    16531658  call++; // Flag 'id' of flux calculation for this timestep
    1654  
     1659
     1660   
    16551661  // Set explicit_update to zero for all conserved_quantities.
    16561662  // This assumes compute_fluxes called before forcing terms
    1657   for (k=0; k<number_of_elements; k++) {
    1658     stage_explicit_update[k]=0.0;
    1659     xmom_explicit_update[k]=0.0;
    1660     ymom_explicit_update[k]=0.0; 
    1661   }
     1663  memset((char*) stage_explicit_update, 0, number_of_elements*sizeof(double));
     1664  memset((char*) xmom_explicit_update, 0, number_of_elements*sizeof(double));
     1665  memset((char*) ymom_explicit_update, 0, number_of_elements*sizeof(double));   
     1666 
    16621667
    16631668  // For all triangles
     
    16661671    // Loop through neighbours and compute edge flux for each 
    16671672    for (i=0; i<3; i++) {
    1668       ki = k*3+i; // Linear index (triangle k, edge i)
     1673      ki = k*3+i; // Linear index to edge i of triangle k
    16691674     
    16701675      if (already_computed_flux[ki] == call)
     
    16721677        continue;
    16731678       
    1674        
     1679      // Get left hand side values from triangle k, edge i
    16751680      ql[0] = stage_edge_values[ki];
    16761681      ql[1] = xmom_edge_values[ki];
     
    16781683      zl = bed_edge_values[ki];
    16791684
    1680       // Quantities at neighbour on nearest face
     1685      // Get right hand side values either from neighbouring triangle
     1686      // or from boundary array (Quantities at neighbour on nearest face).
    16811687      n = neighbours[ki];
    16821688      if (n < 0) {
     
    16891695        zr = zl; // Extend bed elevation to boundary
    16901696      } else {
    1691         // Neighbour is a real element
     1697        // Neighbour is a real triangle
    16921698        m = neighbour_edges[ki];
    16931699        nm = n*3+m; // Linear index (triangle n, edge m)
     
    16991705      }
    17001706     
     1707      // Now we have values for this edge - both from left and right side.
    17011708     
    17021709      if (optimise_dry_cells) {     
Note: See TracChangeset for help on using the changeset viewer.