title: Fast indexing of symmetrical matrix
body: <p>In a large code written in Fortran08 for calculating thermodynamic equilibria and phase diagrams I use many symmetric matrices which I store as 1D arrays and index using a small function</p>
  
  <pre><code>integer function ixsym(i,j)
     if(i.gt.j) then
        ixsym=j+i*(i-1)/2
     else
        ixsym=i+j*(j-1)/2
     endif
     return
  end
  </code></pre>
  
  <p>This works perfectly but after improving the speed of various other parts of the code this routine now takes 15-20% of the calculation time (it is used very often).  I assume there are various ways of speeding this up but I do not know C or other way to replace this function so I am looking for help.  I use gfortran but the replacement has to be portable.</p>
  
  <p>Bo Sundman</p>