Cuba library on Arm64 Mac

Viewed 31

I'm switching from an old Intel 86-64 MacBook Air to a new M1 MacBook Pro. I'm having some problems using the library Cuba, in particular the (ll)Vegas integrator: while on the former pc everything was working properly, while in the latter (with the same compiler g++-12 and the same extra libraries required for my code) I get a generic "segmentation fault" kind of error, after a bunch of "nan" results from integration. The very same code on the older pc was working just fine, so I guess it may be due to architecture in some way. I found people suggesting to increase nstart and nincrease parameters of the used integrator by an order of magnitude or so, but nothing changes.

I'm using a brew-installed gcc version of g++-12 as mentioned, running on macOS Monterey version 12.3

Thanks everyone!

Edit 1: I'm adding the reduced code as well as the error message.

#include <stdlib.h>
#include <stdexcept>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>    // std::min
#include <math.h>
#include <cmath> 
#include <memory>
#include <boost/multiprecision/float128.hpp>
#include <boost/math/special_functions/bessel.hpp>
#include "cuba.h"
#include "gsl/gsl_rng.h"         // scan 

using boost::multiprecision::float128;
// ----------------------------------------------------- Physical constants
double eps2, qf, qD, mf, delta;
double T,sminima,spminima,saminima;
double TCB,Tfo;
double ma,mA,mAY,mZhatY,mAL,mZhatL;
double gfLAY,gfLZY,guLAY,guLZY,gdLAY,gdLZY,gfRAY,gfRZY,guRAY,guRZY,gdRAY,gdRZY,gnuLAY,gnuLZY,gXAY,gXZY,eps2Y;
double gfLAL,gfLZL,guLAL,guLZL,gdLAL,gdLZL,gfRAL,gfRZL,guRAL,guRZL,gdRAL,gdRZL,gnuLAL,gnuLZL,gXAL,gXZL,eps2L;

#define mX 0.01
#define m mX

#define s0 2970
#define rhocr 1.054e-05 
#define T0 2.32e-13 //2.7 Kelvin in GeV 
#define Tfr (mX/10.)    // freeze-out temperature, xfr = 10
#define TCMB T0*(1) //CMB formation

#define mnu 1.e-9 // neutrino mass
#define mqt 173.21
#define mqb 4.18
#define mqc 1.27
#define mqs 96.e-3
#define mqd 4.7e-3
#define mqu 2.2e-3
#define mpionC 139.57e-3
#define mpion0 134.98e-3
#define mtau 1.78
#define mmu 105.66e-3
#define me 0.51e-3
#define mZ 91.19
#define mW 80.38
#define mH 125.09

#define pi 3.1415927
#define MP 1.22e19
#define qe  0.303 

#define gquark 12.
#define ggluon 2.
#define Lqcd 0.217
#define gpion 3.
#define gchargedlepton 4.
#define gneutrino 2.
#define gmassiveboson 3.
#define gmasslessboson 2.
#define gscalar 1.

#define cW 0.8815
#define sW 0.4721
#define thetaW 0.4917 //radiant

// step function
int StepF(double x) {

  int step;
    if (x > 0.) {step = 1.;}
    else { step = 0.;}

  return step;
}

