Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve inlining specifications and fix a few problems #386

Merged
merged 4 commits into from
Aug 21, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tardis/montecarlo/setup_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from glob import glob

if get_distutils_option('with_openmp', ['build', 'install', 'develop']) is not None:
compile_args = ['-fopenmp']
compile_args = ['-fopenmp', '-W', '-Wall', '-Wmissing-prototypes', '-std=c99']
link_args = ['-fopenmp']
define_macros = [('WITHOPENMP', None)]
else:
compile_args = []
compile_args = ['-W', '-Wall', '-Wmissing-prototypes', '-std=c99']
link_args = []
define_macros = []

Expand Down
35 changes: 17 additions & 18 deletions tardis/montecarlo/src/cmontecarlo.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <inttypes.h>
#ifdef WITHOPENMP
#include <omp.h>
#endif
#include "cmontecarlo.h"

rk_state mt_state;

void
static void
initialize_random_kit (unsigned long seed)
{
rk_seed (seed, &mt_state);
}

INLINE tardis_error_t
line_search (double *nu, double nu_insert, int64_t number_of_lines,
tardis_error_t line_search (double *nu, double nu_insert, int64_t number_of_lines,
int64_t * result)
{
tardis_error_t ret_val = TARDIS_ERROR_OK;
Expand All @@ -35,7 +35,7 @@ line_search (double *nu, double nu_insert, int64_t number_of_lines,
return ret_val;
}

inline tardis_error_t
tardis_error_t
reverse_binary_search (double *x, double x_insert,
int64_t imin, int64_t imax, int64_t * result)
{
Expand Down Expand Up @@ -76,7 +76,7 @@ reverse_binary_search (double *x, double x_insert,
return ret_val;
}

inline tardis_error_t
tardis_error_t
binary_search (double *x, double x_insert, int64_t imin,
int64_t imax, int64_t * result)
{
Expand Down Expand Up @@ -121,7 +121,7 @@ binary_search (double *x, double x_insert, int64_t imin,
return ret_val;
}

INLINE double
double
rpacket_doppler_factor (rpacket_t * packet, storage_model_t * storage)
{
return 1.0 -
Expand All @@ -131,7 +131,7 @@ rpacket_doppler_factor (rpacket_t * packet, storage_model_t * storage)

/* Methods for calculating continuum opacities */

INLINE double
double
bf_cross_section(storage_model_t * storage, int64_t continuum_id, double comov_nu)
{
/* Temporary hardcoded values */
Expand All @@ -143,7 +143,6 @@ bf_cross_section(storage_model_t * storage, int64_t continuum_id, double comov_n
return sigma_bf * pow((storage->continuum_list_nu[continuum_id] / comov_nu), 3);
}

INLINE
void calculate_chi_bf(rpacket_t * packet, storage_model_t * storage)
{
double bf_helper = 0;
Expand Down Expand Up @@ -179,7 +178,7 @@ void calculate_chi_bf(rpacket_t * packet, storage_model_t * storage)
rpacket_set_chi_boundfree(packet, bf_helper * doppler_factor);
}

INLINE double
double
compute_distance2boundary (rpacket_t * packet, storage_model_t * storage)
{
double r = rpacket_get_r (packet);
Expand Down Expand Up @@ -219,7 +218,7 @@ compute_distance2boundary (rpacket_t * packet, storage_model_t * storage)
}
}

INLINE tardis_error_t
tardis_error_t
compute_distance2line (rpacket_t * packet, storage_model_t * storage,
double *result)
{
Expand Down Expand Up @@ -274,7 +273,7 @@ compute_distance2line (rpacket_t * packet, storage_model_t * storage,
fprintf (stderr, "mu = %f\n", mu);
fprintf (stderr, "nu = %f\n", nu);
fprintf (stderr, "doppler_factor = %f\n", doppler_factor);
fprintf (stderr, "cur_zone_id = %lld\n", cur_zone_id);
fprintf (stderr, "cur_zone_id = %" PRIi64 "\n", cur_zone_id);
ret_val = TARDIS_ERROR_COMOV_NU_LESS_THAN_NU_LINE;
}
else
Expand All @@ -285,7 +284,7 @@ compute_distance2line (rpacket_t * packet, storage_model_t * storage,
return ret_val;
}

INLINE void
void
compute_distance2continuum(rpacket_t * packet, storage_model_t * storage)
{
double chi_boundfree, chi_freefree, chi_electron, chi_continuum, d_continuum;
Expand Down Expand Up @@ -335,7 +334,7 @@ compute_distance2continuum(rpacket_t * packet, storage_model_t * storage)
}
}

INLINE int64_t
int64_t
macro_atom (rpacket_t * packet, storage_model_t * storage)
{
int emit = 0, i = 0;
Expand All @@ -362,7 +361,7 @@ macro_atom (rpacket_t * packet, storage_model_t * storage)
return storage->transition_line_id[i];
}

INLINE double
double
move_packet (rpacket_t * packet, storage_model_t * storage, double distance)
{
double new_r, doppler_factor, comov_energy, comov_nu;
Expand Down Expand Up @@ -395,7 +394,7 @@ move_packet (rpacket_t * packet, storage_model_t * storage, double distance)
return doppler_factor;
}

INLINE void
void
increment_j_blue_estimator (rpacket_t * packet, storage_model_t * storage,
double d_line, int64_t j_blue_idx)
{
Expand Down Expand Up @@ -734,7 +733,7 @@ montecarlo_line_scatter (rpacket_t * packet, storage_model_t * storage,
}
}

INLINE void
static void
montecarlo_compute_distances (rpacket_t * packet, storage_model_t * storage)
{
// Check if the last line was the same nu as the current line.
Expand All @@ -756,7 +755,7 @@ montecarlo_compute_distances (rpacket_t * packet, storage_model_t * storage)
}
}

INLINE montecarlo_event_handler_t
static montecarlo_event_handler_t
get_event_handler (rpacket_t * packet, storage_model_t * storage,
double *distance)
{
Expand Down Expand Up @@ -784,7 +783,7 @@ get_event_handler (rpacket_t * packet, storage_model_t * storage,
return handler;
}

INLINE montecarlo_event_handler_t
montecarlo_event_handler_t
montecarlo_continuum_event_handler(rpacket_t * packet, storage_model_t * storage)
{
if (storage->cont_status == CONTINUUM_OFF)
Expand Down
57 changes: 29 additions & 28 deletions tardis/montecarlo/src/cmontecarlo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
#include "randomkit/randomkit.h"
#include "rpacket.h"
#include "status.h"

#ifdef __clang__
#define INLINE extern inline
#else
#define INLINE inline
#endif
#include "cmontecarlo1.h"

typedef void (*montecarlo_event_handler_t) (rpacket_t * packet,
storage_model_t * storage,
Expand All @@ -30,7 +25,7 @@ typedef void (*montecarlo_event_handler_t) (rpacket_t * packet,
*
* @return index of the next boundary to the left
*/
inline tardis_error_t reverse_binary_search (double *x, double x_insert,
tardis_error_t reverse_binary_search (double *x, double x_insert,
int64_t imin, int64_t imax,
int64_t * result);

Expand All @@ -43,21 +38,10 @@ inline tardis_error_t reverse_binary_search (double *x, double x_insert,
*
* @return index of the next boundary to the left
*/
inline tardis_error_t binary_search (double *x, double x_insert, int64_t imin,
tardis_error_t binary_search (double *x, double x_insert, int64_t imin,
int64_t imax, int64_t * result);

/** Insert a value in to an array of line frequencies
*
* @param nu array of line frequencies
* @param nu_insert value of nu key
* @param number_of_lines number of lines in the line list
*
* @return index of the next line ot the red. If the key value is redder than the reddest line returns number_of_lines.
*/
inline tardis_error_t line_search (double *nu, double nu_insert,
int64_t number_of_lines, int64_t * result);

inline double rpacket_doppler_factor(rpacket_t * packet, storage_model_t * storage);
double rpacket_doppler_factor(rpacket_t * packet, storage_model_t * storage);

/** Calculate the distance to shell boundary.
*
Expand All @@ -66,7 +50,7 @@ inline double rpacket_doppler_factor(rpacket_t * packet, storage_model_t * stora
*
* @return distance to shell boundary
*/
inline double compute_distance2boundary (rpacket_t * packet,
double compute_distance2boundary (rpacket_t * packet,
storage_model_t * storage);

/** Calculate the distance the packet has to travel until it redshifts to the first spectral line.
Expand All @@ -76,7 +60,7 @@ inline double compute_distance2boundary (rpacket_t * packet,
*
* @return distance to the next spectral line
*/
extern inline tardis_error_t compute_distance2line (rpacket_t * packet,
tardis_error_t compute_distance2line (rpacket_t * packet,
storage_model_t * storage,
double *result);

Expand All @@ -87,7 +71,7 @@ extern inline tardis_error_t compute_distance2line (rpacket_t * packet,
*
* @return distance to the Thomson scatter event in centimeters
*/
inline double compute_distance2electron (rpacket_t * packet,
double compute_distance2electron (rpacket_t * packet,
storage_model_t * storage);

/** Calculate the distance to the next continuum event, which can be a Thomson scattering, bound-free absorption or
Expand All @@ -98,14 +82,14 @@ inline double compute_distance2electron (rpacket_t * packet,
*
* sets distance to the next continuum event (in centimeters) in packet rpacket structure
*/
inline void compute_distance2continuum (rpacket_t * packet, storage_model_t * storage);
void compute_distance2continuum (rpacket_t * packet, storage_model_t * storage);

inline int64_t macro_atom (rpacket_t * packet, storage_model_t * storage);
int64_t macro_atom (rpacket_t * packet, storage_model_t * storage);

inline double move_packet (rpacket_t * packet, storage_model_t * storage,
double move_packet (rpacket_t * packet, storage_model_t * storage,
double distance);

inline void increment_j_blue_estimator (rpacket_t * packet,
void increment_j_blue_estimator (rpacket_t * packet,
storage_model_t * storage,
double d_line, int64_t j_blue_idx);

Expand All @@ -123,10 +107,27 @@ void montecarlo_main_loop(storage_model_t * storage,

/* New handlers for continuum implementation */

inline montecarlo_event_handler_t montecarlo_continuum_event_handler(rpacket_t * packet, storage_model_t * storage);
montecarlo_event_handler_t montecarlo_continuum_event_handler(rpacket_t * packet, storage_model_t * storage);

void montecarlo_free_free_scatter (rpacket_t * packet, storage_model_t * storage, double distance);

void montecarlo_bound_free_scatter (rpacket_t * packet, storage_model_t * storage, double distance);

double
bf_cross_section(storage_model_t * storage, int64_t continuum_id, double comov_nu);

void calculate_chi_bf(rpacket_t * packet, storage_model_t * storage);

void
move_packet_across_shell_boundary (rpacket_t * packet,
storage_model_t * storage, double distance);

void
montecarlo_thomson_scatter (rpacket_t * packet, storage_model_t * storage,
double distance);

void
montecarlo_line_scatter (rpacket_t * packet, storage_model_t * storage,
double distance);

#endif // TARDIS_CMONTECARLO_H
17 changes: 17 additions & 0 deletions tardis/montecarlo/src/cmontecarlo1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef TARDIS_CMONTECARLO1_H
#define TARDIS_CMONTECARLO1_H

/** Insert a value in to an array of line frequencies
*
* @param nu array of line frequencies
* @param nu_insert value of nu key
* @param number_of_lines number of lines in the line list
*
* @return index of the next line ot the red. If the key value is redder than the reddest line returns number_of_lines.
*/
tardis_error_t line_search (double *nu, double nu_insert,
int64_t number_of_lines, int64_t * result);

extern rk_state mt_state;

#endif
Loading