Skip to content

Commit

Permalink
Setting CI
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed Feb 2, 2023
1 parent 85fd822 commit e94f847
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 52 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/clippy.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Lint

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]

defaults:
run:
shell: bash

env:
CLIPPY_PARAMS: -W clippy::all -W clippy::pedantic -W clippy::nursery -W clippy::cargo

jobs:
rustfmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt

- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check --verbose

clippy:
name: clippy
runs-on: ubuntu-latest
strategy:
matrix:
cargo_flags:
- "--no-default-features"
- "--all-features"
steps:
- name: Checkout source code
uses: actions/checkout@master

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy

- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all ${{ matrix.cargo_flags }} -- ${{ env.CLIPPY_PARAMS }}
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test

on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macOS-latest
toolchain:
- stable
- nightly
cargo_flags:
- "--no-default-features"
- "--all-features"
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all ${{ matrix.cargo_flags }}

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --all ${{ matrix.cargo_flags }}
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"editor.formatOnSave": true
},
"rust-analyzer.cargo.features": [
"devstone",
"par_all"
],
}
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rayon = { version = "1.6", optional = true }
cpu-time = { version = "1.0", optional = true }

[features]
devstone = ["cpu-time"]
devstone_busy = ["cpu-time"]
par_any = ["rayon"]
par_start = ["par_any"]
par_collection = ["par_any"]
Expand All @@ -33,7 +33,6 @@ par_all = ["par_all_no_xxc", "par_xxc"]

[[example]]
name = "devstone"
required-features = ["devstone"]

[[example]]
name = "gpt_efp"
Expand Down
16 changes: 11 additions & 5 deletions src/devstone/atomic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(test)]
use super::SharedProbe;
use crate::modeling::*;
#[cfg(feature = "devstone_busy")]
use cpu_time::ThreadTime;
use std::time::Duration;

Expand Down Expand Up @@ -81,12 +82,17 @@ impl DEVStoneAtomic {
#[inline]
fn busy_sleep(duration: &Option<Duration>) {
if let Some(duration) = duration {
let now = ThreadTime::now();
let mut x: u32 = 0;
while now.elapsed() < *duration {
std::hint::black_box(&mut x);
x = x.wrapping_add(1);
#[cfg(feature = "devstone_busy")]
{
let now = ThreadTime::now();
let mut x: u32 = 0;
while now.elapsed() < *duration {
std::hint::black_box(&mut x);
x = x.wrapping_add(1);
}
}
#[cfg(not(feature = "devstone_busy"))]
std::thread::sleep(*duration);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "devstone")]
pub mod devstone;
pub mod modeling;
pub mod simulation;
Expand Down
35 changes: 27 additions & 8 deletions src/modeling/coupled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub struct Coupled {
/// External output couplings (serialized for better performance).
pub(crate) eocs: Vec<(Shared<dyn Port>, Shared<dyn Port>)>,
#[cfg(feature = "par_xic")]
pub(crate) par_eics: Vec<Vec<usize>>,
xic_map: HashMap<String, Vec<usize>>,
#[cfg(feature = "par_xic")]
pub(crate) par_ics: Vec<Vec<usize>>,
pub(crate) par_xics: Vec<Vec<usize>>,
#[cfg(feature = "par_eoc")]
pub(crate) par_eocs: Vec<Vec<usize>>,
}
Expand All @@ -43,9 +43,9 @@ impl Coupled {
xics: Vec::new(),
eocs: Vec::new(),
#[cfg(feature = "par_xic")]
par_eics: Vec::new(),
xic_map: HashMap::new(),
#[cfg(feature = "par_xic")]
par_ics: Vec::new(),
par_xics: Vec::new(),
#[cfg(feature = "par_eoc")]
par_eocs: Vec::new(),
}
Expand Down Expand Up @@ -134,6 +134,14 @@ impl Coupled {
panic!("coupling already exists");
}
coups.insert(source_key, self.xics.len());
#[cfg(feature = "par_xic")]
{
let destination_key = component_to.to_string() + "-" + port_to;
self.xic_map
.entry(destination_key)
.or_default()
.push(self.xics.len());
}
self.xics.push((p_to, p_from));
}

Expand Down Expand Up @@ -176,6 +184,14 @@ impl Coupled {
panic!("coupling already exists");
}
coups.insert(source_key, self.xics.len());
#[cfg(feature = "par_xic")]
{
let destination_key = component_to.to_string() + "-" + port_to;
self.xic_map
.entry(destination_key)
.or_default()
.push(self.xics.len());
}
self.xics.push((p_to, p_from));
}

