Skip to content

Commit

Permalink
Remove execution policy following @drreynolds suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Roberts committed Sep 21, 2024
1 parent 5ba27fa commit 1d35b62
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 373 deletions.
52 changes: 0 additions & 52 deletions include/arkode/arkode_execution_policy.h

This file was deleted.

4 changes: 0 additions & 4 deletions include/arkode/arkode_splittingstep.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef ARKODE_SPLITTINGSTEP_H_
#define ARKODE_SPLITTINGSTEP_H_

#include <arkode/arkode_execution_policy.h>
#include <sundials/sundials_nvector.h>
#include <sundials/sundials_stepper.h>
#include <sundials/sundials_types.h>
Expand Down Expand Up @@ -102,9 +101,6 @@ SUNDIALS_EXPORT void* SplittingStepCreate(SUNStepper* steppers, int partitions,
SUNDIALS_EXPORT int SplittingStep_SetCoefficients(
void* arkode_mem, SplittingStepCoefficients coefficients);

SUNDIALS_EXPORT int SplittingStep_SetExecutionPolicy(
void* arkode_mem, ARKodeSplittingExecutionPolicy policy);

SUNDIALS_EXPORT int SplittingStep_GetNumEvolves(void* arkode_mem, int partition,
long int* evolves);

Expand Down
33 changes: 0 additions & 33 deletions include/arkode/execution_policy/arkode_execution_policy_serial.h

This file was deleted.

4 changes: 1 addition & 3 deletions src/arkode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ set(arkode_SOURCES
arkode_relaxation.c
arkode_root.c
arkode_splittingstep_coefficients.c
arkode_splittingstep_executionpolicy.c
arkode_splittingstep.c
arkode_sprkstep_io.c
arkode_sprkstep.c
arkode_sprk.c
arkode_user_controller.c
arkode.c
execution_policy/arkode_execution_policy_serial.c)
arkode.c)

# Add variable arkode_HEADERS with the exported ARKODE header files
set(arkode_HEADERS
Expand Down
93 changes: 24 additions & 69 deletions src/arkode/arkode_splittingstep.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <arkode/arkode_arkstep.h>
#include <arkode/arkode_splittingstep.h>
#include <arkode/execution_policy/arkode_execution_policy_serial.h>
#include <sundials/sundials_nvector.h>

#include "arkode_impl.h"
Expand Down Expand Up @@ -125,7 +124,6 @@ static int splittingStep_SetCoefficients(const ARKodeMem ark_mem,
With initialization types FIRST_INIT this routine:
- sets/checks the splitting coefficients to be used
- sets/checks the execution policy to be used
With other initialization types, this routine does nothing.
---------------------------------------------------------------*/
Expand All @@ -152,21 +150,6 @@ static int splittingStep_Init(const ARKodeMem ark_mem, const int init_type)
retval = splittingStep_SetCoefficients(ark_mem, step_mem);
if (retval != ARK_SUCCESS) { return retval; }

if (step_mem->policy == NULL)
{
step_mem->policy = ARKodeSplittingExecutionPolicy_New_Serial();
if (step_mem->policy == NULL)
{
if (step_mem->coefficients == NULL)
{
arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__,
"Failed to allocate execution policy");
return ARK_MEM_FAIL;
}
}
step_mem->own_policy = SUNTRUE;
}

ark_mem->interp_degree =
SUNMAX(1, SUNMIN(step_mem->coefficients->order - 1, ark_mem->interp_degree));

Expand Down Expand Up @@ -222,7 +205,7 @@ static int splittingStep_FullRHS(const ARKodeMem ark_mem, const sunrealtype t,
MSG_ARK_RHSFUNC_FAILED, t);
return (ARK_RHSFUNC_FAIL);
}
N_VLinearSum(SUN_RCONST(1.0), f, SUN_RCONST(1.0), ark_mem->tempv1, f);
N_VLinearSum(ONE, f, ONE, ark_mem->tempv1, f);
}

