diff --git a/A2/Makefile b/A2/Makefile index 5bde0ee..5544ddd 100755 --- a/A2/Makefile +++ b/A2/Makefile @@ -1,12 +1,12 @@ CC = gcc CFLAGS = -std=gnu99 -O3 -fopenmp -Wall BIN = assignment2 all: $(BIN) -$(BIN): assignment2.c utility.h algorithm_trivial.c +$(BIN): assignment2.c utility.h algorithm_T_tile.c $(CC) $(CFLAGS) $< -o $@ clean: rm -f $(BIN) *.o diff --git a/A2/algorithm.c b/A2/algorithm.c new file mode 100644 index 0000000..10c4c3c --- /dev/null +++ b/A2/algorithm.c @@ -0,0 +1,42 @@ +/* +============================================================================ +Filename : algorithm.c +Author : Your names go here +SCIPER : Your SCIPER numbers + +============================================================================ +*/ +#include + +#define INPUT(I,J) input[(I)*length+(J)] +#define OUTPUT(I,J) output[(I)*length+(J)] + + +void simulate(double *input, double *output, int threads, int length, int iterations) +{ + double *temp; + + omp_set_num_threads(threads); + + for(int n=0; n < iterations; n++) + { + #pragma omp parallel for + for(int i=1; i #include #include #include #include "utility.h" //#include "algorithm_Ancarola.c" //#include "algorithm_test.c" //#include "algorithm.c" //#include "algorithm_slow.c" -//#include "algorithm_T_tile.c" +#include "algorithm_T_tile.c" //#include "algorithm_1fork.c" //#include "algorithm_onethread.c" -#include "algorithm_trivial.c" +//#include "algorithm_trivial.c" //#include "algorithm_collapse.c" int main (int argc, const char *argv[]) { int threads, length, iterations; double time; if (argc != 5) { printf("Invalid input! \nUsage: ./assignment2 \n"); return 1; } else { threads = atoi(argv[1]); length = atoi(argv[2]); iterations = atoi(argv[3]); if(length%2!=0) { printf("Invalid input! Array length must be even\n"); return 1; } } //Allocate a two-dimensional array double *input = malloc(sizeof(double)*length*length); double *output = malloc(sizeof(double)*length*length); //Initialize the array init(input, length); init(output, length); //Start timer set_clock(); //Optimize the following function simulate(input, output, threads, length, iterations); //Stop timer time = elapsed_time(); //Report time required for n iterations printf("Running the algorithm with %d threads on %d by %d array for %d iterations took %.4g seconds \n", threads, length, length, iterations, time); if(iterations % 2 == 0){ double *temp = input; input = output; output = temp; } //Save array in filelength if the output is not /dev/null // idea: do not save if not needed if (strcmp(argv[4], "/dev/null") != 0) save(output, length, argv[4]); //Free allocated memory free(input); free(output); return 0; } diff --git a/A2/execute_ancarola.sh b/A2/execute_ancarola.sh index 8290d05..8af9a1e 100755 --- a/A2/execute_ancarola.sh +++ b/A2/execute_ancarola.sh @@ -1,22 +1,22 @@ #!/bin/bash #SBATCH --chdir /scratch/ancarola #SBATCH --nodes 1 #SBATCH --ntasks 1 #SBATCH --cpus-per-task 28 #SBATCH --mem 4G #SBATCH --partition serial #SBATCH --account cs307 #SBATCH --reservation CS307-ex echo STARTING AT `date` user=ancarola wdir="/home/$user/multiproc/A2" Ntr="1 2 4 8 16" for ntr in $Ntr; do - ./assignment2 $ntr 10000 100 /dev/null + ./assignment2 $ntr 5000 50 /dev/null done echo FINISHED at `date`