Skip to content

Commit

Permalink
🔨 Added scripts for automatic running with custom sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
OakenKnight committed Jan 28, 2022
1 parent 6941085 commit cdca9d2
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ clean:
@rm -f distributed-fractal
@rm -f fractal-images/distrib-fractal.jpg
@rm -f gpu-fractal
@rm -f fractal-images/cuda-fractal.jpg
23 changes: 23 additions & 0 deletions code/cuda-fractal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ static void run(double xmin, double xmax, double ymin, double ymax, int width, i
}

int main(int argc, char** argv){

FILE *out_file = fopen("code/data/cuda.txt", "a");
if (out_file == NULL) {
printf("Error! Could not open file\n");
exit(-1);
}
cudaError_t err = cudaSuccess;

int width = 300;
Expand All @@ -109,11 +115,28 @@ int main(int argc, char** argv){
double ymin=-1.0;
double ymax= 1.0;


if (argc > 1)
height = atoi(argv[1]);
if(argc>2){
width = atoi(argv[2]);
}
if(argc>3){
max_iter = atoi(argv[3]);
}
clock_t begin = clock();

char *result = NULL;
err = cudaMalloc(&result, width*height*sizeof(char));
checkErr(err, "Failed to allocate result memory on gpu");

run(xmin, xmax, ymin, ymax, width, height, max_iter, result);
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

fprintf(out_file, "%f & ", time_spent); // write to file

printf("time took for execution of sequential algorithm: %f\n", time_spent);

cudaFree(result);
return 0;
Expand Down
1 change: 1 addition & 0 deletions code/data/cuda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.097496 & 0.130999 & 0.249084 & 0.608844 &
Empty file added code/data/distributed.txt
Empty file.
1 change: 1 addition & 0 deletions code/data/seq.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.072927 & 0.170139 & 0.918021 & 11.324259 & 2.699279 & 10.882355 & 42.348594 & 168.265071 &
Empty file added code/data/shared.txt
Empty file.
19 changes: 17 additions & 2 deletions code/distributed-fractal.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void compute_image( double xmin, double xmax, double ymin, double ymax, int maxi
double xstep = (xmax-xmin) / (width-1);
double ystep = (ymax-ymin) / (height-1);

#pragma omp parallel shared(result, maxiter, start, end) private(i,iter)
#pragma omp for schedule(runtime)
// #pragma omp parallel shared(result, maxiter, start, end) private(i,iter)
#pragma omp parallel for shared(result, maxiter, start, end) private(i,iter)
for (i = start; i < end; i++) {

double x = xmin + (i%width)*xstep;
Expand Down Expand Up @@ -94,6 +94,13 @@ void run(int maxiter, int current_processor, int processors_amount, int width, i

int main( int argc, char **argv ){


FILE *out_file = fopen("code/data/distributed.txt", "a");
if (out_file == NULL) {
printf("Error! Could not open file\n");
exit(-1);
}

double xmin=-1.5;
double xmax= 0.5;
double ymin=-1.0;
Expand All @@ -103,6 +110,14 @@ int main( int argc, char **argv ){
int height = 1200;
int maxiter=5000;

if (argc > 1)
height = atoi(argv[1]);
if(argc>2){
width = atoi(argv[2]);
}
if(argc>3){
maxiter = atoi(argv[3]);
}

int size, rank;

Expand Down
27 changes: 22 additions & 5 deletions code/seq-fractal.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,37 @@ void compute_image( double xmin, double xmax, double ymin, double ymax, int maxi
}

}
stbi_write_jpg("fractal-images/fractal.jpg", width, height, 1, buffer, 200);

stbi_write_jpg("fractal-images/fractal.jpg", width, height, 1, buffer, 200);

}

int main( int argc, char *argv[] )
{

FILE *out_file = fopen("code/data/seq.txt", "a");
if (out_file == NULL) {
printf("Error! Could not open file\n");
exit(-1);
}

double xmin=-1.5;
double xmax= 0.5;
double ymin=-1.0;
double ymax= 1.0;

int width = 1000;
int height = 1000;
int width = 128;
int height = 128;

int maxiter=1000;
int maxiter=100;

if (argc > 1)
height = atoi(argv[1]);
if(argc>2){
width = atoi(argv[2]);
}
if(argc>3){
maxiter = atoi(argv[3]);
}

printf("Timer started\n");

Expand All @@ -68,6 +83,8 @@ int main( int argc, char *argv[] )
clock_t end = clock();

double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

fprintf(out_file, "%f & ", time_spent); // write to file

printf("time took for execution of sequential algorithm: %f\n", time_spent);

Expand Down
16 changes: 13 additions & 3 deletions code/shared-fractal.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ void compute_image_opt( double xmin, double xmax, double ymin, double ymax, int

int main( int argc, char *argv[] )
{
FILE *out_file = fopen("code/data/shared.txt", "a");
if (out_file == NULL) {
printf("Error! Could not open file\n");
exit(-1);
}
double xmin=-1.5;
double xmax= 0.5;
double ymin=-1.0;
Expand All @@ -95,13 +100,18 @@ int main( int argc, char *argv[] )
int height = 1200;
int threadct = omp_get_max_threads();
int maxiter=5000;

if (argc > 1)
threadct = atoi(argv[1]);
height = atoi(argv[1]);
if(argc>2){
maxiter = atoi(argv[2]);
width = atoi(argv[2]);
}
if(argc>3){
maxiter = atoi(argv[3]);
}



printf("Coordinates: %lf %lf %lf %lf\n",xmin,xmax,ymin,ymax);
printf("Timer started\n");

Expand Down
Binary file removed distributed-fractal
Binary file not shown.
Binary file removed fractal-images/cuda-fractal.jpg
Binary file not shown.
Binary file removed fractal-images/distrib-fractal.jpg
Binary file not shown.
Binary file removed fractal-images/shared-fractal.jpg
Binary file not shown.
Binary file removed gpu-fractal
Binary file not shown.
13 changes: 13 additions & 0 deletions run_cuda_fractals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
make cuda

./gpu-fractal 128 128 5000

./gpu-fractal 256 256 5000

./gpu-fractal 512 512 5000

./gpu-fractal 1024 1024 5000



13 changes: 13 additions & 0 deletions run_distributed_fractals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
make distributed-fractal

mpiexec ./distributed-fractal 128 128 5000

mpiexec ./distributed-fractal 256 256 5000

mpiexec ./distributed-fractal 512 512 5000

mpiexec ./distributed-fractal 1024 1024 5000



11 changes: 11 additions & 0 deletions run_seq_fractals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
make seq-fractal

./seq-fractal 128 128 5000

./seq-fractal 256 256 5000

./seq-fractal 512 512 5000

./seq-fractal 1024 1024 5000

13 changes: 13 additions & 0 deletions run_shared_fractals.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
make shared-fractal

./shared-fractal 128 128 5000

./shared-fractal 256 256 5000

./shared-fractal 512 512 5000

./shared-fractal 1024 1024 5000



Binary file removed shared-fractal
Binary file not shown.

0 comments on commit cdca9d2

Please sign in to comment.