-
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.
- Loading branch information
Showing
17 changed files
with
569 additions
and
3 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
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,29 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <omp.h> | ||
|
||
float i_func(float x){ | ||
return 4.0/(1.0 + x * x); | ||
} | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
float start = 0, stop = 1; | ||
float range = stop - start; | ||
int interval_count = 100; | ||
float interval_width = range / (float) interval_count; | ||
|
||
float result = 0.0; | ||
|
||
for (int i = 0; i < interval_count; i++) | ||
{ | ||
float curr_start = start + (interval_width * (float) i); | ||
result += i_func(curr_start) * interval_width; | ||
printf("\nResult[%d]= %f",i,result); | ||
|
||
} | ||
|
||
printf("\nResult: %f", result); | ||
|
||
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,45 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <omp.h> | ||
#define steps 100 | ||
#define thread_num 4 | ||
float i_func(float x){ | ||
return 4.0/(1.0 + x * x); | ||
} | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
omp_set_num_threads(thread_num); | ||
|
||
float start = 0, stop = 1; | ||
float interval_width = (stop - start) / (float) steps; | ||
|
||
float* results = malloc(sizeof(float) * thread_num); | ||
|
||
float sum= 0.0; | ||
|
||
#pragma omp parallel | ||
{ | ||
int p_id = omp_get_thread_num(); | ||
float result = 0.0; | ||
for (int i = p_id * (steps / thread_num); i < (p_id + 1) * (steps / thread_num); i++) | ||
{ | ||
result += i_func(start + (interval_width * (float) i )) * interval_width; | ||
} | ||
|
||
#pragma omp critical | ||
sum += result; | ||
} | ||
|
||
// for (int i = 0; i < thread_num; i++) | ||
// { | ||
// /* code */ | ||
// printf("\nResult[%d]= %f",i,results[i]); | ||
// sum+= results[i]; | ||
// } | ||
|
||
printf("\nResult: %f", sum); | ||
|
||
|
||
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,24 @@ | ||
#include <math.h> | ||
#include <mpi.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int rank; | ||
|
||
MPI_Init(NULL, NULL); | ||
|
||
// Get the number of processes | ||
int world_size; | ||
MPI_Comm_size(MPI_COMM_WORLD, &world_size); | ||
|
||
// Get the rank of the process | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
|
||
printf("Hello world from processor, rank %d out of %d processors\n", rank, world_size); | ||
|
||
MPI_Finalize(); | ||
|
||
} |
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,26 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
|
||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int a = 5; | ||
|
||
#pragma omp parallel sections private(a) | ||
{ | ||
#pragma omp section | ||
{ | ||
printf("\nA avant section 1: %d",a); | ||
a = 15; | ||
printf("\nA après section 1: %d",a); | ||
} | ||
|
||
#pragma omp section | ||
{ | ||
printf("\n Affichage: %d", a); | ||
} | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
|
||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
// Two threads | ||
// omp_set_num_threads(2); | ||
// Four threads | ||
omp_set_num_threads(4); | ||
#pragma omp parallel sections | ||
{ | ||
#pragma omp section | ||
{ | ||
printf("\n Hello %d",omp_get_thread_num()); | ||
} | ||
|
||
#pragma omp section | ||
{ | ||
printf("\n World %d", omp_get_thread_num()); | ||
} | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <omp.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
|
||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int a = 5; | ||
|
||
#pragma omp parallel sections | ||
{ | ||
#pragma omp section | ||
{ | ||
// with critical or not the output is the same, misunderstanding ? | ||
#pragma omp critical | ||
{ | ||
a = 15; | ||
} | ||
} | ||
|
||
#pragma omp section | ||
{ | ||
printf("\n Affichage: %d", a); | ||
} | ||
} | ||
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,25 @@ | ||
#include <stdio.h> | ||
#include <omp.h> | ||
#define SIZE 100 | ||
#define CHUNK 10 | ||
int main() | ||
{ | ||
int tid; | ||
double a[SIZE], b[SIZE], c[SIZE]; | ||
for (size_t i = 0; i < SIZE; i++) | ||
a[i] = b[i] = i; | ||
#pragma omp parallel private(tid) | ||
{ | ||
tid = omp_get_thread_num(); | ||
if (tid == 0) | ||
printf("Nb threads = %d\n", omp_get_num_threads()); | ||
printf("Thread %d: starting ...\n", tid); | ||
#pragma omp for schedule(static, CHUNK) | ||
for (size_t i = 0; i < SIZE; i++) | ||
{ | ||
c[i] = a[i] + b[i]; | ||
printf("Thread %d: c[%2zu] = %g\n", tid, i, c[i]); | ||
} | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.