Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cs.yale.edu!doctor.chem.yale.edu From: jim@doctor.chem.yale.edu (James F. Blake) Newsgroups: comp.lang.c Subject: SUMMARY: Memory allocation / data access Message-ID: <29599@cs.yale.edu> Date: 20 Mar 91 01:40:19 GMT Sender: news@cs.yale.edu Distribution: na Organization: Laboratory for Computational Chemistry, Yale University Lines: 39 Nntp-Posting-Host: master.chem.yale.edu Earlier I inquired about allocating memory and the efficiency of various addressing schemes. I would like to thank the following individuals for their helpful comments: Rich Salz (rsalz@bbn.com) James Davies (jrbd@craycos.com) David Wald (wald@theory.lcs.mit.edu) Harry Protoolis (harry@matilda.uk.sun.com) Michael W. Balk (mwb@ulysses.att.com) The general consensus is that: for (k = 0; k < natoms; k++) { for (l = 0; l < natoms; l++) { xdis = fabs (monomer[i].atom[k].x - monomer[j].atom[l].x); ydis = fabs (monomer[i].atom[k].y - monomer[j].atom[l].y); zdis = fabs (monomer[i].atom[k].z - monomer[j].atom[l].z); should be accessed as: atom_a = monomer[i].atom; for (k = 0; k < natoms; k++, atom_a++) { for (atom_b = monomer[j].atom, l = 0; l < natoms; l++, atom_b++) { xdis = fabs (atom_a->x - atom_b->x); ydis = fabs (atom_a->y - atom_b->y); zdis = fabs (atom_a->z - atom_b->z); This give ca. 7-10% speed-up on our SGI Iris 4D's. Also, Rich Salz provided the following useful macro: #define NEW(T, c) ((T *)calloc((unsigned int) c, sizeof (T))) if ((monomer = NEW(solvent, nmol)) == NULL) ... Thanks once again for the advice. Jim