View Javadoc
1   // ******************************************************************************
2   //
3   // Title:       Force Field X.
4   // Description: Force Field X - Software for Molecular Biophysics.
5   // Copyright:   Copyright (c) Michael J. Schnieders 2001-2024.
6   //
7   // This file is part of Force Field X.
8   //
9   // Force Field X is free software; you can redistribute it and/or modify it
10  // under the terms of the GNU General Public License version 3 as published by
11  // the Free Software Foundation.
12  //
13  // Force Field X is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  // details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA 02111-1307 USA
21  //
22  // Linking this library statically or dynamically with other modules is making a
23  // combined work based on this library. Thus, the terms and conditions of the
24  // GNU General Public License cover the whole combination.
25  //
26  // As a special exception, the copyright holders of this library give you
27  // permission to link this library with independent modules to produce an
28  // executable, regardless of the license terms of these independent modules, and
29  // to copy and distribute the resulting executable under terms of your choice,
30  // provided that you also meet, for each linked independent module, the terms
31  // and conditions of the license of that module. An independent module is a
32  // module which is not derived from or based on this library. If you modify this
33  // library, you may extend this exception to your version of the library, but
34  // you are not obligated to do so. If you do not wish to do so, delete this
35  // exception statement from your version.
36  //
37  // ******************************************************************************
38  package ffx.potential.nonbonded.pme;
39  
40  import static ffx.utilities.Constants.NS2SEC;
41  import static java.lang.String.format;
42  import static org.apache.commons.math3.util.FastMath.max;
43  import static org.apache.commons.math3.util.FastMath.min;
44  
45  import java.util.logging.Logger;
46  
47  public class PMETimings {
48  
49    private static final Logger logger = Logger.getLogger(PMETimings.class.getName());
50  
51    public final long[] realSpacePermTime;
52    public final long[] realSpaceEnergyTime;
53    public final long[] realSpaceSCFTime;
54    /** Timing variables. */
55    private final int numThreads;
56  
57    public long realSpacePermTotal, realSpaceEnergyTotal, realSpaceSCFTotal;
58    public long bornRadiiTotal, gkEnergyTotal;
59  
60    public PMETimings(int numThreads) {
61      this.numThreads = numThreads;
62      realSpacePermTime = new long[numThreads];
63      realSpaceEnergyTime = new long[numThreads];
64      realSpaceSCFTime = new long[numThreads];
65    }
66  
67    public void init() {
68      for (int i = 0; i < numThreads; i++) {
69        realSpacePermTime[i] = 0;
70        realSpaceEnergyTime[i] = 0;
71        realSpaceSCFTime[i] = 0;
72      }
73      realSpacePermTotal = 0;
74      realSpaceEnergyTotal = 0;
75      realSpaceSCFTotal = 0;
76      bornRadiiTotal = 0;
77      gkEnergyTotal = 0;
78    }
79  
80    public void printRealSpaceTimings(int maxThreads, RealSpaceEnergyRegion realSpaceEnergyRegion) {
81      double total = (realSpacePermTotal + realSpaceSCFTotal + realSpaceEnergyTotal) * NS2SEC;
82      logger.info(format("\n Real Space: %7.4f (sec)", total));
83      logger.info("           Electric Field");
84      logger.info(" Thread    Direct  SCF     Energy     Counts");
85      long minPerm = Long.MAX_VALUE;
86      long maxPerm = 0;
87      long minSCF = Long.MAX_VALUE;
88      long maxSCF = 0;
89      long minEnergy = Long.MAX_VALUE;
90      long maxEnergy = 0;
91      int minCount = Integer.MAX_VALUE;
92      int maxCount = Integer.MIN_VALUE;
93  
94      for (int i = 0; i < maxThreads; i++) {
95        int count = realSpaceEnergyRegion.getCount(i);
96        logger.info(format("    %3d   %7.4f %7.4f %7.4f %10d",
97            i, realSpacePermTime[i] * NS2SEC, realSpaceSCFTime[i] * NS2SEC,
98            realSpaceEnergyTime[i] * NS2SEC, count));
99        minPerm = min(realSpacePermTime[i], minPerm);
100       maxPerm = max(realSpacePermTime[i], maxPerm);
101       minSCF = min(realSpaceSCFTime[i], minSCF);
102       maxSCF = max(realSpaceSCFTime[i], maxSCF);
103       minEnergy = min(realSpaceEnergyTime[i], minEnergy);
104       maxEnergy = max(realSpaceEnergyTime[i], maxEnergy);
105       minCount = min(count, minCount);
106       maxCount = max(count, maxCount);
107     }
108     logger.info(format(" Min      %7.4f %7.4f %7.4f %10d",
109         minPerm * NS2SEC, minSCF * NS2SEC, minEnergy * NS2SEC, minCount));
110     logger.info(format(" Max      %7.4f %7.4f %7.4f %10d",
111         maxPerm * NS2SEC, maxSCF * NS2SEC, maxEnergy * NS2SEC, maxCount));
112     logger.info(format(" Delta    %7.4f %7.4f %7.4f %10d",
113         (maxPerm - minPerm) * NS2SEC,
114         (maxSCF - minSCF) * NS2SEC,
115         (maxEnergy - minEnergy) * NS2SEC,
116         (maxCount - minCount)));
117     logger.info(format(" Actual   %7.4f %7.4f %7.4f %10d",
118         realSpacePermTotal * NS2SEC,
119         realSpaceSCFTotal * NS2SEC,
120         realSpaceEnergyTotal * NS2SEC,
121         realSpaceEnergyRegion.getInteractions()));
122   }
123 }