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

Optional vpacket logging WIP #433

Merged
merged 2 commits into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
is_bool=True)
add_command_option('develop', 'with-openmp', 'compile TARDIS without OpenMP',
is_bool=True)
add_command_option('install', 'with-vpacket-logging', 'compile TARDIS with virtual packet logging',
is_bool=True)
add_command_option('build', 'with-vpacket-logging', 'compile TARDIS with virtual packet logging',
is_bool=True)
add_command_option('develop', 'with-vpacket-logging', 'compile TARDIS with virtual packet logging',
is_bool=True)

# Adjust the compiler in case the default on this platform is to use a
# broken one.
Expand Down
52 changes: 30 additions & 22 deletions tardis/montecarlo/montecarlo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ cdef extern from "src/cmontecarlo.h":
CONTINUUM_OFF = 0
CONTINUUM_ON = 1

cdef int LOG_VPACKETS

ctypedef struct storage_model_t:
double *packet_nus
double *packet_mus
Expand Down Expand Up @@ -236,34 +238,40 @@ def montecarlo_radial1d(model, runner, int_type_t virtual_packet_flag=0,

montecarlo_main_loop(&storage, virtual_packet_flag, nthreads,
model.tardis_config.montecarlo.seed)

cdef np.ndarray[double, ndim=1] virt_packet_nus = np.zeros(storage.virt_packet_count, dtype=np.float64)
cdef np.ndarray[double, ndim=1] virt_packet_energies = np.zeros(storage.virt_packet_count, dtype=np.float64)
cdef np.ndarray[double, ndim=1] virt_packet_last_interaction_in_nu = np.zeros(storage.virt_packet_count, dtype=np.float64)
cdef np.ndarray[int_type_t, ndim=1] virt_packet_last_interaction_type = np.zeros(storage.virt_packet_count, dtype=np.int64)
cdef np.ndarray[int_type_t, ndim=1] virt_packet_last_line_interaction_in_id = np.zeros(storage.virt_packet_count, dtype=np.int64)
cdef np.ndarray[int_type_t, ndim=1] virt_packet_last_line_interaction_out_id = np.zeros(storage.virt_packet_count, dtype=np.int64)

for i in range(storage.virt_packet_count):
virt_packet_nus[i] = storage.virt_packet_nus[i]
virt_packet_energies[i] = storage.virt_packet_energies[i]
virt_packet_last_interaction_in_nu[i] = storage.virt_packet_last_interaction_in_nu[i]
virt_packet_last_interaction_type[i] = storage.virt_packet_last_interaction_type[i]
virt_packet_last_line_interaction_in_id[i] = storage.virt_packet_last_line_interaction_in_id[i]
virt_packet_last_line_interaction_out_id[i] = storage.virt_packet_last_line_interaction_out_id[i]
free(<void *>storage.virt_packet_nus)
free(<void *>storage.virt_packet_energies)
free(<void *>storage.virt_packet_last_interaction_in_nu)
free(<void *>storage.virt_packet_last_interaction_type)
free(<void *>storage.virt_packet_last_line_interaction_in_id)
free(<void *>storage.virt_packet_last_line_interaction_out_id)
runner.virt_packet_nus = virt_packet_nus
runner.virt_packet_energies = virt_packet_energies
runner.virt_packet_last_interaction_in_nu = virt_packet_last_interaction_in_nu
runner.virt_packet_last_interaction_type = virt_packet_last_interaction_type
runner.virt_packet_last_line_interaction_in_id = virt_packet_last_line_interaction_in_id
runner.virt_packet_last_line_interaction_out_id = virt_packet_last_line_interaction_out_id

if LOG_VPACKETS != 0:
print "NOVPACKETS!"
for i in range(storage.virt_packet_count):
virt_packet_nus[i] = storage.virt_packet_nus[i]
virt_packet_energies[i] = storage.virt_packet_energies[i]
virt_packet_last_interaction_in_nu[i] = storage.virt_packet_last_interaction_in_nu[i]
virt_packet_last_interaction_type[i] = storage.virt_packet_last_interaction_type[i]
virt_packet_last_line_interaction_in_id[i] = storage.virt_packet_last_line_interaction_in_id[i]
virt_packet_last_line_interaction_out_id[i] = storage.virt_packet_last_line_interaction_out_id[i]
free(<void *>storage.virt_packet_nus)
free(<void *>storage.virt_packet_energies)
free(<void *>storage.virt_packet_last_interaction_in_nu)
free(<void *>storage.virt_packet_last_interaction_type)
free(<void *>storage.virt_packet_last_line_interaction_in_id)
free(<void *>storage.virt_packet_last_line_interaction_out_id)
runner.virt_packet_nus = virt_packet_nus
runner.virt_packet_energies = virt_packet_energies
runner.virt_packet_last_interaction_in_nu = virt_packet_last_interaction_in_nu
runner.virt_packet_last_interaction_type = virt_packet_last_interaction_type
runner.virt_packet_last_line_interaction_in_id = virt_packet_last_line_interaction_in_id
runner.virt_packet_last_line_interaction_out_id = virt_packet_last_line_interaction_out_id
else:
runner.virt_packet_nus = None
runner.virt_packet_energies = None
runner.virt_packet_last_interaction_in_nu = None
runner.virt_packet_last_interaction_type = None
runner.virt_packet_last_line_interaction_in_id = None
runner.virt_packet_last_line_interaction_out_id = None
#return output_nus, output_energies, js, nubars, last_line_interaction_in_id, last_line_interaction_out_id, last_interaction_type, last_line_interaction_shell_id, virt_packet_nus, virt_packet_energies


3 changes: 3 additions & 0 deletions tardis/montecarlo/setup_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
link_args = []
define_macros = []

if get_distutils_option('with_vpacket_logging', ['build', 'install', 'develop']) is not None:
define_macros.append(('WITH_VPACKET_LOGGING', None))

def get_extensions():
sources = ['tardis/montecarlo/montecarlo.pyx']
sources += [os.path.relpath(fname) for fname in glob(
Expand Down
10 changes: 7 additions & 3 deletions tardis/montecarlo/src/cmontecarlo.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,14 @@ montecarlo_one_packet (storage_model_t * storage, rpacket_t * packet,
rpacket_get_energy (packet) * doppler_factor_ratio);
rpacket_set_nu(&virt_packet,rpacket_get_nu (packet) * doppler_factor_ratio);
reabsorbed = montecarlo_one_packet_loop (storage, &virt_packet, 1, mt_state);
#ifdef WITH_VPACKET_LOGGING
if ((rpacket_get_nu(&virt_packet) < storage->spectrum_end_nu) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ifdef block is also activates/deactivates the setting of
storage->spectrum_virt_nu[virt_id_nu] in line 455. This is crucial part of calculating and storing the virtual spectrum. This part should live outside the ifdef vpacketlogging block. See #445

(rpacket_get_nu(&virt_packet) > storage->spectrum_start_nu))
{
#ifdef WITHOPENMP
#pragma omp critical
{
#endif
#endif // WITHOPENMP
if (storage->virt_packet_count >= storage->virt_array_size)
{
storage->virt_array_size *= 2;
Expand All @@ -455,8 +456,9 @@ montecarlo_one_packet (storage_model_t * storage, rpacket_t * packet,
rpacket_get_energy(&virt_packet) * weight;
#ifdef WITHOPENMP
}
#endif
#endif // WITHOPENMP
}
#endif // WITH_VPACKET_LOGGING
}
}
else
Expand Down Expand Up @@ -806,14 +808,16 @@ montecarlo_one_packet_loop (storage_model_t * storage, rpacket_t * packet,
void
montecarlo_main_loop(storage_model_t * storage, int64_t virtual_packet_flag, int nthreads, unsigned long seed)
{
storage->virt_packet_count = 0;
#ifdef WITH_VPACKET_LOGGING
storage->virt_packet_nus = (double *)malloc(sizeof(double) * storage->no_of_packets);
storage->virt_packet_energies = (double *)malloc(sizeof(double) * storage->no_of_packets);
storage->virt_packet_last_interaction_in_nu = (double *)malloc(sizeof(double) * storage->no_of_packets);
storage->virt_packet_last_interaction_type = (int64_t *)malloc(sizeof(int64_t) * storage->no_of_packets);
storage->virt_packet_last_line_interaction_in_id = (int64_t *)malloc(sizeof(int64_t) * storage->no_of_packets);
storage->virt_packet_last_line_interaction_out_id = (int64_t *)malloc(sizeof(int64_t) * storage->no_of_packets);
storage->virt_packet_count = 0;
storage->virt_array_size = storage->no_of_packets;
#endif // WITH_VPACKET_LOGGING
#ifdef WITHOPENMP
fprintf(stderr, "Running with OpenMP - %d threads\n", nthreads);
omp_set_dynamic(0);
Expand Down
6 changes: 6 additions & 0 deletions tardis/montecarlo/src/cmontecarlo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include "status.h"
#include "cmontecarlo1.h"

#ifdef WITH_VPACKET_LOGGING
#define LOG_VPACKETS 1
#else
#define LOG_VPACKETS 0
#endif

typedef void (*montecarlo_event_handler_t) (rpacket_t * packet,
storage_model_t * storage,
double distance, rk_state *mt_state);
Expand Down