diff --git a/06_prolog/ex1.pl b/06_prolog/ex1.pl index 099e1a9..cada0c8 100644 --- a/06_prolog/ex1.pl +++ b/06_prolog/ex1.pl @@ -46,4 +46,7 @@ grandmother(X,Y) :- female(X),parent(Z,Y),parent(X,Z). sister(X,Y) :- female(X),parent(Z,X),parent(Z,Y),X\=Y. brother(X,Y) :- male(X),parent(Z,X),parent(Z,Y),X\=Y. cousin(X,Y) :- uncle(Z,Y),parent(Z,X). -cousin(X,Y) :- aunt(Z,Y),parent(Z,X). \ No newline at end of file +cousin(X,Y) :- aunt(Z,Y),parent(Z,X). + +ancestor(X,Y) :- parent(X,Y). +ancestor(X,Y) :- parent(X,Z),ancestor(Z,Y). \ No newline at end of file diff --git a/07_OpenMP/desc b/07_OpenMP/desc new file mode 100644 index 0000000..1539d71 --- /dev/null +++ b/07_OpenMP/desc @@ -0,0 +1,12 @@ +Excercise 1 +This is our quick tutorial. + + +Excercise 2 +Implement in OpenMP the search of the maximum value in an array with randomly generated numbers. Check the speed up from 1 up to X threads. + +Why there is no speed up at some point? + + +Excercise 3 +Implement bubble sort in OpenMP. Can you make it faster than 1 threaded quicksort? \ No newline at end of file diff --git a/07_OpenMP/ex1/src/openmp1.c b/07_OpenMP/ex1/src/openmp1.c new file mode 100644 index 0000000..930a8a4 --- /dev/null +++ b/07_OpenMP/ex1/src/openmp1.c @@ -0,0 +1,59 @@ +/* + ============================================================================ + Name : openmp1.c + Author : + Version : + Copyright : Your copyright notice + Description : Hello World in C, Ansi-style + ============================================================================ + */ + +#include +#include +#include + + +void sum() { + int partial_Sum, total_Sum; + + #pragma omp parallel private(partial_Sum) shared(total_Sum) + { + partial_Sum = 0; + total_Sum = 0; + + #pragma omp for + for(int i = 1; i <= 100; i++) { + partial_Sum += i; + } + + //Create thread safe region. + #pragma omp critical + { + //add each threads partial sum to the total sum + total_Sum += partial_Sum; + } + } + printf("Total Sum: %d\n", total_Sum); +} + +int main(void) { + puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ + + const int numThreads = 4; + int a[numThreads]; + omp_set_num_threads(numThreads); + #pragma omp parallel + { + int id = omp_get_thread_num(); + a[id] = id + 1; + } + + for (int i = 0; i < numThreads; i++) { + printf("Hello from thread %d\n", a[i]); + } + + sum(); +// sum2(); + + return EXIT_SUCCESS; +}