// dof function
double gstar(double x, int i) {
  /* function computing the 2 effective d.o.f
   i=1: ge, i=2:gs 
   */
 double TnuoT, res;

  if (x > me) {
    TnuoT = 1.; 
   }
  else {
    if (i == 1) {TnuoT = pow(4./11,4./3);}
    else if (i == 2) {TnuoT = 4./11;}
   } 

  res = StepF(x-Lqcd)*( gmasslessboson + 8.*ggluon + 7./8.*gquark*( StepF(x-mqt) + StepF(x-mqb) + StepF(x-mqc) + StepF(x-mqs) + StepF(x-mqd) + StepF(x-mqu) ) + gscalar*(StepF(x-mH) ) + gmassiveboson*( StepF(x-mA) + StepF(x-mZ) + 2.*StepF(x-mW) ) + 7./8.*( gchargedlepton*( StepF(x-me) + StepF(x-mmu) + StepF(x-mtau) ) + 3.*gneutrino + gneutrino*StepF(x-mX) ) ) + 
        StepF(Lqcd-x)*( gmasslessboson + gmassiveboson*StepF(x-mA) + gpion*( 2.*StepF(x-mpionC) + StepF(x-mpion0)) + 7./8.*(gchargedlepton*( StepF(x-me) + StepF(x-mmu)) + 3.*gneutrino*TnuoT + gneutrino*StepF(x-mX) ) ); 
  return res;

}

// bessel functions
template <class T1, class T2>
long double cyl_bessel_k(T1 v, T2 x){
  long double result;

  result = cyl_bessel_k(v, x);
  return result;
}

double Power(double x, double y){
  return pow(x,y);
}

double Sqrt(double x){
  return sqrt(x);
}

// ----------------------------------------------------- Gamma_A' U(1)_em x U(1)_d
double GammaA(double massA) {
double tw = 0.;

  double PSe = 0.; 
if(massA>2.*me)
  PSe = eps2*pow(qe*qf,2.)*(1.+2.*me*me/(massA*massA))*sqrt(1.-4.*me*me/(massA*massA));
  else PSe = 0.;

  double PSmu = 0.; 
if(massA>2.*mmu)
  PSe = eps2*pow(qe*qf,2.)*(1.+2.*mmu*mmu/(massA*massA))*sqrt(1.-4.*mmu*mmu/(massA*massA));
  else PSmu = 0.;

  double PStau = 0.; 
if(massA>2.*mtau)
  PStau = eps2*pow(qe*qf,2.)*(1.+2.*mtau*mtau/(massA*massA))*sqrt(1.-4.*mtau*mtau/(massA*massA));
  else PStau = 0.;

  double PSqu = 0.; 
if(massA>2.*mqu)
  PSqu = eps2*Power(qe*qf*2./3.,2)*(1.+2.*mqu*mqu/(massA*massA))*sqrt(1.-4.*mqu*mqu/(massA*massA));
  else PSqu = 0.;

  double PSqc = 0.; 
if(massA>2.*mqc)
  PSqc = eps2*Power(qe*qf*2./3.,2)*(1.+2.*mqc*mqc/(massA*massA))*sqrt(1.-4.*mqc*mqc/(massA*massA));
  else PSqc = 0.;

  double PSqt = 0.; 
if(massA>2.*mqt)
  PSqt = eps2*Power(qe*qf*2./3.,2)*(1.+2.*mqt*mqt/(massA*massA))*sqrt(1.-4.*mqt*mqt/(massA*massA));
  else PSqt = 0.;

  double PSqd = 0.; 
if(massA>2.*mqd)
  PSqd = eps2*Power(qe*qf*1./3.,2)*(1.+2.*mqd*mqd/(massA*massA))*sqrt(1.-4.*mqd*mqd/(massA*massA));
  else PSqd = 0.;

  double PSqs = 0.; 
if(massA>2.*mqs)
  PSqs = eps2*Power(qe*qf*1./3.,2)*(1.+2.*mqs*mqs/(massA*massA))*sqrt(1.-4.*mqs*mqs/(massA*massA));
  else PSqs = 0.;

  double PSqb = 0.; 
if(massA>2.*mqb)
  PSqb = eps2*Power(qe*qf*1./3.,2)*(1.+2.*mqb*mqb/(massA*massA))*sqrt(1.-4.*mqb*mqb/(massA*massA));
  else PSqb = 0.;

  double PSX = 0.; 
if(massA>2.*mX)
  PSX = qD*qD*(1.+2.*mX*mX/(massA*massA))*sqrt(1.-4.*mX*mX/(massA*massA));
  else PSX = 0.;

tw = massA/4./pi*( PSe + PSmu + PStau + PSX + 3.*(PSqu + PSqc + PSqt + PSqd + PSqs + PSqb)) ;
  return tw;
}

