Skip to content

Commit

Permalink
Merge pull request dacelib#44 from abgandar/master
Browse files Browse the repository at this point in the history
branch predictors and storage qualifiers
  • Loading branch information
abgandar authored Oct 22, 2022
2 parents 2bda904 + 7a56659 commit df6901c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Tutorials/Tutorial2/1Basics-Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ int main( void )
cout << "Exercise 1.2.2: Breaking bad\n"
<< ex1_2_2( 0.0, 0.0 ) << endl
<< ex1_2_2( x, y ) << endl;
} catch( exception &ex ) { cout << ex.what( ) << endl; }
} catch( exception const& ex ) { cout << ex.what( ) << endl; }
}
12 changes: 6 additions & 6 deletions core/daceaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void daceDecode(const unsigned int jc, unsigned int jj[])
\param[in] cc C array of nmmax monomials
\param[in] inc Pointer to DA object to pack the monomials into
*/
void dacePack(double cc[], DACEDA *inc)
void dacePack(double cc[restrict], DACEDA *restrict inc)
{
monomial *ipoc; unsigned int ilmc, illc;

Expand All @@ -350,7 +350,7 @@ void dacePack(double cc[], DACEDA *inc)
{
for(unsigned int i = 0; i < DACECom.nmmax; i++)
{
if(!(fabs(cc[i]) <= DACECom_t.eps)) // && (DACECom.ieo[i] <= DACECom_t.nocut) is avoided for performance
if(LIKELY(!(fabs(cc[i]) <= DACECom_t.eps))) // && (DACECom.ieo[i] <= DACECom_t.nocut) is avoided for performance
{
ic->ii = i;
ic->cc = cc[i];
Expand All @@ -363,9 +363,9 @@ void dacePack(double cc[], DACEDA *inc)
{
for(unsigned int i = 0; i < DACECom.nmmax; i++)
{
if(!(fabs(cc[i]) <= DACECom_t.eps) && DACECom.ieo[i] <= DACECom_t.nocut) // here we remove also cut orders to save as much space as possible
if(LIKELY(!(fabs(cc[i]) <= DACECom_t.eps) && DACECom.ieo[i] <= DACECom_t.nocut)) // here we remove also cut orders to save as much space as possible
{
if(ic >= ipoc+ilmc)
if(UNLIKELY(ic >= ipoc+ilmc))
{
daceSetError(__func__, DACE_ERROR, 21);
for(unsigned int j = i; j < DACECom.nmmax; j++) cc[j] = 0.0;
Expand All @@ -384,9 +384,9 @@ void dacePack(double cc[], DACEDA *inc)
{
for(unsigned int i = 0; i < DACECom.nmmax; i++)
{
if((DACECom.ifi[i] != 0) && !(fabs(cc[i]) <= DACECom_t.eps) && (DACECom.ieo[i] <= DACECom_t.nocut))
if(LIKELY((DACECom.ifi[i] != 0) && !(fabs(cc[i]) <= DACECom_t.eps) && (DACECom.ieo[i] <= DACECom_t.nocut)))
{
if(ic >= ipoc+ilmc)
if(UNLIKELY(ic >= ipoc+ilmc))
{
daceSetError(__func__, DACE_ERROR, 21);
for(unsigned int j = 0; j < DACECom.nmmax; j++) cc[j] = 0.0;
Expand Down
10 changes: 5 additions & 5 deletions core/dacemath.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void daceMultiply(const DACEDA *ina, const DACEDA *inb, DACEDA *inc)
ipbeg[i] = emb + daceCountMonomials(i - 1, DACECom.nvmax);
}
#else
static DACE_THREAD_LOCAL double *cc = NULL;
static DACE_THREAD_LOCAL double *restrict cc = NULL;
static DACE_THREAD_LOCAL extended_monomial *emb = NULL;
static DACE_THREAD_LOCAL extended_monomial **ipbeg = NULL;
static DACE_THREAD_LOCAL extended_monomial **ipend = NULL;
Expand Down Expand Up @@ -171,18 +171,18 @@ void daceMultiply(const DACEDA *ina, const DACEDA *inb, DACEDA *inc)
for(unsigned int i = 0; i <= DACECom_t.nocut; i++) ipend[i] = ipbeg[i];

// sort vector b by order
for(monomial *ib = ipob; ib < ipob+illb; ib++)
for(const monomial *ib = ipob; ib < ipob+illb; ib++)
{
const unsigned int noib = DACECom.ieo[ib->ii];
if(noib > DACECom_t.nocut) continue;
if(UNLIKELY(noib > DACECom_t.nocut)) continue;
ipend[noib]->i1 = DACECom.ie1[ib->ii];
ipend[noib]->i2 = DACECom.ie2[ib->ii];
ipend[noib]->cc = ib->cc;
ipend[noib]++;
}

// perform actual multiplication
for(monomial *ia = ipoa; ia < ipoa+illa; ia++)
for(const monomial *ia = ipoa; ia < ipoa+illa; ia++)
{
const unsigned int i1ia = DACECom.ie1[ia->ii];
const unsigned int i2ia = DACECom.ie2[ia->ii];
Expand All @@ -191,7 +191,7 @@ void daceMultiply(const DACEDA *ina, const DACEDA *inb, DACEDA *inc)
//#pragma omp parallel for
for(int noib = DACECom_t.nocut-DACECom.ieo[ia->ii]; noib >= 0; noib--)
{
for(extended_monomial *ib = ipbeg[noib]; ib < ipend[noib]; ib++)
for(const extended_monomial *ib = ipbeg[noib]; ib < ipend[noib]; ib++)
{
const unsigned int ic = DACECom.ia1[i1ia+ib->i1] + DACECom.ia2[i2ia+ib->i2];
cc[ic] += ccia*ib->cc;
Expand Down
2 changes: 1 addition & 1 deletion core/include/dace/daceaux.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ unsigned int daceNextOrderedMonomial(unsigned int p[], const unsigned int no, co
// internal routines
void daceInitializeThread0();
void daceSetError(const char *c, const unsigned int ix, const unsigned int iyy);
void dacePack(double cc[], DACEDA *inc);
void dacePack(double cc[restrict], DACEDA *restrict inc);
void daceMultiplicativeInverse0(const DACEDA *ina, DACEDA *inc, const double a0);
int BesselWrapper(const double x, const int n0, const int n1, const int type, double *bz);
int ModifiedBesselWrapper(const double x, const int n0, const int n1, const int type, double *bz);
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cxx/DA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void DA::init(const unsigned int ord, const unsigned int nvar) {
*/
try {
checkVersion();
} catch(DACEException ex) {
} catch(DACEException const& ex) {
std::cerr << ex << std::endl;
std::terminate(); }
daceInitialize(ord,nvar);
Expand Down

0 comments on commit df6901c

Please sign in to comment.