return ARK_SUCCESS;
Expand All @@ -231,14 +214,10 @@ static int splittingStep_FullRHS(const ARKodeMem ark_mem, const sunrealtype t,
/*---------------------------------------------------------------
This routine performs a sequential operator splitting method
---------------------------------------------------------------*/
static int splittingStep_SequentialMethod(const int i, const N_Vector y,
void* const user_data)
static int splittingStep_SequentialMethod(const ARKodeMem ark_mem,
const ARKodeSplittingStepMem step_mem,
const int i, const N_Vector y)
{
ARKodeMem ark_mem = (ARKodeMem)user_data;
ARKodeSplittingStepMem step_mem = NULL;
const int retval = splittingStep_AccessStepMem(ark_mem, __func__, &step_mem);
if (retval != ARK_SUCCESS) { return (retval); }

const SplittingStepCoefficients coefficients = step_mem->coefficients;

#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG
Expand Down Expand Up @@ -312,11 +291,26 @@ static int splittingStep_TakeStep(const ARKodeMem ark_mem,

const SplittingStepCoefficients coefficients = step_mem->coefficients;

return step_mem->policy->execute(step_mem->policy,
splittingStep_SequentialMethod, ark_mem->yn,
ark_mem->ycur, ark_mem->tempv1,
coefficients->alpha,
coefficients->sequential_methods, ark_mem);
N_VScale(ONE, ark_mem->yn, ark_mem->ycur);
retval = splittingStep_SequentialMethod(ark_mem, step_mem, 0, ark_mem->ycur);
if (retval != ARK_SUCCESS) { return retval; }

if (coefficients->alpha[0] != ONE)
{
N_VScale(coefficients->alpha[0], ark_mem->ycur, ark_mem->ycur);
}

for (int i = 1; i < coefficients->sequential_methods; i++)
{
N_VScale(ONE, ark_mem->yn, ark_mem->tempv1);
retval = splittingStep_SequentialMethod(ark_mem, step_mem, i,
ark_mem->tempv1);
if (retval != ARK_SUCCESS) { return retval; }
N_VLinearSum(ONE, ark_mem->ycur, coefficients->alpha[i], ark_mem->tempv1,
ark_mem->ycur);
}

return ARK_SUCCESS;
}

/*---------------------------------------------------------------
Expand Down Expand Up @@ -382,11 +376,6 @@ static void splittingStep_Free(const ARKodeMem ark_mem)
{
free(step_mem->steppers);
free(step_mem->n_stepper_evolves);
if (step_mem->own_policy)
{
ARKodeSplittingExecutionPolicy_Free(&step_mem->policy);
}

SplittingStepCoefficients_Free(step_mem->coefficients);
free(step_mem);
}
Expand Down Expand Up @@ -451,9 +440,6 @@ static int splittingStep_SetDefaults(const ARKodeMem ark_mem)
retval = splittingStep_SetOrder(ark_mem, 0);
if (retval != ARK_SUCCESS) { return retval; }

if (step_mem->own_policy) { free(step_mem->policy); }
step_mem->own_policy = SUNFALSE;

/* TODO(SBR): This may cause issues if a user calls ARKodeSetDefaults. This
* issues affects other ARKODE steppers as well */
ARKodeSetInterpolantType(ark_mem, ARK_INTERP_LAGRANGE);
Expand Down Expand Up @@ -537,7 +523,6 @@ void* SplittingStepCreate(SUNStepper* const steppers, const int partitions,
memcpy(step_mem->steppers, steppers, partitions * sizeof(*steppers));

step_mem->coefficients = NULL;
step_mem->policy = NULL;
step_mem->n_stepper_evolves = calloc(partitions,
sizeof(*step_mem->n_stepper_evolves));
if (step_mem->n_stepper_evolves == NULL)
Expand All @@ -549,7 +534,6 @@ void* SplittingStepCreate(SUNStepper* const steppers, const int partitions,
}
step_mem->partitions = partitions;
step_mem->order = 0;
step_mem->own_policy = SUNFALSE;

/* Attach step_mem structure and function pointers to ark_mem */
ark_mem->step_init = splittingStep_Init;
Expand Down Expand Up @@ -625,35 +609,6 @@ int SplittingStep_SetCoefficients(void* const arkode_mem,
return ARK_SUCCESS;
}

/*---------------------------------------------------------------
Sets the execution policy.
---------------------------------------------------------------*/
int SplittingStep_SetExecutionPolicy(void* const arkode_mem,
ARKodeSplittingExecutionPolicy policy)
{
ARKodeMem ark_mem = NULL;
ARKodeSplittingStepMem step_mem = NULL;
int retval = splittingStep_AccessARKODEStepMem(arkode_mem, __func__, &ark_mem,
&step_mem);
if (retval != ARK_SUCCESS) { return (retval); }

if (policy == NULL)
{
arkProcessError(ark_mem, ARK_ILL_INPUT, __LINE__, __func__, __FILE__,
"The execution policy must be non-NULL");
return ARK_ILL_INPUT;
}

if (step_mem->own_policy)
{
ARKodeSplittingExecutionPolicy_Free(&step_mem->policy);
}
step_mem->policy = policy;
step_mem->own_policy = SUNFALSE;

return ARK_SUCCESS;
}

int SplittingStep_GetNumEvolves(void* const arkode_mem, const int partition,
long int* const evolves)
{
Expand Down
35 changes: 0 additions & 35 deletions src/arkode/arkode_splittingstep_executionpolicy.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/arkode/arkode_splittingstep_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ typedef struct ARKodeSplittingStepMemRec
{
SUNStepper* steppers;
SplittingStepCoefficients coefficients;
ARKodeSplittingExecutionPolicy policy;
long int* n_stepper_evolves;

int partitions;
int order;
sunbooleantype own_policy;
}* ARKodeSplittingStepMem;

#endif
Loading

0 comments on commit 1d35b62

Please sign in to comment.