@@ -18,7 +18,6 @@ use crate::mpi_events::{
18
18
} ;
19
19
use crate :: types:: { MpiCallType , MpiComm , MpiOp , MpiRank , MpiReq , MpiTag , Tsc , Usecs } ;
20
20
use crate :: InterpolError ;
21
- use lazy_static:: lazy_static;
22
21
use rayon:: prelude:: * ;
23
22
use std:: fs:: { self , File } ;
24
23
use std:: io:: Write ;
@@ -61,30 +60,28 @@ macro_rules! impl_register {
61
60
} ;
62
61
}
63
62
64
- lazy_static ! {
65
- /// A vector that keeps track of interposed MPI functions called by a process.
66
- ///
67
- /// The `lazy_static` macro creates static objects that are only initialized when needed at
68
- /// runtime. In this case, this implementation is similar to a singleton. It removes the need
69
- /// to pass a constant pointer on the `Vec` back to the C part of the interposition library,
70
- /// therefore avoiding the use of `unsafe` code sections.
71
- ///
72
- /// As the MPI standard allows for processes to run code in parallel (e.g. through libraries
73
- /// like OpenMP or pthread), the `Vec` *must* be wrapped in a `Mutex` to prevent concurrent
74
- /// attempts at pushing onto the traces vector. Each time an event is registered, the caller
75
- /// must first take the lock on the `Mutex` before pushing an `Event`. This ensures that
76
- /// `interpol-rs` is thread-safe even in `MPI_THREAD_MULTIPLE` context.
77
- ///
78
- /// We have chosen to implement mutual exclusion in the Rust part of the interposition library
79
- /// to reduce the critical section of code to the minimum, i.e. when a MPI call has been
80
- /// registered and *needs* to be saved. This choice theoretically allows for the best
81
- /// safety/performance ratio.
82
- ///
83
- /// It should be noted that in a MPI context, it is "rare" that the same process manages a
84
- /// large number of threads. Therefore, the contention on the `Mutex` should not impact the
85
- /// performance of the application and the blocking of threads will be kept to a minimum.
86
- static ref EVENTS : Trace = Trace ( Mutex :: new( Vec :: new( ) ) ) ;
87
- }
63
+ /// A vector that keeps track of interposed MPI functions called by a process.
64
+ ///
65
+ /// The `lazy_static` macro creates static objects that are only initialized when needed at
66
+ /// runtime. In this case, this implementation is similar to a singleton. It removes the need
67
+ /// to pass a constant pointer on the `Vec` back to the C part of the interposition library,
68
+ /// therefore avoiding the use of `unsafe` code sections.
69
+ ///
70
+ /// As the MPI standard allows for processes to run code in parallel (e.g. through libraries
71
+ /// like OpenMP or pthread), the `Vec` *must* be wrapped in a `Mutex` to prevent concurrent
72
+ /// attempts at pushing onto the traces vector. Each time an event is registered, the caller
73
+ /// must first take the lock on the `Mutex` before pushing an `Event`. This ensures that
74
+ /// `interpol-rs` is thread-safe even in `MPI_THREAD_MULTIPLE` context.
75
+ ///
76
+ /// We have chosen to implement mutual exclusion in the Rust part of the interposition library
77
+ /// to reduce the critical section of code to the minimum, i.e. when a MPI call has been
78
+ /// registered and *needs* to be saved. This choice theoretically allows for the best
79
+ /// safety/performance ratio.
80
+ ///
81
+ /// It should be noted that in a MPI context, it is "rare" that the same process manages a
82
+ /// large number of threads. Therefore, the contention on the `Mutex` should not impact the
83
+ /// performance of the application and the blocking of threads will be kept to a minimum.
84
+ static EVENTS : Trace = Trace ( Mutex :: new ( Vec :: new ( ) ) ) ;
88
85
89
86
#[ derive( Debug , PartialEq ) ]
90
87
#[ repr( C ) ]
@@ -112,8 +109,7 @@ fn serialize(
112
109
current_rank : MpiRank ,
113
110
) -> Result < ( ) , InterpolError > {
114
111
println ! ( "[interpol]: serializing traces for rank {current_rank}" ) ;
115
- let ser_traces = serde_json:: to_string_pretty ( events)
116
- . expect ( "failed to serialize vector contents to string" ) ;
112
+ let traces = serde_json:: to_string ( events) . expect ( "failed to serialize traces to string" ) ;
117
113
let filename = format ! ( "{}/rank{}_traces.json" , INTERPOL_DIR , current_rank) ;
118
114
119
115
fs:: create_dir_all ( INTERPOL_DIR ) ?;
@@ -122,7 +118,7 @@ fn serialize(
122
118
. truncate ( true )
123
119
. create ( true )
124
120
. open ( filename) ?;
125
- write ! ( file, "{}" , ser_traces ) ?;
121
+ write ! ( file, "{}" , traces ) ?;
126
122
Ok ( ( ) )
127
123
}
128
124
0 commit comments