<commit_before>//------------------------------------------------------------------------------------------------------------------------------
// <NAME>
// <EMAIL>
// Lawrence Berkeley National Lab
//------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
//#include<instrinsics.h>
//------------------------------------------------------------------------------------------------------------------------------
#include "timer.h"
#include "defines.h"
#include "level.h"
#include "operators.h"
//------------------------------------------------------------------------------------------------------------------------------
#define __STENCIL_STAR_SHAPED 1
#define __STENCIL_RADIUS      1
#define __STENCIL_VARIABLE_COEFFICIENT
#define __STENCIL_FUSE_BC
//------------------------------------------------------------------------------------------------------------------------------
#ifndef __OMP_COLLAPSE
#define __OMP_COLLAPSE collapse(2)
#endif
//------------------------------------------------------------------------------------------------------------------------------
// FIX... make #define
void apply_BCs(level_type * level, int x_id){
  #ifndef __STENCIL_FUSE_BCs 
  // This is a failure mode if (trying to do communication-avoiding) && (BC!=__BC_PERIODIC)
  apply_BCs_linear(level,x_id);
  #endif
}
//------------------------------------------------------------------------------------------------------------------------------
#ifdef __STENCIL_VARIABLE_COEFFICIENT
  #ifdef __STENCIL_FUSE_BCs                        
    #define __apply_op(x)                                                                        \
    (                                                                                            \
      a*alpha[ijk]*x[ijk] -b*h2inv*(                                                             \
       +beta_i[ijk        ]*( valid[ijk-1      ]*( (x)[ijk] + (x)[ijk-1      ]) - 2.0*(x)[ijk] ) \
       +beta_j[ijk        ]*( valid[ijk-jStride]*( (x)[ijk] + (x)[ijk-jStride]) - 2.0*(x)[ijk] ) \
       +beta_k[ijk        ]*( valid[ijk-kStride]*( (x)[ijk] + (x)[ijk-kStride]) - 2.0*(x)[ijk] ) \
       +beta_i[ijk+1      ]*( valid[ijk+1      ]*( (x)[ijk] + (x)[ijk+1      ]) - 2.0*(x)[ijk] ) \
       +beta_j[ijk+jStride]*( valid[ijk+jStride]*( (x)[ijk] + (x)[ijk+jStride]) - 2.0*(x)[ijk] ) \
       +beta_k[ijk+kStride]*( valid[ijk+kStride]*( (x)[ijk] + (x)[ijk+kStride]) - 2.0*(x)[ijk] ) \
      )                                                                                          \
    )
  #else
    #define __apply_op(x)                                          \
    (                                                              \
      a*alpha[ijk]*x[ijk] -b*h2inv*(                               \
         beta_i[ijk+1      ]*( (x)[ijk+1      ]-(x)[ijk        ] ) \
        -beta_i[ijk        ]*( (x)[ijk        ]-(x)[ijk-1      ] ) \
        +beta_j[ijk+jStride]*( (x)[ijk+jStride]-(x)[ijk        ] ) \
        -beta_j[ijk        ]*( (x)[ijk        ]-(x)[ijk-jStride] ) \
        +beta_k[ijk+kStride]*( (x)[ijk+kStride]-(x)[ijk        ] ) \
        -beta_k[ijk        ]*( (x)[ijk        ]-(x)[ijk-kStride] ) \
      )                                                            \
    )
  #endif
#else
  #error constant coefficient not yet implemented !!!
