CosmoMC: Likelihood Function

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Paniez Paykari
Posts: 14
Joined: June 08 2007
Affiliation: CEA

CosmoMC: Likelihood Function

Post by Paniez Paykari » March 15 2010

Hi All,

I need to make a few changes to CosmoMC so that it calculates the likelihood function of [tex]C_l[/tex]s in another space, e.g. [tex]w*C_l[/tex] (where w is a dictionary; could be PCA or something). Apart from the changes that I need to make in the cmbdata.F90 file, is there any other changes I need to make? (I only care about CMB data)
Does anyone know? I appreciate your help.

Many thanks,
Paniez

Paniez Paykari
Posts: 14
Joined: June 08 2007
Affiliation: CEA

CosmoMC: Likelihood Function

Post by Paniez Paykari » March 15 2010

Also, does anyone know if we can call C++/IDL programs from Fortran?
(The programs that take my [tex]C_l[/tex] to [tex]w*C_l[/tex] are in C++/IDL)

Thanks,
Paniez

Pascal Vaudrevange
Posts: 50
Joined: March 26 2006
Affiliation: DESY
Contact:

CosmoMC: Likelihood Function

Post by Pascal Vaudrevange » March 18 2010

Hi Paniez,

as far as I know, calling C++ from Fortran is a bit tricky. However, it is possible to call C from Fortran, see the attached .tgz file for an example. The files will be unpacked into the current working directory. Compile them with "make".

Download here: f90c.tgz

Pascal

Tess Jaffe
Posts: 7
Joined: March 11 2005
Affiliation: Centre d'Etude Spatiale des Rayonnements

CosmoMC: Likelihood Function

Post by Tess Jaffe » March 19 2010

I've used cosmomc as a sample calling a C++ likelihood function, though the function call itself is not different from a C function, so maybe that's why it's easy. (Caveat: I have no idea what I'm doing. I just google and hack around until it works.) Basically, I add to my C++ code the following definition:

Code: Select all

extern "C" {
int my_like_(float *inparams,int *n_params, float *lnlike ) {
  my_like(inparams,n_params,lnlike);
  return(0);
}
}
where my_like() is the C++ function. That object can then be linked while compiling cosmomc with the addition of the -cxxlib or -lstdc++ flag (depending on the compiler, apparently) and called in the Fortran as

Code: Select all

call my_like(Params%P,num_hard,thisval)
I've done this variously with ifort and gfortran (4.3+) on Linux and Mac OS X.

I have not, however, ever tried to do this intelligently, calling a C++ class function from Fortran, where the class object is kept around between samples rather than starting from scratch each time. It would make my life easier if I could, so if anybody has an example of that, I'd like to see it.

Paniez Paykari
Posts: 14
Joined: June 08 2007
Affiliation: CEA

CosmoMC: Likelihood Function

Post by Paniez Paykari » March 25 2010

Thanks so much to both of you. I will test them.

Regards
Paniez

Post Reply