#include #include "cmdline.h" void parse_arguments(int argc, char *argv[], int *nx, int *maxsteps, float *threshold, int *num_work_items, int *workgroup_size_factor, FILE **outfile, cl_device_type *device_type) { char *usage_msg = "usage is" "\n %s points max_iterations convergence_threshold" "\n num_work_items workgroup_size_factor [\"CPU\"]" "\n [outfilename]" "\n"; *nx = get_integer_arg(argc, argv, 1, 1, "points", usage_msg); *maxsteps = get_integer_arg(argc, argv, 2, 1, "max_iterations", usage_msg); *threshold = get_floating_arg(argc, argv, 3, 0.0, "convergence_threshold", usage_msg); *num_work_items = get_integer_arg(argc, argv, 4, 1, "num_work_items", usage_msg); *workgroup_size_factor = get_integer_arg(argc, argv, 5, 1, "workgroup_size_factor", usage_msg); *outfile = NULL; *device_type = CL_DEVICE_TYPE_GPU; int next_parm = 6; if (argc > next_parm) { if (strcmp(argv[next_parm], "CPU") == 0) { *device_type = CL_DEVICE_TYPE_CPU; next_parm += 1; } } if (argc > next_parm) { FILE* out = fopen(argv[next_parm], "w"); if (out == NULL) { fprintf(stderr, "Cannot open outfile %s\n", argv[next_parm]); fprintf(stderr, usage_msg, argv[0]); exit(EXIT_FAILURE); } *outfile = out; } } void initialize_values(float uk[], int nx) { uk[0] = LEFTVAL; uk[nx+1] = RIGHTVAL; for (int i = 1; i <= nx; ++i) uk[i] = 0.0f; }