#endif
//------------------------------------------------------------------------------------------------------------------------------
void rebuild_operator(level_type * level, level_type *fromLevel, double a, double b){
  if(level->my_rank==0){printf("  rebuilding operator for level h=%e: ",level->h);fflush(stdout);}

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // form restriction of alpha[], beta_*[] coefficients from fromLevel
  if(fromLevel != NULL){
    restriction(level,__alpha ,fromLevel,__alpha ,__RESTRICT_CELL  );
    restriction(level,__beta_i,fromLevel,__beta_i,__RESTRICT_FACE_I);
    restriction(level,__beta_j,fromLevel,__beta_j,__RESTRICT_FACE_J);
    restriction(level,__beta_k,fromLevel,__beta_k,__RESTRICT_FACE_K);
  } // else case assumes alpha/beta have been set

<commit_msg>constant/variable coefficent with possibility of fusing BCs<commit_after>//------------------------------------------------------------------------------------------------------------------------------
// <NAME>
// <EMAIL>
// Lawrence Berkeley National Lab
//------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
//#include<instrinsics.h>
//------------------------------------------------------------------------------------------------------------------------------
#include "timer.h"
#include "defines.h"
#include "level.h"
#include "operators.h"
//------------------------------------------------------------------------------------------------------------------------------
#define __STENCIL_STAR_SHAPED 1
#define __STENCIL_RADIUS      1
#define __STENCIL_VARIABLE_COEFFICIENT
#define __STENCIL_FUSE_BC
//------------------------------------------------------------------------------------------------------------------------------
#ifndef __OMP_COLLAPSE
#define __OMP_COLLAPSE collapse(2)
#endif
//------------------------------------------------------------------------------------------------------------------------------
// FIX... make #define
void apply_BCs(level_type * level, int x_id){
  #ifndef __STENCIL_FUSE_BC
  // This is a failure mode if (trying to do communication-avoiding) && (BC!=__BC_PERIODIC)
  apply_BCs_linear(level,x_id);
  #endif
}
//------------------------------------------------------------------------------------------------------------------------------
#ifdef __STENCIL_FUSE_BC

  #ifdef __STENCIL_VARIABLE_COEFFICIENT
    #define __apply_op(x)                                                                           \
    (                                                                                               \
      a*alpha[ijk]*x[ijk] - b*h2inv*(                                                               \
        + beta_i[ijk        ]*( valid[ijk-1      ]*( (x)[ijk] + (x)[ijk-1      ] ) - 2.0*(x)[ijk] ) \
        + beta_j[ijk        ]*( valid[ijk-jStride]*( (x)[ijk] + (x)[ijk-jStride] ) - 2.0*(x)[ijk] ) \
        + beta_k[ijk        ]*( valid[ijk-kStride]*( (x)[ijk] + (x)[ijk-kStride] ) - 2.0*(x)[ijk] ) \
        + beta_i[ijk+1      ]*( valid[ijk+1      ]*( (x)[ijk] + (x)[ijk+1      ] ) - 2.0*(x)[ijk] ) \
        + beta_j[ijk+jStride]*( valid[ijk+jStride]*( (x)[ijk] + (x)[ijk+jStride] ) - 2.0*(x)[ijk] ) \
        + beta_k[ijk+kStride]*( valid[ijk+kStride]*( (x)[ijk] + (x)[ijk+kStride] ) - 2.0*(x)[ijk] ) \
      )                                                                                             \
    )
  #else  // constant coefficient case...  
    #define __apply_op(x)                                    \
    (                                                        \
      a*alpha[ijk]*x[ijk] - b*h2inv*(                        \
        + valid[ijk-1      ]*( (x)[ijk] + (x)[ijk-1      ] ) \
        + valid[ijk-jStride]*( (x)[ijk] + (x)[ijk-jStride] ) \
        + valid[ijk-kStride]*( (x)[ijk] + (x)[ijk-kStride] ) \
        + valid[ijk+1      ]*( (x)[ijk] + (x)[ijk+1      ] ) \
        + valid[ijk+jStride]*( (x)[ijk] + (x)[ijk+jStride] ) \
        + valid[ijk+kStride]*( (x)[ijk] + (x)[ijk+kStride] ) \
                       -12.0*( (x)[ijk]                    ) \
      )                                                      \
    )
  #endif // variable/constant coefficient

#endif


//------------------------------------------------------------------------------------------------------------------------------
#ifndef __STENCIL_FUSE_BC

  #ifdef __STENCIL_VARIABLE_COEFFICIENT
    #define __apply_op(x)                                     \
    (                                                         \
      a*alpha[ijk]*x[ijk] - b*h2inv*(                         \
        + beta_i[ijk+1      ]*( (x)[ijk+1      ] - (x)[ijk] ) \
        + beta_i[ijk        ]*( (x)[ijk-1      ] - (x)[ijk] ) \
        + beta_j[ijk+jStride]*( (x)[ijk+jStride] - (x)[ijk] ) \
        + beta_j[ijk        ]*( (x)[ijk-jStride] - (x)[ijk] ) \
        + beta_k[ijk+kStride]*( (x)[ijk+kStride] - (x)[ijk] ) \
        + beta_k[ijk        ]*( (x)[ijk-kStride] - (x)[ijk] ) \
      )                                                       \
    )
  #else  // constant coefficient case...  
    #define __apply_op(x)              \
    (                                  \
      a*alpha[ijk]*x[ijk] - b*h2inv*(  \
        + (x)[ijk+1      ]             \
        + (x)[ijk-1      ]             \
        + (x)[ijk+jStride]             \
        + (x)[ijk-jStride]             \
        + (x)[ijk+kStride]             \
        + (x)[ijk-kStride]             \
        - (x)[ijk        ]*6.0         \
      )                                \
    )
  #endif // variable/constant coefficient

#endif // BCs


//------------------------------------------------------------------------------------------------------------------------------
void rebuild_operator(level_type * level, level_type *fromLevel, double a, double b){
  if(level->my_rank==0){printf("  rebuilding operator for level h=%e: ",level->h);fflush(stdout);}

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // form restriction of alpha[], beta_*[] coefficients from fromLevel
  if(fromLevel != NULL){
    restriction(level,__alpha ,fromLevel,__alpha ,__RESTRICT_CELL  );
    restriction(level,__beta_i,fromLevel,__beta_i,__RESTRICT_FACE_I);
    restriction(level,__beta_j,fromLevel,__beta_j,__RESTRICT_FACE_J);
    restriction(level,__beta_k,fromLevel,__beta_k,__RESTRICT_FACE_K);
  } // else case assumes alpha/beta have been set


{'fraction_non_alphanumeric': 0.3481081081081081, 'fraction_numerical': 0.0063882063882063885, 'mean_word_length': 0.8491731782664002, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 61, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1447887', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2817, 'n_words': 399}