[gmx-developers] calc_avcsix is N**2!

David van der Spoel spoel at xray.bmc.uu.se
Wed Jul 13 10:55:53 CEST 2005


On Wed, 2005-07-13 at 01:10 -0700, Vishal Vaidyanathan wrote:
> Hi,
>   I noticed that calc_avcsix does an unnecessary double loop over natoms.
> This usually results in a small initialization delay before simulation
> begins, but for large systems (~300k atoms), this is very significant
> (several hours).
thanks, this was already solved in CVS...

> 
>   It's relatively trivial to speed it up. The replacement function is
> below in case anybody is interested.
> 
> Thanks,
> Vishal
> 
> static double calc_avcsix_fast( FILE *log, real *nbfp, int ntypes,
>             int natoms, int type[],  bool bBHAM ) {
> 
>     int * typecounts;
>     int i, j;
>     float c6,c6sum, c6av;
> 
>     typecounts = ( int * ) calloc ( ntypes, sizeof( int ) );
> 
> 
>     for ( i = 0; i < natoms; i++ ){
>         typecounts[ type[i] ]++;
>     }
> 
>     //Now we have to do a double loop over ntypes
>     c6sum = 0;
>     for ( i = 0; i < ntypes; i++ ){
>         for ( j = 0; j < ntypes; j++ ) {
>             if ( bBHAM )
>                 c6 = BHAMC( nbfp, ntypes, i, j );
>             else
>                 c6 = C6( nbfp, ntypes, i, j );
> 
>             c6sum += typecounts[ i ] * typecounts[ j ] * c6;
>         }
>     }
> 
>     c6av = c6sum / ( natoms * natoms );
>     free( typecounts );
>     return c6av;
> }
> 
> 
> _______________________________________________
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://www.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use the 
> www interface or send it to gmx-developers-request at gromacs.org.
-- 
David.
________________________________________________________________________
David van der Spoel, PhD, Assoc. Prof., Molecular Biophysics group,
Dept. of Cell and Molecular Biology, Uppsala University.
Husargatan 3, Box 596,          75124 Uppsala, Sweden
phone:  46 18 471 4205          fax: 46 18 511 755
spoel at xray.bmc.uu.se    spoel at gromacs.org   http://xray.bmc.uu.se/~spoel
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++





More information about the gromacs.org_gmx-developers mailing list