*/
#include "algorithm_1.h"
-int algorithm_1 (numtype y[], int n, int ops[]) {
- return 0;
+void algorithm_1 (numtype x[], int n, int ops[]) {
+ int i;
+ numtype y[n/2];
+ if (n == 1) {
+ return;
+ }
+
+ for (i=0; i < (n/2); i++) {
+ y[i] = x[2*i] + x[2*i+1];
+ }
+
+ algorithm_1(y, n/2, ops);
+
+ x[1] = y[0];
+
+ for (i = 1; i < (n/2); i++){
+ x[2*i] = y[i-1] + x[2*i];
+ x[2*i+1] = y[i];
+ }
+ if ((n%2)==1) {
+ x[n-1] = y[n/2-1] + x[n-1];
+ }
}
#include "algorithm_2.h"
#include "algorithm_3.h"
+#define NUMBERS 800000
+
int main (int argc, char* argv[]) {
int result = 0;
- numtype numarray[5];
- int countarray[5];
+ numtype numarray[NUMBERS];
+ int countarray[NUMBERS];
int i;
double startTime, endTime;
- for (i = 0; i < 5; i++) {
- numarray[i] = i;
+ for (i = 0; i < NUMBERS; i++) {
+ numarray[i] = 10;
countarray[i] = 0;
}
startTime = omp_get_wtime();
printf ("calling algorithm 1:");
- result = algorithm_1(numarray, 5, countarray);
- printf ("sum: %i\n", result);
+ algorithm_1(numarray, NUMBERS, countarray);
+ printf ("sum: %i\n", numarray[NUMBERS-1]);
endTime = omp_get_wtime();
printf("took %f seconds.\n", endTime-startTime);
startTime = omp_get_wtime();
printf ("calling algorithm 2:");
- result = algorithm_2(numarray, 5, countarray);
+ result = algorithm_2(numarray, NUMBERS, countarray);
printf ("sum: %i\n", result);
endTime = omp_get_wtime();
printf("took %f seconds.\n", endTime-startTime);
startTime = omp_get_wtime();
printf ("calling algorithm 3:");
- result = algorithm_3(numarray, 5, countarray);
+ result = algorithm_3(numarray, NUMBERS, countarray);
printf ("sum: %i\n", result);
endTime = omp_get_wtime();
printf("took %f seconds.\n", endTime-startTime);