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

          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 <distributed/mpi.h>
      17             : #include <gvt/fossil.h>
      18             : #include <gvt/gvt.h>
      19             : #include <gvt/termination.h>
      20             : #include <lib/lib.h>
      21             : #include <log/stats.h>
      22             : #include <lp/lp.h>
      23             : #include <mm/msg_allocator.h>
      24             : 
      25           0 : static thr_ret_t THREAD_CALL_CONV parallel_thread_run(void *rid_arg)
      26             : {
      27             :         rid = (uintptr_t)rid_arg;
      28             :         stats_init();
      29             :         msg_allocator_init();
      30             :         msg_queue_init();
      31             :         sync_thread_barrier();
      32             :         lp_init();
      33             :         process_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             :                 mpi_remote_msg_handle();
      46             : 
      47             :                 unsigned i = 8;
      48             :                 while (i--) {
      49             :                         process_msg();
      50             :                 }
      51             : 
      52             :                 simtime_t current_gvt;
      53             :                 if (unlikely(current_gvt = gvt_phase_run())) {
      54             :                         termination_on_gvt(current_gvt);
      55             :                         fossil_collect(current_gvt);
      56             :                         stats_on_gvt(current_gvt);
      57             :                 }
      58             :         }
      59             : 
      60             :         if (sync_thread_barrier()) {
      61             :                 stats_dump();
      62             :                 stats_global_time_take(STATS_GLOBAL_EVENTS_END);
      63             :                 log_log(LOG_INFO, "Finalizing simulation");
      64             :         }
      65             : 
      66             :         process_fini();
      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             : }
      85             : 
      86           0 : static void parallel_global_fini(void)
      87             : {
      88             :         msg_queue_global_fini();
      89             :         lp_global_fini();
      90             :         process_global_fini();
      91             :         lib_global_fini();
      92             :         stats_global_fini();
      93             : }
      94             : 
      95           0 : void parallel_simulation(void)
      96             : {
      97             :         log_log(LOG_INFO, "Initializing parallel simulation");
      98             :         parallel_global_init();
      99             :         stats_global_time_take(STATS_GLOBAL_INIT_END);
     100             : 
     101             :         thr_id_t thrs[n_threads];
     102             :         rid_t i = n_threads;
     103             :         while (i--) {
     104             :                 if (thread_start(&thrs[i], parallel_thread_run,
     105             :                                   (void *)(uintptr_t)i)) {
     106             :                         log_log(LOG_FATAL, "Unable to create a thread!");
     107             :                         abort();
     108             :                 }
     109             :                 if (global_config.core_binding &&
     110             :                                 thread_affinity_set(thrs[i], i)) {
     111             :                         log_log(LOG_FATAL, "Unable to set a thread affinity!");
     112             :                         abort();
     113             :                 }
     114             :         }
     115             : 
     116             :         i = n_threads;
     117             :         while (i--)
     118             :                 thread_wait(thrs[i], NULL);
     119             : 
     120             :         stats_global_time_take(STATS_GLOBAL_FINI_START);
     121             :         parallel_global_fini();
     122             : }

Generated by: LCOV version 1.14