EDIT: OK sorry, I'll try and be clearer.(adsbygoogle = window.adsbygoogle || []).push({});

I'm trying to make this program finish more quickly. For this program to give a good result I need the for loop to run at least 10^9 times. Which takes hours...

Any way to make this program with n=10^9 finish more quickly?

Code (Text):

# include <cstdlib>

# include <iostream>

# include <iomanip>

# include <stdio.h>

# include <math.h>

# include <cmath>

# include <string>

# include <fstream>

# include <process.h>

#include <limits>

using namespace std;

# include "sobol.H"

const int dim=7;

double H=0.000001;

const double E=exp(1.0);

const double c=299792458.0;

const double Pi=3.14159265;

const double lp=0.0000002;

const double hbar=1.05457148*pow(10.0,-34);

const double VLargeL=20.0*H/lp;

double S2Min=0;

double x2Min=0; double xd2Min=-VLargeL;

double y2Min=0; double yd2Min=-VLargeL;

double z2Min=-VLargeL; double zd2Min=H/lp;

double S2Max=10.0;

double x2Max=VLargeL; double xd2Max=VLargeL;

double y2Max=VLargeL; double yd2Max=VLargeL;

double z2Max=0; double zd2Max=VLargeL;

double S2Range=(S2Max - S2Min); double x2Range=x2Max-x2Min; double xd2Range=xd2Max-xd2Min;

double y2Range=y2Max-y2Min; double yd2Range=yd2Max-yd2Min; double z2Range=z2Max-z2Min;

double zd2Range=zd2Max-zd2Min;

double Integrand1(double S2, double x2, double xd2, double y2, double yd2,

double z2, double zd2)

{

return (1 + 4*Pi*S2*(sqrt(pow(x2 - xd2,2) + pow(y2 - yd2,2) + pow(z2 - zd2,2)) +

Pi*S2*(pow(x2 - xd2,2) + pow(y2 - yd2,2) + pow(z2 - zd2,2))))/

(pow(E,4*Pi*S2*sqrt(pow(x2 - xd2,2) + pow(y2 - yd2,2) + pow(z2 - zd2,2)))*

pow(2 + pow(S2,2),2)*pow(pow(x2 - xd2,2) + pow(y2 - yd2,2) +

pow(z2 - zd2,2),3));

}

//****************************************************************************80

int main ( void )

{

cout << "Define n by entering an integer please:\n";

long long int n;

cin >> n;

cout << "n = " << n <<"\n";

cout << "\n";

double r[dim];

long long int seed=0;

long double Result1=0;

long long int PercentagesShown=0;

long double OnePercent=n/100.0;

for(long long int i=0;i<n;i++)

{

i8_sobol(dim,&seed,r);

Result1+=Integrand1(r[0] * S2Range,x2Min + (r[1]*x2Range),xd2Min + (r[2]*xd2Range),

y2Min + (r[3]*y2Range), yd2Min + (r[4]*yd2Range),z2Min + (r[5] * z2Range),

zd2Min + (r[6] * zd2Range));

if(i>2000000*(PercentagesShown+1))

{

system("cls");

cout << i << " loops completed";

PercentagesShown++;

}

}

Result1=(-(c*hbar)/(4.*lp*pow(Pi,2)))*2*S2Range*x2Range*xd2Range*y2Range*yd2Range*z2Range*zd2Range*Result1/(n*pow(2*VLargeL,2));

system("cls");

cout << "Result = " << Result1 << "\n";

std::ofstream OutputFile("SQR2ndOrderFlatResults.txt", std::ios_base::out | std::ios_base::app);

OutputFile << "\n\n";

OutputFile << "2nd Order Flat\n";

OutputFile << "Very Large Length= " << VLargeL;

OutputFile << ", N = " << n;

OutputFile << ", H = " << H;

OutputFile << ", S2Max = " << S2Max;

OutputFile << "\nIntegration Result = " << Result1 << "\n";

OutputFile.close();

cout <<"\n";

cout << "Exit program? (y/n)\n";

std::string BoolStr;

cin >> BoolStr;

while(BoolStr!="y")

{

cout <<"\n";

cout << "User chose not to exit program.\n";

cout << "Exit program? (y/n)\n";

cin >> BoolStr;

}

}

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Faster please?

Loading...

Similar Threads for Faster please | Date |
---|---|

Fortran I need help in Fortran please -- Bairstow's method & Newton-Raphson | Nov 26, 2016 |

How to get faster at coding in a short amount of time? | Jun 10, 2016 |

Python How much faster is Python than Mathematica? | May 30, 2015 |

Which is faster? reading from memory or arithmetic? | Apr 10, 2015 |

Drawing a line - faster | Apr 30, 2014 |

**Physics Forums - The Fusion of Science and Community**