Segmentation fault when using PowerAt

Use of Healpix, camb, CLASS, cosmomc, compilers, etc.
Post Reply
Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 04 2017

Hi Antony & everyone else!

I am writing a new likelihood which requires calling CAMB to get the theoretical matter power spectrum through the function PowerAt. However, the code runs into a segmentation fault the moment it tries to call PowerAt within my likelihood (forrtl: severe (174): SIGSEGV, segmentation fault occurred). Do you have any idea why this might be happening? Note that I DON'T incur into the error "ERROR: PowerAt least one of your PK arrays is not initialized:" defined in line 62 of CosmoTheory.f90, and I checked that the code is indeed entering the PowerAt function, but failing to compute the theoretical power spectrum.

A few other details which might be useful:
-I am calling through PowerAt as follows: pkz=PK%PowerAt(klimber,z0), where klimber and z0 are the wavenumber and redshift of interest respectively and are defined as real(mcp), allocatable (I check both klimber and z0 store the correct values), same as pkz
-PK is defined as Type(TCosmoTheoryPK), pointer :: PK

I tried also adding the following line:
PK=>Theory%MPK
where Theory is defined as follows:
Class(TCosmoTheoryPredictions), target :: Theory
However, I get the following error during compilation:
An entity declared with the CLASS keyword shall be a dummy argument or have the ALLOCATABLE or POINTER attribute.

I tried debugging with gdb but did not discover anything more than what I already knew...

Any ideas on what might be going on is really appreciated!

Cheers,
Sunny

Antony Lewis
Posts: 1364
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Segmentation fault when using PowerAt

Post by Antony Lewis » April 04 2017

I would compare what you've done with e.g. what's done in the supplied wl.f90.

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 05 2017

Hi Antony,

thanks for your answer. I do still have a question after checking wl.f90.

It looks like my problem might be due to the fact that PK%x, PK%y, PK%nx, PK%ny, PK%z are not initialized or defined before I try calling PK%PowerAt. However, in wl.f90 it's not at all clear to me how these are initialized/defined in first place. The only points in wl.f90 where these variables enter are:
line 264: num_z = PK%ny
line 265: khmin = exp(PK%x(1))
line 266: khmax = exp(PK%x(PK%nx))
line 276 and line 318: z = PK%y(iz)
line 281: call r_z%Init(PK%y,r,n=num_z)
line 282: call r_z%Init(PK%y,r,n=num_z)

but in none of these lines does it seem to me like these variables are ever initialized/defined. Am I missing something, like are they initialized/defined elsewhere in order to then be able to call PowerAt properly, and where it this happening?

Thanks so much! Cheers,
Sunny

Luke Hart
Posts: 39
Joined: July 13 2015
Affiliation: University of Manchester

Segmentation fault when using PowerAt

Post by Luke Hart » April 05 2017

Hey Sunny!

This may be obvious but I just checked and those variables crop up in Calculator_CAMB.f90 as well. Is there a possibility these initialisation errors could crop up in the read in from CosmoMC to CAMB? or possibly even in the Set Def of the params before reading from ini?

Luke

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 06 2017

Update: has been solved by following the steps in http://cosmocoffee.info/viewtopic.php?t=2395 , I was missing some initialization step. Thanks for the help!

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 14 2017

Hi again Antony, Luke, all,

whereas I solved the problem above basically copying what wl.f90 did, I still have a problem. I have no problems in calling the linear power spectrum, whereas I cannot call the non-linear (Halofit-corrected) one.

In other words, I can allocate Theory%MPK (if I print "allocated(Theory%MPK)" this results in True), but I cannot allocate Theory%NL_MPK (if I print "allocated(Theory%NL_MPK)" this results in False).

Any idea why this might be happening, i.e. why I can allocate MPK but not NL_MPK?

Thanks a lot!!
Sunny

Antony Lewis
Posts: 1364
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Segmentation fault when using PowerAt

Post by Antony Lewis » April 14 2017

Are you setting needs_nonlinear_pk?

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 14 2017

Dear Antony,

yes I am setting needs_nonlinear_pk, in the following way. My new likelihood is defined in My.f90 by:

Code: Select all

type, extends(TCosmoCalcLikelihood) :: MyLikelihood
logical :: use_non_linear_pk
and it contains the subroutine:

Code: Select all

subroutine MyLikelihood_Add(LikeList, Ini)
where I declare the pointer:

Code: Select all

Type(MyLikelihood), pointer :: this
Next I have the following if-clause:

Code: Select all

      if (Ini%Read_Logical('use_My,.false.)) then
         nonlinear = Ini%Read_Logical('My_use_non_linear',.true.)
         allocate(this)
         this%LikelihoodType = 'My'
         this%name= Ini%Read_String('My_name')
         this%needs_powerspectra = .true.
         this%use_non_linear_pk = nonlinear
[...bunch of other stuff...]
         call LikeList%Add(this)
      end if
I checked that when in batch2/My.ini I set My_use_non_linear = F, I can successfully allocate Theory%MPK, but the moment I set it to T or, alternatively, set nonlinear=.true. in the if-clause above, I get a segmentation fault because the code is not able to allocate Theory%NL_MPK. Any idea why this is happening?

Thanks!
Sunny

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 14 2017

One more clarification: after the code reads this%reads_non_linear_pk, I actually try to allocate Theory%NL_MPK in the module computing the theoretical value of my observable (the equivalent of get_convergence in wl.f90 for example!) in the following way:

Code: Select all

if (this%use_non_linear_pk) then
      if (this%use_non_linear_pk) then
         PK => Theory%NL_MPK
      else
         PK => Theory%MPK
      end if
end if
Sunny

Antony Lewis
Posts: 1364
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Segmentation fault when using PowerAt

Post by Antony Lewis » April 18 2017

That is assigning a pointer not allocating.

It looks like you are setting your own this%use_non_linear_pk variable but not the inherited this%needs_nonlinear_pk which the code uses whether to calculate non-linear things.

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Segmentation fault when using PowerAt

Post by Sunny Vagnozzi » April 18 2017

Thanks Antony, I set this%needs_nonlinear_pk and it now works

Post Reply