// ----------------------------------------------------- Integral XX -> ee (em x d)
static int IntegrandEXXee(const int *ndim, const double xx[],
             const int *ncomp, double ff[], void *userdata)

{

sminima  = 4.*m*m;

#define st1  xx[1]   // x
#define Tt1  xx[0]   // y
#define f1   ff[0]      // integrand: factor of yield

#define Tmax1 Tfr
#define Tmin1 T0

#define smax1  1000
#define smin1  sminima

#define T1    (Tmin1*exp( Tt1*log(Tmax1/Tmin1) ))
#define JacT1 (Tmin1*log(Tmax1/Tmin1)*exp(Tt1*log(Tmax1/Tmin1)))

#define s1    (smin1*exp( st1*log(smax1/smin1) ))
#define JacS1 (smin1*log(smax1/smin1)*exp(st1*log(smax1/smin1)))

long double func1;
long double neqX       = gchargedlepton*mX*mX*T1*boost::math::cyl_bessel_k(2, mX/T1)/(2.*pi*pi);
long double sigma_XXff = Power(qe*qf*qD,2)*eps2*(s1+2.*m*m)*(s1+2.*mf*mf)*Sqrt(1-4.*mf*mf/s1)/(12.*pi*s1*Sqrt(1-4.*m*m/s1)*(Power(s1-mA*mA,2)+mA*mA*GammaA(mA)*GammaA(mA)));

func1 = JacT1 * JacS1;
func1 = func1 * Sqrt(pi/45) * MP * 2. * Power(pi,2.) * gchargedlepton/ Power(2.*pi,6.);
func1 = func1 * gstar(T1,2) * T1 /(sqrt(gstar(T1,1)) * neqX * neqX);
func1 = func1 * (sqrt(s1) * boost::math::cyl_bessel_k(1, sqrt(s1)/T1) * (s1-4.*m*m) * sigma_XXff);
f1 = func1;

return 0;
 }

// ----------------------------------------------------- Common parameters
#define ndim 2
#define ncomp 1
#define userdata NULL
#define epsrel 1.e-1
#define epsabs 0
#define flags 6
//#define VERBOSE 2
//#define LAST 4
#define seed 1
#define mineval 1000
#define maxeval 300000
#define statefile NULL
// ----------------------------------------------------- Vegas-specific parameters
#define nstart 10000
#define nincrease 5000
#define nbatch 1000
#define gridno 1

int main(int numb, char** array) 
{

  double xtest;
  long long int neval;
  int fail;
  double integralEXXee[ncomp], errorEXXee[ncomp],probEXXee[ncomp];
  double numbd;
  int nregions;
  
  #define resultXXee  integralEXXee[0]
  #define errorXXee   errorEXXee[0]   

  qD    = 1.;           
  qf    = 1.;
  mA    = 1.e-1;
  eps2  = 1.e-8;

  double neqX = gchargedlepton*mX*mX*Tfr*boost::math::cyl_bessel_k(2, mX/Tfr)/(2.*pi*pi);
  double stot = 2.*pi*pi/45.*gstar(Tfr,2)*Tfr*Tfr*Tfr;

  llVegas(ndim, ncomp, IntegrandEXXee, userdata, 1 /* nvec */,
    epsrel, epsabs, flags, seed, mineval, maxeval, nstart, nincrease, 
  nbatch, gridno, statefile, NULL,&neval, &fail, integralEXXee, errorEXXee, probEXXee);
  }

error I get on m1:

Iteration 1:  10000 integrand evaluations so far
[1] nan +- 2.22056e-18      chisq nan (0 df)
zsh: segmentation fault  ./draft

the same routine works just fine on x86-64

0 Answers
Related