| 5 | 
  | 
#include "mpiSimulation.hpp" | 
| 6 | 
  | 
#include "simError.h" | 
| 7 | 
  | 
 | 
| 8 | 
+ | 
mpiSimulation* mpiSim; | 
| 9 | 
  | 
 | 
| 9 | 
– | 
 | 
| 10 | 
  | 
mpiSimulation::mpiSimulation(SimInfo* the_entryPlug) | 
| 11 | 
  | 
{ | 
| 12 | 
  | 
  entryPlug = the_entryPlug; | 
| 13 | 
+ | 
  mpiPlug = new MpiSimData; | 
| 14 | 
  | 
   | 
| 15 | 
< | 
  numberProcessors = MPI::COMM_WORLD.Get_size(); | 
| 16 | 
< | 
  myNode = worldRank; | 
| 15 | 
> | 
  mpiPlug->numberProcessors = MPI::COMM_WORLD.Get_size(); | 
| 16 | 
> | 
  mpiPlug->myNode = worldRank; | 
| 17 | 
  | 
   | 
| 18 | 
< | 
  // let the simulation know were there. | 
| 18 | 
< | 
  entryPlug->mpiSim = this; | 
| 18 | 
> | 
 | 
| 19 | 
  | 
} | 
| 20 | 
  | 
 | 
| 21 | 
  | 
 | 
| 22 | 
  | 
mpiSimulation::~mpiSimulation(){ | 
| 23 | 
  | 
   | 
| 24 | 
< | 
  // empty for now | 
| 24 | 
> | 
  delete mpiPlug; | 
| 25 | 
> | 
  // perhaps we should let fortran know the party is over. | 
| 26 | 
  | 
   | 
| 27 | 
  | 
} | 
| 28 | 
  | 
 | 
| 50 | 
  | 
  compStamps = entryPlug->compStamps; | 
| 51 | 
  | 
  componentsNmol = entryPlug->componentsNmol; | 
| 52 | 
  | 
 | 
| 53 | 
< | 
  simTotAtoms = entryPlug->n_atoms; | 
| 54 | 
< | 
  simTotBonds = entryPlug->n_bonds; | 
| 55 | 
< | 
  simTotBends = entryPlug->n_bends; | 
| 56 | 
< | 
  simTotTorsions = entryPlug->n_torsions; | 
| 57 | 
< | 
  simTotSRI = entryPlug->n_SRI; | 
| 58 | 
< | 
  simTotNmol = entryPlug->n_nmol; | 
| 53 | 
> | 
  mpiPlug->nAtomsGlobal = entryPlug->n_atoms; | 
| 54 | 
> | 
  mpiPlug->nBondsGlobal = entryPlug->n_bonds; | 
| 55 | 
> | 
  mpiPlug->nBendsGlobal = entryPlug->n_bends; | 
| 56 | 
> | 
  mpiPlug->nTorsionsGlobal = entryPlug->n_torsions; | 
| 57 | 
> | 
  mpiPlug->nSRIGlobal = entryPlug->n_SRI; | 
| 58 | 
> | 
  mpiPlug->nMolGlobal = entryPlug->n_nmol; | 
| 59 | 
  | 
 | 
| 60 | 
  | 
  numerator = (double) entryPlug->n_atoms; | 
| 61 | 
< | 
  denominator = (double) numberProcessors; | 
| 61 | 
> | 
  denominator = (double) mpiPlug->numberProcessors; | 
| 62 | 
  | 
  precast = numerator / denominator; | 
| 63 | 
  | 
  nTarget = (int)( precast + 0.5 ); | 
| 64 | 
  | 
   | 
| 66 | 
  | 
  atomIndex = 0; | 
| 67 | 
  | 
  compIndex = 0; | 
| 68 | 
  | 
  compStart = 0; | 
