Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue118 misaligned blocks in gpu codes #119

Merged
merged 5 commits into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gpu_diffusion_list := gpu-cuda-diffusion \
gpu-openacc-diffusion \
gpu-opencl-diffusion

phi_diffusion_list := phi-openmp-diffusion

.PHONY: run
run: run_cpu_diffusion run_gpu_diffusion

Expand Down
68 changes: 40 additions & 28 deletions common-diffusion/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#include <png.h>
#include "output.h"

void param_parser(int argc, char* argv[], int* nx, int* ny, int* nm, int* code, fp_t* dx, fp_t* dy, fp_t* D, fp_t* linStab, int* steps, int* checks)
void param_parser(int argc, char* argv[], int* bx, int* by, int* checks, int* code, fp_t* D, fp_t* dx, fp_t* dy, fp_t* linStab, int* nm, int* nx, int* ny, int* steps)
{
FILE * input;
char buffer[256];
char* pch;
int inx=0, iny=0, idx=0, idy=0, ins=0, inc=0, idc=0, ico=0, isc=0;
int ibx=0, iby=0, ico=0, idc=0, idx=0, idy=0, inc=0, ins=0, inx=0, iny=0, isc=0;

if (argc != 2) {
printf("Error: improper arguments supplied.\nUsage: ./%s filename\n", argv[0]);
Expand All @@ -53,14 +53,22 @@ void param_parser(int argc, char* argv[], int* nx, int* ny, int* nm, int* code,
{
pch = strtok(buffer, " ");

if (strcmp(pch, "nx") == 0) {
if (strcmp(pch, "bx") == 0) {
pch = strtok(NULL, " ");
*nx = atoi(pch);
inx = 1;
} else if (strcmp(pch, "ny") == 0) {
*bx = atoi(pch);
ibx = 1;
} else if (strcmp(pch, "by") == 0) {
pch = strtok(NULL, " ");
*ny = atoi(pch);
iny = 1;
*by = atoi(pch);
iby = 1;
} else if (strcmp(pch, "co") == 0) {
pch = strtok(NULL, " ");
*linStab = atof(pch);
ico = 1;
} else if (strcmp(pch, "dc") == 0) {
pch = strtok(NULL, " ");
*D = atof(pch);
idc = 1;
} else if (strcmp(pch, "dx") == 0) {
pch = strtok(NULL, " ");
*dx = atof(pch);
Expand All @@ -69,22 +77,22 @@ void param_parser(int argc, char* argv[], int* nx, int* ny, int* nm, int* code,
pch = strtok(NULL, " ");
*dy = atof(pch);
idy = 1;
} else if (strcmp(pch, "ns") == 0) {
pch = strtok(NULL, " ");
*steps = atoi(pch);
ins = 1;
} else if (strcmp(pch, "nc") == 0) {
pch = strtok(NULL, " ");
*checks = atoi(pch);
inc = 1;
} else if (strcmp(pch, "dc") == 0) {
} else if (strcmp(pch, "ns") == 0) {
pch = strtok(NULL, " ");
*D = atof(pch);
idc = 1;
} else if (strcmp(pch, "co") == 0) {
*steps = atoi(pch);
ins = 1;
} else if (strcmp(pch, "nx") == 0) {
pch = strtok(NULL, " ");
*linStab = atof(pch);
ico = 1;
*nx = atoi(pch);
inx = 1;
} else if (strcmp(pch, "ny") == 0) {
pch = strtok(NULL, " ");
*ny = atoi(pch);
iny = 1;
} else if (strcmp(pch, "sc") == 0) {
pch = strtok(NULL, " ");
*nm = atoi(pch);
Expand All @@ -98,22 +106,26 @@ void param_parser(int argc, char* argv[], int* nx, int* ny, int* nm, int* code,
}

/* make sure we got everyone */
if (! inx) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "nx", *nx);
} else if (! iny) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "ny", *ny);
if (! ibx) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "bx", *bx);
} else if (! iby) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "by", *by);
} else if (! ico) {
printf("Warning: parameter %s undefined. Using default value, %f.\n", "co", *linStab);
} else if (! idc) {
printf("Warning: parameter %s undefined. Using default value, %f.\n", "dc", *D);
} else if (! idx) {
printf("Warning: parameter %s undefined. Using default value, %f.\n", "dx", *dx);
} else if (! idy) {
printf("Warning: parameter %s undefined. Using default value, %f.\n", "dy", *dy);
} else if (! ins) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "ns", *steps);
} else if (! inc) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "nc", *checks);
} else if (! idc) {
printf("Warning: parameter %s undefined. Using default value, %f.\n", "dc", *D);
} else if (! ico) {
printf("Warning: parameter %s undefined. Using default value, %f.\n", "co", *linStab);
} else if (! ins) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "ns", *steps);
} else if (! inx) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "nx", *nx);
} else if (! iny) {
printf("Warning: parameter %s undefined. Using default value, %i.\n", "ny", *ny);
} else if (! isc) {
printf("Warning: parameter %s undefined. Using default values, %i and %i.\n", "sc", *nm, *code);
}
Expand Down
2 changes: 1 addition & 1 deletion common-diffusion/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
\brief Read parameters from file specified on the command line
*/
void param_parser(int argc, char* argv[], int* nx, int* ny, int* nm, int* code, fp_t* dx, fp_t* dy, fp_t* D, fp_t* linStab, int* steps, int* checks);
void param_parser(int argc, char* argv[], int* bx, int* by, int* checks, int* code, fp_t* D, fp_t* dx, fp_t* dy, fp_t* linStab, int* nm, int* nx, int* ny, int* steps);

