Skip to content

Commit

Permalink
Last touches to fix up #1563:
Browse files Browse the repository at this point in the history
1) On GPU:
   'NULL' (automatic) mode is mapped to 'default' which means 'regular'
2) When explicitly using 'regular' (or arriving there by logic on GPU)
   terminate in error if dataset axie-dimensions are not equal.
  • Loading branch information
willend committed Feb 9, 2024
1 parent 82da9fa commit c9126cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 13 additions & 2 deletions common/lib/share/interpolation-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ struct interpolator_struct *interpolator_load(char *filename,

#ifdef OPENACC
if (method && strlen(method) && (!strcmp(method, "kdtree"))) {
fprintf(stderr, "interpolator_load: FATAL ERROR: 'kdtree' is not supported on OpenACC/GPU - only 'regular' works!\n");
fprintf(stderr, "\n\n!! interpolator_load: FATAL ERROR: !! \n'kdtree' is not supported on OpenACC/GPU - only 'regular' works!\n\n");
Table_Free(&table);
exit(-1);
}
Expand Down Expand Up @@ -468,10 +468,21 @@ struct interpolator_struct *interpolator_load(char *filename,
/* assign interpolation technique: 'regular' direct indexing */
if (!strcmp(interpolator->method, "regular")) {
interpolator->kdtree = NULL;
/* Terminate if the dimensions are not equal */
if (interpolator->bin[0] != interpolator->bin[1] ||
interpolator->bin[0] != interpolator->bin[2] ||
interpolator->bin[1] != interpolator->bin[2]) {
fprintf(stderr,"\n\n%s\n\n",
"!! interpolation-lib ERROR: !!\n"
" You are running the 'regular' interpolation scheme\n"
" with a file of unequal axis dimensions. This will lead to systematic errors!\n"
" Please either resample the file to achieve this or run with 'kdtree'\n"
" (kdtree is available on CPU only)");
exit(-1);
}
/* store table values onto the grid: each field component is stored on the
* interpolator->grid, and has size=prod(interpolator->bin)
*/

long prod=1; /* the number of elements in the grid */
for (dim=0; dim<interpolator->space_dimensionality; dim++)
prod *= interpolator->bin[dim];
Expand Down
12 changes: 11 additions & 1 deletion mcstas-comps/optics/Pol_tabled_field.comp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ INITIALIZE
/* these default field functions are part of pol-lib */
/*initialize the interpolation vertex structure*/


#ifdef OPENACC
// If "aotomatic mode is given on GPU, switch
// to 'default'
if (!strcmp(interpol_method,"NULL")) {
sprintf(interpol_method,"default");
}
#endif

// Handle default mode in both CPU and GPU case
if (!strcmp(interpol_method,"default")) {
#ifdef OPENACC
// Default is to assume regular interpolation on GPU
Expand All @@ -168,7 +178,7 @@ INITIALIZE
sprintf(interpol_method,"NULL");
#endif
}

interpolator = interpolator_load(filename, 3, 3, interpol_method);
interpolator_info(interpolator);

Expand Down

0 comments on commit c9126cb

Please sign in to comment.