Skip to content

Commit

Permalink
Added programs
Browse files Browse the repository at this point in the history
  • Loading branch information
erikasan committed Oct 19, 2019
1 parent 086ea13 commit 4125574
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 25 deletions.
4 changes: 4 additions & 0 deletions compiling_error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/home/erik/Documents/cpp/test.cpp: In function ‘double g(double (*)())’:
/home/erik/Documents/cpp/test.cpp:15:11: error: invalid operands of types ‘int’ and ‘double (*)()’ to binary ‘operator*’
return 2*f;
~^~
11 changes: 11 additions & 0 deletions function_as_argument.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
double Gaussian_Legendre(double a,double b,int n, function<double(double)> f){
double *x = new double[n];
double *w = new double[n];

gauleg(a,b,x,w,n);
double integral = 0;
for (int i=0; i<n;i++){
integral += w[i]*f(x[i]);
}
return integral;
}
46 changes: 21 additions & 25 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <array>
#include <cstdlib>
#include <cstdio>
using namespace std;


int func(int, int);

int main()
{

int a = 1, b = 2;
cout << func(a, b);
return 0;
}

int func(int a, int b)
{
return a + b;
}
#include <iostream>

using namespace std;

double g(double f());
double f(double x);

int main()
{
return 0;
}

double g(double f())
{
return 2*f;
}

double f(double x)
{
return 2*x;
}
5 changes: 5 additions & 0 deletions test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

double* returnarray(double* b)
{
return b;
}
19 changes: 19 additions & 0 deletions test2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <cmath>

using namespace std;

double func(double x);

int main()
{

return 0;
}

double func(double x)
{
double value;
value = 4/(1.+x*x);
return value;
} // end of function to evaluate
24 changes: 24 additions & 0 deletions testMPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <omp.h>
#define CHUNKSIZE 100
#define N 10

using namespace std;

int main (int argc, char *argv[])
{
int i, chunk;
float a[N], b[N], c[N];
for (i=0; i < N; i++) a[i] = b[i] = i * 1.0;
chunk = CHUNKSIZE;
#pragma omp parallel shared(a,b,c,chunk) private(i)
{
#pragma omp for schedule(dynamic,chunk)
for (i=0; i < N; i++) c[i] = a[i] + b[i];
} /* end of parallel region */

for (int j = 0; j != N; ++j) {
cout << c[i] << endl;
}

}
12 changes: 12 additions & 0 deletions tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <tuple>

using namespace std;

int main()
{
double a = 0, b = 2, c = 3, d = 5;
auto args = make_tuple (a, b, c ,d);
cout << get<1>(args);
return 0;
}

0 comments on commit 4125574

Please sign in to comment.