-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added td2 and td4 (not done) and finishing docs
- Loading branch information
Showing
25 changed files
with
645 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mkdir -p ./dist/$(dirname ${1%".c"}) | ||
|
||
mpicc -w ./scripts/$1 -fopenmp -lm -o ./dist/${1%".c"} | ||
mpirun -np $2 ./dist/${1%".c"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
#define MAX 50 | ||
#define NUMTHREAD 4 | ||
|
||
int main(int argc, char* argv[]){ | ||
|
||
float step, x, sum, pi; | ||
int i, steps; | ||
steps = 200.0; | ||
|
||
step = 1.0/(float)steps; | ||
|
||
float* resultArray = malloc(sizeof(float)*NUMTHREAD); | ||
|
||
// printf("\nwe have %d threads", omp_get_thread_num()); | ||
// omp_set_num_threads(NUMTHREAD); | ||
// int t_num = omp_get_thread_num(); | ||
// int start = (steps/NUMTHREAD)*t_num; | ||
// int end = (steps/NUMTHREAD) * (t_num + 1); | ||
// printf("\nThread %d , starts: %d , ends: %d",t_num, start, end); | ||
|
||
#pragma omp parallel for | ||
for (int i = 0; i < steps; i++) | ||
{ | ||
x = (i + 0.5)* step; | ||
sum += 4.0/(1.0+x*x); | ||
} | ||
|
||
// printf("\nsum=%f",sum) | ||
// printf("\nThread %d, sum: %f",t_num, sum); | ||
|
||
|
||
pi = step * sum; | ||
// print("pi= %f", math.pi) | ||
printf("\npi= %.10f", pi); | ||
|
||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
#define NUMTHREAD 4 | ||
|
||
int main(int argc, char* argv[]){ | ||
|
||
double step, x, sum, pi; | ||
int i, steps; | ||
steps = 1000.0; | ||
|
||
step = 1.0/(double)steps; | ||
|
||
#pragma omp parallel for private(x) | ||
for (int i = 0; i < steps; i++) | ||
{ | ||
x = (i + 0.5)* step; | ||
#pragma omp critical | ||
{ | ||
sum += 4.0/(1.0+x*x); | ||
} | ||
} | ||
|
||
|
||
pi = step * sum; | ||
printf("\npi= %.15f", pi); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
|
||
double step, x, sum, pi; | ||
int i, steps; | ||
steps = 1000.0; | ||
|
||
int p[4] = { 2, 4, 6, 8 }; | ||
int n[5] = { 200, 400, 600, 800, 1000 }; | ||
|
||
for (int j = 0; j < 5; j++) | ||
{ | ||
for (int k = 0; k < 5; k++) | ||
{ | ||
pi = 0, sum = 0.0; | ||
step = 1.0 / (double)n[k]; | ||
omp_set_num_threads(p[j]); | ||
|
||
#pragma omp parallel for reduction(+:sum) | ||
for (int i = 0; i < n[k]; i++) | ||
{ | ||
x = (i + 0.5) * step; | ||
sum += 4.0 / (1.0 + x * x); | ||
} | ||
|
||
printf("\npi for num_threads %d and steps %d is %f",p[j], n[k], sum * step); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
pi = step * sum; | ||
printf("\npi= %.15f", pi); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
|
||
#define NUMTHREAD 4 | ||
|
||
int main(int argc, char* argv[]){ | ||
|
||
double step, x, sum, pi; | ||
int i, steps; | ||
steps = 1000.0; | ||
|
||
step = 1.0/(double)steps; | ||
|
||
#pragma omp parallel for private(x) reduction(+:sum) | ||
for (int i = 0; i < steps; i++) | ||
{ | ||
x = (i + 0.5)* step; | ||
sum += 4.0/(1.0+x*x); | ||
} | ||
|
||
|
||
pi = step * sum; | ||
printf("\npi= %.15f", pi); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include<omp.h> | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<math.h> | ||
|
||
|
||
void main() | ||
{ | ||
float step,x,sum,pi; | ||
int steps, tid; | ||
steps=1000; | ||
int num; | ||
step = 1.0/(float)steps; | ||
int numthread =4; | ||
omp_set_num_threads(numthread); | ||
#pragma omp parallel private(tid, num, x) | ||
{ | ||
tid=omp_get_thread_num(); | ||
num=omp_get_num_threads(); | ||
|
||
printf("threads num %d\n",numthread); | ||
printf("threads %d\n",num); | ||
printf("tid= %d\n",tid); | ||
#pragma omp for reduction(+:sum) | ||
for(int i= 0; i<steps; i++ ) | ||
{ | ||
x=(i+0.5)*step; | ||
sum+=4.0/(1.0+x*x); | ||
} | ||
} | ||
pi=step*sum; | ||
|
||
printf("pi=%.8f",pi); | ||
printf("\npi=%.8f",M_PI); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if (rank == 0) | ||
{ | ||
MPI_Recv(&recvbuf, count, MPI_Float, 1, tag, MPI_COMM_WORLD,&status); | ||
MPI_Send(&sendbuf, count, MPI_Float, 1, tag, MPI_COMM_WORLD); | ||
} | ||
else if (rank == 1) | ||
{ | ||
MPI_Send(&sendbuf, count, MPI_Float, 0, tag, MPI_CMM_WORLD, &status); | ||
MPI_Recv(&recvbuf, count, MPI_Float, 0, tag, MPI_COMM_WORLD, &status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if (rank == 0) | ||
{ | ||
MPI_Ssend(&sendbuf, count, MPI_Float, 1, tag, MPI_COMM_WORLD); | ||
MPI_Recv(&recvbuf, count, MPI_Float, 1, tag, MPI_COMM_WORLD, &status); | ||
} | ||
else if (rank == 1) | ||
{ | ||
MPI_SRecv(&recvbuf, count, MPI_Float, 0, tag, MPI_COMM_WORLD, &status); | ||
MPI_Ssend(&sendbuf, count, MPI_Float, 0, tag, MPI_CMM_WORLD); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <mpich/mpi.h> | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int numtasks, myRank, len, rc; | ||
char hostname[MPI_MAX_PROCESSOR_NAME]; | ||
MPI_Init(&argc, &argv); | ||
|
||
int sendbuf1, sendbuf2, count, recvbuf1, recvbuf2, tag; | ||
|
||
MPI_Comm comm = MPI_COMM_WORLD; | ||
MPI_Status status; | ||
|
||
|
||
MPI_Comm_rank(comm, &myRank); | ||
if (myRank == 0) | ||
{ | ||
MPI_Send(sendbuf1, count, MPI_INT, 2, tag, comm); | ||
MPI_Send(sendbuf2, count, MPI_INT, 1, tag, comm); | ||
} | ||
else if (myRank == 1) | ||
{ | ||
MPI_Recv(recvbuf1, count, MPI_INT, 0, tag, comm, &status); | ||
MPI_Send(recvbuf1, count, MPI_INT, 2, tag, comm); | ||
} | ||
else if (myRank == 2) | ||
{ | ||
MPI_Recv(recvbuf1, count, MPI_INT, MPI_ANY_SOURCE, tag, comm, &status); | ||
MPI_Recv(recvbuf2, count, MPI_INT, MPI_ANY_SOURCE, tag, comm, &status); | ||
} | ||
|
||
MPI_Finalize(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.