Expand Down Expand Up @@ -212,7 +228,7 @@ impl Coupled {
self.eocs.push((p_to, p_from));
}

#[cfg(any(feature = "par_xic", feature = "par_eoc"))]
#[cfg(any(ffeature = "par_eoc"))]
fn flatten_map(map: &HashMap<String, HashMap<String, usize>>) -> Vec<Vec<usize>> {
map.values()
.map(|m| m.values().copied().collect())
Expand All @@ -221,12 +237,15 @@ impl Coupled {

#[cfg(feature = "par_xic")]
pub(crate) fn build_par_xics(&mut self) {
self.par_eics = Self::flatten_map(&self.eic_map);
self.par_ics = Self::flatten_map(&self.ic_map);
self.par_xics = self.xic_map.values().cloned().collect();
}

#[cfg(feature = "par_eoc")]
pub(crate) fn build_par_eocs(&mut self) {
self.par_eocs = Self::flatten_map(&self.eoc_map);
self.par_eocs = self
.eoc_map
.values()
.map(|m| m.values().copied().collect())
.collect();
}
}
37 changes: 14 additions & 23 deletions src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub trait Simulator: DynRef {
fn collection(&mut self, t: f64);

/// Propagates messages according to EICs and executes model transition functions.
fn transition(&mut self, t: f64);
fn transition(&mut self, t: f64) -> f64;
}

impl<T: Atomic + DynRef> Simulator for T {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<T: Atomic + DynRef> Simulator for T {
}
}

fn transition(&mut self, t: f64) {
fn transition(&mut self, t: f64) -> f64 {
let t_next = self.get_t_next();
if !self.get_component().is_input_empty() {
if t == t_next {
Expand All @@ -100,10 +100,12 @@ impl<T: Atomic + DynRef> Simulator for T {
} else if t == t_next {
Atomic::delta_int(self);
} else {
return;
return t_next;
}
let ta = Atomic::ta(self);
self.set_sim_t(t, t + ta);
let t_next = t + Atomic::ta(self);
self.set_sim_t(t, t_next);
self.clear_ports();
t_next
}
}

Expand Down Expand Up @@ -190,16 +192,9 @@ impl Simulator for Coupled {
/// 3. obtain their next simulation time.
///
/// If the feature `par_transition` is activated, the iteration is parallelized.
fn transition(&mut self, t: f64) {
fn transition(&mut self, t: f64) -> f64 {
#[cfg(feature = "par_xic")]
self.par_eics.par_iter().for_each(|coups| {
for &i in coups.iter() {
let (port_to, port_from) = &self.xics[i];
unsafe { port_from.propagate(&**port_to) };
}
});
#[cfg(feature = "par_xic")]
self.par_ics.par_iter().for_each(|coups| {
self.par_xics.par_iter().for_each(|coups| {
for &i in coups.iter() {
let (port_to, port_from) = &self.xics[i];
unsafe { port_from.propagate(&**port_to) };
Expand All @@ -214,15 +209,13 @@ impl Simulator for Coupled {
let iterator = self.components.par_iter_mut();
#[cfg(not(feature = "par_transition"))]
let iterator = self.components.iter_mut();
let next_t = iterator
.map(|c| {
c.transition(t);
c.clear_ports();
c.get_t_next()
})
let t_next = iterator
.map(|c| c.transition(t))
.min_by(|a, b| a.total_cmp(b))
.unwrap_or(f64::INFINITY);
self.set_sim_t(t, next_t);
self.set_sim_t(t, t_next);
self.clear_ports();
t_next
}
}

Expand All @@ -242,7 +235,6 @@ impl<T: Simulator> RootCoordinator<T> {
while t_next < t_end {
self.collection(t_next);
self.transition(t_next);
self.clear_ports();
t_next = self.get_t_next();
}
self.stop(t_next);
Expand All @@ -255,7 +247,6 @@ impl<T: Simulator> RootCoordinator<T> {
while t_next < f64::INFINITY && n_steps > 0 {
self.collection(t_next);
self.transition(t_next);
self.clear_ports();
t_next = self.get_t_next();
n_steps -= 1;
}
Expand Down

0 comments on commit e94f847

Please sign in to comment.