/* initialise RPacket */ static void init_rpacket(rpacket_t *rp){ double MU = 0.3; double R = 7.5e14; double ENERGY = 0.9; int NEXT_LINE_ID = 1; double NU = 0.4; double NU_LINE = 0.2; int CURRENT_SHELL_ID = 0; double TAU_EVENT = 2.9e13; rpacket_set_current_shell_id(rp, CURRENT_SHELL_ID); rpacket_set_next_shell_id(rp, CURRENT_SHELL_ID+1); rpacket_set_mu(rp, MU); rpacket_set_nu(rp, NU); rpacket_set_r(rp, R); rpacket_set_last_line(rp, false); rpacket_set_recently_crossed_boundary(rp, 1); rpacket_set_close_line(rp, false); rpacket_set_nu_line(rp, NU_LINE); rpacket_set_next_line_id(rp, NEXT_LINE_ID); rpacket_set_tau_event(rp, TAU_EVENT); rpacket_set_virtual_packet(rp, 0); rpacket_set_energy(rp, ENERGY); rpacket_set_virtual_packet_flag(rp, true); rpacket_set_status(rp, TARDIS_PACKET_STATUS_IN_PROCESS); rpacket_set_id(rp, 0); rpacket_set_current_continuum_id(rp, 1); }
void montecarlo_main_loop(storage_model_t * storage, int64_t virtual_packet_flag, int nthreads, unsigned long seed) { int64_t finished_packets = 0; storage->virt_packet_count = 0; #ifdef WITH_VPACKET_LOGGING storage->virt_packet_nus = (double *)safe_malloc(sizeof(double) * storage->no_of_packets); storage->virt_packet_energies = (double *)safe_malloc(sizeof(double) * storage->no_of_packets); storage->virt_packet_last_interaction_in_nu = (double *)safe_malloc(sizeof(double) * storage->no_of_packets); storage->virt_packet_last_interaction_type = (int64_t *)safe_malloc(sizeof(int64_t) * storage->no_of_packets); storage->virt_packet_last_line_interaction_in_id = (int64_t *)safe_malloc(sizeof(int64_t) * storage->no_of_packets); storage->virt_packet_last_line_interaction_out_id = (int64_t *)safe_malloc(sizeof(int64_t) * storage->no_of_packets); storage->virt_array_size = storage->no_of_packets; #endif // WITH_VPACKET_LOGGING #ifdef WITHOPENMP omp_set_dynamic(0); if (nthreads > 0) { omp_set_num_threads(nthreads); } #pragma omp parallel firstprivate(finished_packets) { rk_state mt_state; rk_seed (seed + omp_get_thread_num(), &mt_state); #pragma omp master { fprintf(stderr, "Running with OpenMP - %d threads\n", omp_get_num_threads()); print_progress(0, storage->no_of_packets); } #pragma omp for #else rk_state mt_state; rk_seed (seed, &mt_state); fprintf(stderr, "Running without OpenMP\n"); #endif for (int64_t packet_index = 0; packet_index < storage->no_of_packets; ++packet_index) { int reabsorbed = 0; rpacket_t packet; rpacket_set_id(&packet, packet_index); rpacket_init(&packet, storage, packet_index, virtual_packet_flag); if (virtual_packet_flag > 0) { reabsorbed = montecarlo_one_packet(storage, &packet, -1, &mt_state); } reabsorbed = montecarlo_one_packet(storage, &packet, 0, &mt_state); storage->output_nus[packet_index] = rpacket_get_nu(&packet); if (reabsorbed == 1) { storage->output_energies[packet_index] = -rpacket_get_energy(&packet); } else { storage->output_energies[packet_index] = rpacket_get_energy(&packet); } if ( ++finished_packets%100 == 0 ) { #ifdef WITHOPENMP // WARNING: This only works with a static sheduler and gives an approximation of progress. // The alternative would be to have a shared variable but that could potentially decrease performance when using many threads. if (omp_get_thread_num() == 0 ) print_progress(finished_packets * omp_get_num_threads(), storage->no_of_packets); #else print_progress(finished_packets, storage->no_of_packets); #endif } } #ifdef WITHOPENMP } #endif print_progress(storage->no_of_packets, storage->no_of_packets); fprintf(stderr,"\n"); }
bool test_rpacket_get_id(void) { rpacket_t rp; rpacket_set_id(&rp, 2); return rpacket_get_id(&rp) == 2; }