LCOV - code coverage report
Current view: top level - core/src/parallel - parallel.c Hit Total Coverage
Test: ROOT-Sim develop Documentation Coverage Lines: 1 5 20.0 %
Date: 2021-03-02 11:24:52

          Line data    Source code
       1           1 : /**
       2             :  * @file parallel/parallel.c
       3             :  *
       4             :  * @brief Concurrent simulation engine
       5             :  *
       6             :  * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com>
       7             :  * SPDX-License-Identifier: GPL-3.0-only
       8             :  */
       9             : #include <parallel/parallel.h>
      10             : 
      11             : #include <arch/thread.h>
      12             : #include <core/core.h>
      13             : #include <core/init.h>
      14             : #include <core/sync.h>
      15             : #include <datatypes/msg_queue.h>
      16             : #include <datatypes/remote_msg_map.h>
      17             : #include <distributed/mpi.h>
      18             : #include <gvt/fossil.h>
      19             : #include <gvt/gvt.h>
      20             : #include <gvt/termination.h>
      21             : #include <lib/lib.h>
      22             : #include <log/stats.h>
      23             : #include <lp/lp.h>
      24             : #include <mm/msg_allocator.h>
      25             : 
      26           0 : static thr_ret_t THREAD_CALL_CONV parallel_thread_run(void *rid_arg)
      27             : {
      28             :         rid = (uintptr_t)rid_arg;
      29             :         stats_init();
      30             :         msg_allocator_init();
      31             :         msg_queue_init();
      32             :         sync_thread_barrier();
      33             :         lp_init();
      34             : 
      35             : #ifdef ROOTSIM_MPI
      36             :         if (sync_thread_barrier())
      37             :                 mpi_node_barrier();
      38             : #endif
      39             :         if (sync_thread_barrier()) {
      40             :                 log_log(LOG_INFO, "Starting simulation");
      41             :                 stats_global_time_take(STATS_GLOBAL_EVENTS_START);
      42             :         }
      43             : 
      44             :         while (likely(termination_cant_end())) {
      45             : #ifdef ROOTSIM_MPI
      46             :                 mpi_remote_msg_handle();
      47             : #endif
      48             :                 unsigned i = 8;
      49             :                 while (i--) {
      50             :                         process_msg();
      51             :                 }
      52             : 
      53             :                 simtime_t current_gvt;
      54             :                 if (unlikely(current_gvt = gvt_phase_run())) {
      55             :                         termination_on_gvt(current_gvt);
      56             :                         fossil_collect(current_gvt);
      57             :                         stats_on_gvt(current_gvt);
      58             :                 }
      59             :         }
      60             : 
      61             :         if (sync_thread_barrier()) {
      62             :                 stats_dump();
      63             :                 stats_global_time_take(STATS_GLOBAL_EVENTS_END);
      64             :                 log_log(LOG_INFO, "Finalizing simulation");
      65             :         }
      66             : 
      67             :         lp_fini();
      68             :         msg_queue_fini();
      69             :         sync_thread_barrier();
      70             :         msg_allocator_fini();
      71             : 
      72             :         return THREAD_RET_SUCCESS;
      73             : }
      74             : 
      75           0 : static void parallel_global_init(void)
      76             : {
      77             :         stats_global_init();
      78             :         lib_global_init();
      79             :         process_global_init();
      80             :         lp_global_init();
      81             :         msg_queue_global_init();
      82             :         termination_global_init();
      83             :         gvt_global_init();
      84             : #ifdef ROOTSIM_MPI
      85             :         remote_msg_map_global_init();
      86             : #endif
      87             : }
      88             : 
      89           0 : static void parallel_global_fini(void)
      90             : {
      91             : #ifdef ROOTSIM_MPI
      92             :         remote_msg_map_global_fini();
      93             : #endif
      94             :         msg_queue_global_fini();
      95             :         lp_global_fini();
      96             :         process_global_fini();
      97             :         lib_global_fini();
      98             :         stats_global_fini();
      99             : }
     100             : 
     101           0 : void parallel_simulation(void)
     102             : {
     103             :         log_log(LOG_INFO, "Initializing parallel simulation");
     104             :         parallel_global_init();
     105             :         stats_global_time_take(STATS_GLOBAL_INIT_END);
     106             : 
     107             :         thr_id_t thrs[n_threads];
     108             :         rid_t i = n_threads;
     109             :         while (i--) {
     110             :                 if (thread_start(&thrs[i], parallel_thread_run,
     111             :                                   (void *)(uintptr_t)i)) {
     112             :                         log_log(LOG_FATAL, "Unable to create a thread!");
     113             :                         abort();
     114             :                 }
     115             :                 if (global_config.core_binding &&
     116             :                                 thread_affinity_set(thrs[i], i)) {
     117             :                         log_log(LOG_FATAL, "Unable to set a thread affinity!");
     118             :                         abort();
     119             :                 }
     120             :         }
     121             : 
     122             :         i = n_threads;
     123             :         while (i--)
     124             :                 thread_wait(thrs[i], NULL);
     125             : 
     126             :         stats_global_time_take(STATS_GLOBAL_FINI_START);
     127             :         parallel_global_fini();
     128             : }

Generated by: LCOV version 1.14