gcc flags changed

This commit is contained in:
Afonso Franco 2023-10-16 19:51:28 +01:00
parent 4c27b3c774
commit 763c84739f
Signed by: afonso
SSH key fingerprint: SHA256:JiuxZNdA5bRWXPMUJChI0AQ75yC+cXY4xM0IaVwEVys
3 changed files with 526 additions and 538 deletions

View file

@ -6,7 +6,7 @@ ts := $(shell /usr/bin/date "+%d-%m__%H_%M_%S")
.DEFAULT_GOAL = MD .DEFAULT_GOAL = MD
MD: $(SRC)/MD.cpp MD: $(SRC)/MD.cpp
$(CC) $(CFLAGS) $(SRC)MD.cpp -lm -O2 -ftree-vectorize -funroll-loops -pg -g -o ./out/MD $(CC) $(CFLAGS) $(SRC)MD.cpp -lm -march=native -mavx -O2 -ftree-vectorize -funroll-loops -pg -g -o ./out/MD
MDorig: $(SRC)/MD-original.cpp MDorig: $(SRC)/MD-original.cpp
$(CC) $(CFLAGS) $(SRC)MD-original.cpp -lm -O2 -pg -o ./out/MD-original $(CC) $(CFLAGS) $(SRC)MD-original.cpp -lm -O2 -pg -o ./out/MD-original

BIN
out/MD

Binary file not shown.

View file

