CosmoCoffee Forum Index CosmoCoffee

 
 FAQFAQ   SearchSearch  MemberlistSmartFeed   MemberlistMemberlist    RegisterRegister 
   ProfileProfile   Log inLog in 
Arxiv New Filter | Bookmarks & clubs | Arxiv ref/author:

Segmentation fault when using PowerAt
 
Post new topic   Reply to topic    CosmoCoffee Forum Index -> Computers and software
View previous topic :: View next topic  
Author Message
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 04 2017  Reply with quote

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
Back to top
View user's profile  
Antony Lewis



Joined: 23 Sep 2004
Posts: 1278
Affiliation: University of Sussex

PostPosted: April 04 2017  Reply with quote

I would compare what you've done with e.g. what's done in the supplied wl.f90.
Back to top
View user's profile [ Hidden ] Visit poster's website
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 05 2017  Reply with quote

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
Back to top
View user's profile  
Luke Hart



Joined: 13 Jul 2015
Posts: 25
Affiliation: University of Manchester

PostPosted: April 05 2017  Reply with quote

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
Back to top
View user's profile  
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 06 2017  Reply with quote

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!
Back to top
View user's profile  
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 14 2017  Reply with quote

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
Back to top
View user's profile  
Antony Lewis



Joined: 23 Sep 2004
Posts: 1278
Affiliation: University of Sussex

PostPosted: April 14 2017  Reply with quote

Are you setting needs_nonlinear_pk?
Back to top
View user's profile [ Hidden ] Visit poster's website
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 14 2017  Reply with quote

Dear Antony,

yes I am setting needs_nonlinear_pk, in the following way. My new likelihood is defined in My.f90 by:
Code:
type, extends(TCosmoCalcLikelihood) :: MyLikelihood
logical :: use_non_linear_pk

and it contains the subroutine:
Code:
subroutine MyLikelihood_Add(LikeList, Ini)

where I declare the pointer:
Code:
Type(MyLikelihood), pointer :: this

Next I have the following if-clause:
Code:
      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
Back to top
View user's profile  
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 14 2017  Reply with quote

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:
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
Back to top
View user's profile  
Antony Lewis



Joined: 23 Sep 2004
Posts: 1278
Affiliation: University of Sussex

PostPosted: April 18 2017  Reply with quote

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.
Back to top
View user's profile [ Hidden ] Visit poster's website
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 39
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: April 18 2017  Reply with quote

Thanks Antony, I set this%needs_nonlinear_pk and it now works
Back to top
View user's profile  
Display posts from previous:   
Post new topic   Reply to topic    CosmoCoffee Forum Index -> Computers and software All times are GMT + 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group. Sponsored by WordWeb online dictionary and dictionary software.