/**
\brief Prints timestamps and a 20-point progress bar to stdout
Expand Down
3 changes: 3 additions & 0 deletions common-diffusion/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#ifndef __USE_BSD
#define __USE_BSD
#endif
#ifndef __USE_MISC
#define __USE_MISC
#endif
#include <sys/time.h>
#endif

Expand Down
4 changes: 2 additions & 2 deletions cpu-analytic-diffusion/analytic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(int argc, char* argv[])

/* declare default mesh size and resolution */
fp_t **conc_old, **conc_new, **conc_lap, **mask_lap;
int nx=512, ny=512, nm=3, code=53;
int bx=32, by=32, nx=512, ny=512, nm=3, code=53;
fp_t dx=0.5, dy=0.5, h=0.5;

/* declare default materials and numerical parameters */
Expand All @@ -82,7 +82,7 @@ int main(int argc, char* argv[])

StartTimer();

param_parser(argc, argv, &nx, &ny, &nm, &code, &dx, &dy, &D, &linStab, &steps, &checks);
param_parser(argc, argv, &bx, &by, &checks, &code, &D, &dx, &dy, &linStab, &nm, &nx, &ny, &steps);

h = (dx > dy) ? dy : dx;
dt = (linStab * h * h) / (4.0 * D);
Expand Down
4 changes: 2 additions & 2 deletions cpu-openmp-diffusion/openmp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char* argv[])

/* declare default mesh size and resolution */
fp_t **conc_old, **conc_new, **conc_lap, **mask_lap;
int nx=512, ny=512, nm=3, code=53;
int bx=32, by=32, nx=512, ny=512, nm=3, code=53;
fp_t dx=0.5, dy=0.5, h=0.5;
fp_t bc[2][2];

Expand All @@ -55,7 +55,7 @@ int main(int argc, char* argv[])

StartTimer();

param_parser(argc, argv, &nx, &ny, &nm, &code, &dx, &dy, &D, &linStab, &steps, &checks);
param_parser(argc, argv, &bx, &by, &checks, &code, &D, &dx, &dy, &linStab, &nm, &nx, &ny, &steps);

h = (dx > dy) ? dy : dx;
dt = (linStab * h * h) / (4.0 * D);
Expand Down
4 changes: 2 additions & 2 deletions cpu-serial-diffusion/serial_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(int argc, char* argv[])

/* declare default mesh size and resolution */
fp_t **conc_old, **conc_new, **conc_lap, **mask_lap;
int nx=512, ny=512, nm=3, code=53;
int bx=32, by=32, nx=512, ny=512, nm=3, code=53;
fp_t dx=0.5, dy=0.5, h=0.5;
fp_t bc[2][2];

Expand All @@ -63,7 +63,7 @@ int main(int argc, char* argv[])

StartTimer();

param_parser(argc, argv, &nx, &ny, &nm, &code, &dx, &dy, &D, &linStab, &steps, &checks);
param_parser(argc, argv, &bx, &by, &checks, &code, &D, &dx, &dy, &linStab, &nm, &nx, &ny, &steps);

h = (dx > dy) ? dy : dx;
dt = (linStab * h * h) / (4.0 * D);
Expand Down
4 changes: 2 additions & 2 deletions cpu-tbb-diffusion/tbb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char* argv[])

/* declare default mesh size and resolution */
fp_t **conc_old, **conc_new, **conc_lap, **mask_lap;
int nx=512, ny=512, nm=3, code=53;
int bx=32, by=32, nx=512, ny=512, nm=3, code=53;
fp_t dx=0.5, dy=0.5, h=0.5;
fp_t bc[2][2];

Expand All @@ -55,7 +55,7 @@ int main(int argc, char* argv[])

StartTimer();

param_parser(argc, argv, &nx, &ny, &nm, &code, &dx, &dy, &D, &linStab, &steps, &checks);
param_parser(argc, argv, &bx, &by, &checks, &code, &D, &dx, &dy, &linStab, &nm, &nx, &ny, &steps);

h = (dx > dy) ? dy : dx;
dt = (linStab * h * h) / (4.0 * D);
Expand Down
5 changes: 3 additions & 2 deletions gpu-cuda-diffusion/cuda_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ void init_cuda(fp_t** conc_old, fp_t** mask_lap, fp_t bc[2][2],
\brief Specialization of solve_diffusion_equation() using CUDA
*/
void cuda_diffusion_solver(struct CudaData* dev, fp_t** conc_new,
int nx, int ny, int nm,
fp_t bc[2][2], fp_t D, fp_t dt, int checks,
fp_t bc[2][2], int bx, int by,
int nm, int nx, int ny,
fp_t D, fp_t dt, int checks,
fp_t *elapsed, struct Stopwatch* sw);

/**
Expand Down
Loading