@ -85,8 +85,7 @@ double MeanSquaredVelocity ();
// Compute total kinetic energy from particle mass and velocities // Compute total kinetic energy from particle mass and velocities
double Kinetic(); double Kinetic();
int int main() {
main () {
// variable delcarations // variable delcarations
int i; int i;
@ -246,7 +245,8 @@ main () {
// Files that we can write different quantities to // Files that we can write different quantities to
tfp = fopen(tfn, "w"); // The MD trajectory, coordinates of every tfp = fopen(tfn, "w"); // The MD trajectory, coordinates of every
// particle at each timestep // particle at each timestep
ofp = fopen (ofn, ofp = fopen(
ofn,
"w"); // Output of other quantities (T, P, gc, etc) at every timestep "w"); // Output of other quantities (T, P, gc, etc) at every timestep
afp = fopen(afn, "w"); // Average T, P, gc, etc from the simulation afp = fopen(afn, "w"); // Average T, P, gc, etc from the simulation
@ -286,7 +286,8 @@ main () {
Tavg = 0; Tavg = 0;
int tenp = floor(NumTime / 10); int tenp = floor(NumTime / 10);
fprintf (ofp, " time (s) T(t) (K) P(t) (Pa) " fprintf(ofp,
" time (s) T(t) (K) P(t) (Pa) "
"Kinetic En. (n.u.) Potential En. (n.u.) Total En. (n.u.)\n"); "Kinetic En. (n.u.) Potential En. (n.u.) Total En. (n.u.)\n");
printf(" PERCENTAGE OF CALCULATION COMPLETE:\n ["); printf(" PERCENTAGE OF CALCULATION COMPLETE:\n [");
for (i = 0; i < NumTime + 1; i++) { for (i = 0; i < NumTime + 1; i++) {
@ -344,8 +345,8 @@ main () {
Tavg += Temp; Tavg += Temp;
Pavg += Press; Pavg += Press;
fprintf (ofp, " %8.4e %20.12f %20.12f %20.12f %20.12f %20.12f \n", i * dt * timefac, fprintf(ofp, " %8.4e %20.12f %20.12f %20.12f %20.12f %20.12f \n",
Temp, Press, KE, PE, KE + PE); i * dt * timefac, Temp, Press, KE, PE, KE + PE);
} }
// Because we have calculated the instantaneous temperature and pressure, // Because we have calculated the instantaneous temperature and pressure,
@ -356,7 +357,8 @@ main () {
gc = NA * Pavg * (Vol * VolFac) / (N * Tavg); gc = NA * Pavg * (Vol * VolFac) / (N * Tavg);
fprintf(afp, " Total Time (s) T (K) P (Pa) PV/nT " fprintf(afp, " Total Time (s) T (K) P (Pa) PV/nT "
"(J/(mol K)) Z V (m^3) N\n"); "(J/(mol K)) Z V (m^3) N\n");
fprintf (afp, " -------------- ----------- --------------- " fprintf(afp,
" -------------- ----------- --------------- "
"-------------- --------------- ------------ -----------\n"); "-------------- --------------- ------------ -----------\n");
fprintf(afp, fprintf(afp,
" %8.4e %15.5f %15.5f %10.5f %10.5f %10.5e " " %8.4e %15.5f %15.5f %10.5f %10.5f %10.5e "
@ -379,7 +381,8 @@ main () {
printf("\n PERCENT ERROR of pV/nT AND GAS CONSTANT: %15.5f\n", printf("\n PERCENT ERROR of pV/nT AND GAS CONSTANT: %15.5f\n",
100 * fabs(gc - 8.3144598) / 8.3144598); 100 * fabs(gc - 8.3144598) / 8.3144598);
printf("\n THE COMPRESSIBILITY (unitless): %15.5f \n", Z); printf("\n THE COMPRESSIBILITY (unitless): %15.5f \n", Z);
printf ("\n TOTAL VOLUME (m^3): %10.5e \n", Vol * VolFac); printf("\n TOTAL VOLUME (m^3): %10.5e \n",
Vol * VolFac);
printf("\n NUMBER OF PARTICLES (unitless): %i \n", N); printf("\n NUMBER OF PARTICLES (unitless): %i \n", N);
fclose(tfp); fclose(tfp);
@ -389,8 +392,7 @@ main () {
return 0; return 0;
} }
void void initialize() {
initialize () {
int n, p, i, j, k; int n, p, i, j, k;
double pos; double pos;
@ -434,8 +436,7 @@ initialize () {
} }
// Function to calculate the averaged velocity squared // Function to calculate the averaged velocity squared
double double MeanSquaredVelocity() {
MeanSquaredVelocity () {
double vx2 = 0; double vx2 = 0;
double vy2 = 0; double vy2 = 0;
@ -455,8 +456,7 @@ MeanSquaredVelocity () {
} }
// Function to calculate the kinetic energy of the system // Function to calculate the kinetic energy of the system
double double Kinetic() { // Write Function here!
Kinetic () { // Write Function here!
double v2, kin; double v2, kin;
@ -475,12 +475,6 @@ Kinetic () { // Write Function here!
return kin; return kin;
} }
double
getF (double dist) {}
double
getLocalPot (double dist) {}
// void // void
// transposeMatrix (double mat[MAXPART][3], double matT[3][MAXPART]) { // transposeMatrix (double mat[MAXPART][3], double matT[3][MAXPART]) {
// for (int i = 0; i < 3; i++) { // for (int i = 0; i < 3; i++) {
@ -490,8 +484,7 @@ getLocalPot (double dist) {}
// } // }
// } // }
double double PotentialAndAcceleration() {
PotentialAndAcceleration () {
memset(a, 0, sizeof(a)); memset(a, 0, sizeof(a));
double Pot = 0.; double Pot = 0.;
// double rT[3][MAXPART]; // double rT[3][MAXPART];
@ -521,7 +514,7 @@ PotentialAndAcceleration () {
double distSqd = dist * dist; double distSqd = dist * dist;
double rSqd_inv4 = 1.0 / (distSqd * distSqd); double rSqd_inv4 = 1.0 / (distSqd * distSqd);
double rSqd_inv7 = rSqd_inv4 / (distSqd * dist); double rSqd_inv7 = rSqd_inv4 / (distSqd * dist);
double f = 24.0 * (2.0 * rSqd_inv7 - rSqd_inv4); double f = 48.0 * rSqd_inv7 - 24 * rSqd_inv4;
// from F = ma, where m = 1 in natural units! // from F = ma, where m = 1 in natural units!
for (int k = 0; k < 3; k++) { for (int k = 0; k < 3; k++) {
double tmp = posItoJ[k] * f; double tmp = posItoJ[k] * f;
@ -534,8 +527,7 @@ PotentialAndAcceleration () {
} }
// Function to calculate the potential energy of the system // Function to calculate the potential energy of the system
double double Potential() {
Potential () {
double quot, r2, rnorm, term1, term2, Pot; double quot, r2, rnorm, term1, term2, Pot;
int i, j; int i, j;
@ -564,8 +556,7 @@ Potential () {
// Uses the derivative of the Lennard-Jones potential to calculate // Uses the derivative of the Lennard-Jones potential to calculate
// the forces on each atom. Then uses a = F/m to calculate the // the forces on each atom. Then uses a = F/m to calculate the
// accelleration of each atom. // accelleration of each atom.
void void computeAccelerations() {
computeAccelerations () {
int i, j, k; int i, j, k;
double f, rSqd, tmp = 0.; double f, rSqd, tmp = 0.;
double rij[3]; // position of i relative to j double rij[3]; // position of i relative to j
@ -600,8 +591,7 @@ computeAccelerations () {
} }
// returns sum of dv/dt*m/A (aka Pressure) from elastic collisions with walls // returns sum of dv/dt*m/A (aka Pressure) from elastic collisions with walls
double double VelocityVerlet(double dt, int iter, double *PE, FILE *fp) {
VelocityVerlet (double dt, int iter, double *PE, FILE *fp) {
int i, j, k; int i, j, k;
double psum = 0.; double psum = 0.;
@ -658,8 +648,7 @@ VelocityVerlet (double dt, int iter, double *PE, FILE *fp) {
return psum / (6 * L * L); return psum / (6 * L * L);
} }
void void initializeVelocities() {
initializeVelocities () {
int i, j; int i, j;
@ -718,8 +707,7 @@ initializeVelocities () {
} }
// Numerical recipes Gaussian distribution number generator // Numerical recipes Gaussian distribution number generator
double double gaussdist() {
gaussdist () {
static bool available = false; static bool available = false;
static double gset; static double gset;
double fac, rsq, v1, v2; double fac, rsq, v1, v2;