| 69 | 
< | 
  for( i=0; i<(numberProcessors-1); i++){ | 
| 69 | 
> | 
  for( i=0; i<(mpiPlug->numberProcessors-1); i++){ | 
| 70 | 
  | 
     | 
| 71 | 
  | 
    done = 0; | 
| 72 | 
  | 
    nLocal = 0; | 
| 73 | 
  | 
    molLocal = 0; | 
| 74 | 
  | 
 | 
| 75 | 
< | 
    if( i == myNode ){ | 
| 76 | 
< | 
      myMolStart = molIndex; | 
| 77 | 
< | 
      myAtomStart = atomIndex; | 
| 75 | 
> | 
    if( i == mpiPlug->myNode ){ | 
| 76 | 
> | 
      mpiPlug->myMolStart = molIndex; | 
| 77 | 
> | 
      mpiPlug->myAtomStart = atomIndex; | 
| 78 | 
  | 
    } | 
| 79 | 
  | 
     | 
| 80 | 
  | 
    while( !done ){ | 
| 109 | 
  | 
      } | 
| 110 | 
  | 
    } | 
| 111 | 
  | 
     | 
| 112 | 
< | 
    if( i == myNode ){ | 
| 113 | 
< | 
      myMolEnd = (molIndex - 1); | 
| 114 | 
< | 
      myAtomEnd = (atomIndex - 1); | 
| 115 | 
< | 
      myNlocal = nLocal; | 
| 116 | 
< | 
      myMol = molLocal; | 
| 112 | 
> | 
    if( i == mpiPlug->myNode ){ | 
| 113 | 
> | 
      mpiPlug->myMolEnd = (molIndex - 1); | 
| 114 | 
> | 
      mpiPlug->myAtomEnd = (atomIndex - 1); | 
| 115 | 
> | 
      mpiPlug->myNlocal = nLocal; | 
| 116 | 
> | 
      mpiPlug->myMol = molLocal; | 
| 117 | 
  | 
    } | 
| 118 | 
  | 
     | 
| 119 | 
  | 
    numerator = (double)( entryPlug->n_atoms - atomIndex ); | 
| 120 | 
< | 
    denominator = (double)( numberProcessors - (i+1) ); | 
| 120 | 
> | 
    denominator = (double)( mpiPlug->numberProcessors - (i+1) ); | 
| 121 | 
  | 
    precast = numerator / denominator; | 
| 122 | 
  | 
    nTarget = (int)( precast + 0.5 ); | 
| 123 | 
  | 
  } | 
| 124 | 
  | 
   | 
| 125 | 
< | 
  if( myNode == numberProcessors-1 ){ | 
| 126 | 
< | 
      myMolStart = molIndex; | 
| 127 | 
< | 
      myAtomStart = atomIndex; | 
| 125 | 
> | 
  if( mpiPlug->myNode == mpiPlug->numberProcessors-1 ){ | 
| 126 | 
> | 
      mpiPlug->myMolStart = molIndex; | 
| 127 | 
> | 
      mpiPlug->myAtomStart = atomIndex; | 
| 128 | 
  | 
 | 
| 129 | 
  | 
      nLocal = 0; | 
| 130 | 
  | 
      molLocal = 0; | 
| 142 | 
  | 
        molLocal++; | 
| 143 | 
  | 
      } | 
| 144 | 
  | 
       | 
| 145 | 
< | 
      myMolEnd = (molIndex - 1); | 
| 146 | 
< | 
      myAtomEnd = (atomIndex - 1); | 
| 147 | 
< | 
      myNlocal = nLocal;   | 
| 148 | 
< | 
      myMol = molLocal; | 
| 145 | 
> | 
      mpiPlug->myMolEnd = (molIndex - 1); | 
| 146 | 
> | 
      mpiPlug->myAtomEnd = (atomIndex - 1); | 
| 147 | 
> | 
      mpiPlug->myNlocal = nLocal;   | 
| 148 | 
> | 
      mpiPlug->myMol = molLocal; | 
| 149 | 
  | 
  } | 
| 150 | 
  | 
 | 
| 151 | 
  | 
 | 
| 152 | 
< | 
  MPI_Allreduce( &Nlocal, &testSum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); | 
| 152 | 
> | 
  MPI_Allreduce( &nLocal, &testSum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); | 
| 153 | 
  | 
   | 
| 154 | 
< | 
  if( myNode == 0 ){ | 
| 154 | 
> | 
  if( mpiPlug->myNode == 0 ){ | 
| 155 | 
  | 
    if( testSum != entryPlug->n_atoms ){ | 
| 156 | 
  | 
      sprintf( painCave.errMsg, | 
| 157 | 
  | 
               "The summ of all nLocals, %d, did not equal the total number of atoms, %d.\n", |