Skip to content

Commit

Permalink
fluids: Move smartsim things to header file
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwrigh committed Apr 25, 2023
1 parent 9ea59c5 commit ca41b51
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
33 changes: 33 additions & 0 deletions examples/fluids/include/smartsim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors.
// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
//
// SPDX-License-Identifier: BSD-2-Clause
//
// This file is part of CEED: http://github.com/ceed

#include <c_client.h>
#include <petscsys.h>
#include <sr_enums.h>

#if defined(__clang_analyzer__)
void SmartRedisCall(SRError);
#else
#define SmartRedisCall(...) \
do { \
SRError ierr_smartredis_call_q_; \
PetscStackUpdateLine; \
ierr_smartredis_call_q_ = __VA_ARGS__; \
if (PetscUnlikely(ierr_smartredis_call_q_ != SRNoError)) \
SETERRQ(PETSC_COMM_SELF, ierr_smartredis_call_q_, "SmartRedis Error (Code %d): %s", ierr_smartredis_call_q_, SRGetLastError()); \
} while (0)
#endif

static PetscErrorCode SmartRedisVerifyPutTensor(void *c_client, const char *name, const size_t name_length) {
bool does_exist = false;
PetscFunctionBeginUser;

SmartRedisCall(tensor_exists(c_client, name, name_length, &does_exist));
PetscCheck(does_exist, PETSC_COMM_SELF, -1, "Tensor of name '%s' was not written to the database successfully", name);

PetscFunctionReturn(0);
}
26 changes: 1 addition & 25 deletions examples/fluids/src/smartsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,10 @@
// This file is part of CEED: http://github.com/ceed
// Based on the instructions from https://www.craylabs.org/docs/sr_integration.html and PHASTA implementation

#include <c_client.h>
#include <sr_enums.h>
#include "../include/smartsim.h"

#include "../navierstokes.h"

#if defined(__clang_analyzer__)
void SmartRedisCall(SRError);
#else
#define SmartRedisCall(...) \
do { \
SRError ierr_smartredis_call_q_; \
PetscStackUpdateLine; \
ierr_smartredis_call_q_ = __VA_ARGS__; \
if (PetscUnlikely(ierr_smartredis_call_q_ != SRNoError)) \
SETERRQ(PETSC_COMM_SELF, ierr_smartredis_call_q_, "SmartRedis Error (Code %d): %s", ierr_smartredis_call_q_, SRGetLastError()); \
} while (0)
#endif

static PetscErrorCode SmartRedisVerifyPutTensor(void *c_client, const char *name, const size_t name_length) {
bool does_exist = false;
PetscFunctionBeginUser;

SmartRedisCall(tensor_exists(c_client, name, name_length, &does_exist));
PetscCheck(does_exist, PETSC_COMM_SELF, -1, "Tensor of name '%s' was not written to the database successfully", name);

PetscFunctionReturn(0);
}

PetscErrorCode SmartSimTrainingSetup(User user) {
SmartSimData smartsim = user->smartsim;
PetscMPIInt rank;
Expand Down

0 comments on commit ca41b51

Please sign in to comment.