Пример #1
0
void CpuBondForce::threadComputeForce(ThreadPool& threads, int threadIndex, vector<Vec3>& atomCoordinates, double** parameters, vector<Vec3>& forces, 
            double* totalEnergy, ReferenceBondIxn& referenceBondIxn) {
    vector<int>& bonds = threadBonds[threadIndex];
    int numBonds = bonds.size();
    for (int i = 0; i < numBonds; i++) {
        int bond = bonds[i];
        referenceBondIxn.calculateBondIxn(bondAtoms[bond], atomCoordinates, parameters[bond], forces, totalEnergy, NULL);
    }
}
Пример #2
0
void CpuBondForce::calculateForce(vector<RealVec>& atomCoordinates, RealOpenMM** parameters, vector<RealVec>& forces, 
        RealOpenMM* totalEnergy, ReferenceBondIxn& referenceBondIxn) {
    // Have the worker threads compute their forces.
    
    vector<RealOpenMM> threadEnergy(threads->getNumThreads(), 0);
    ComputeForceTask task(*this, atomCoordinates, parameters, forces, threadEnergy, totalEnergy, referenceBondIxn);
    threads->execute(task);
    threads->waitForThreads();
    
    // Compute any "extra" bonds.
    
    for (int i = 0; i < extraBonds.size(); i++) {
        int bond = extraBonds[i];
        referenceBondIxn.calculateBondIxn(bondAtoms[bond], atomCoordinates, parameters[bond], forces, totalEnergy, NULL);
    }

    // Compute the total energy.
    
    if (totalEnergy != NULL)
        for (int i = 0; i < threads->getNumThreads(); i++)
            *totalEnergy += threadEnergy[i];
}
Пример #3
0
void CpuBondForce::calculateForce(vector<Vec3>& atomCoordinates, double** parameters, vector<Vec3>& forces, 
        double* totalEnergy, ReferenceBondIxn& referenceBondIxn) {
    // Have the worker threads compute their forces.
    
    vector<double> threadEnergy(threads->getNumThreads(), 0);
    threads->execute([&] (ThreadPool& threads, int threadIndex) {
        double* energy = (totalEnergy == NULL ? NULL : &threadEnergy[threadIndex]);
        threadComputeForce(threads, threadIndex, atomCoordinates, parameters, forces, energy, referenceBondIxn);
    });
    threads->waitForThreads();
    
    // Compute any "extra" bonds.
    
    for (int i = 0; i < extraBonds.size(); i++) {
        int bond = extraBonds[i];
        referenceBondIxn.calculateBondIxn(bondAtoms[bond], atomCoordinates, parameters[bond], forces, totalEnergy, NULL);
    }

    // Compute the total energy.
    
    if (totalEnergy != NULL)
        for (int i = 0; i < threads->getNumThreads(); i++)
            *totalEnergy += threadEnergy[i];
}