Skip to content

Commit

Permalink
Fix lints and use &mut Vec for wait_{some, all} and test_{some, all};…
Browse files Browse the repository at this point in the history
… also fix bug in test_some()
  • Loading branch information
jtronge committed Aug 3, 2022
1 parent 8f4b0bf commit 007f5bb
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 174 deletions.
2 changes: 1 addition & 1 deletion build-probe-mpi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![warn(unused_extern_crates)]
#![warn(unused_import_braces)]
#![warn(unused_qualifications)]
#![allow(clippy::unknown_clippy_lints)]
#![allow(unknown_lints)]

//! Probe an environment for an installed MPI library
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use mpi;
use mpi::traits::*;

#[cfg(msmpi)]
fn main() {
}
fn main() {}

const COUNT: usize = 128;

Expand All @@ -19,8 +18,11 @@ fn main() {
let req = world.immediate_barrier();
coll.add(req);
}
let mut finished = 0;
while coll.incomplete() > 0 {
coll.wait_any().unwrap();
finished += 1;
assert_eq!(coll.incomplete(), COUNT - finished);
}
});

Expand All @@ -30,16 +32,12 @@ fn main() {
let req = world.immediate_barrier();
coll.add(req);
}
let mut result = vec![None; COUNT];
let mut result = vec![];
let mut finished = 0;
while coll.incomplete() > 0 {
let count = coll.wait_some(&mut result);
let mut i = 0;
for elm in result.iter() {
if let Some(_) = elm {
i += 1;
}
}
assert_eq!(i, count);
coll.wait_some(&mut result);
finished += result.len();
assert_eq!(coll.incomplete(), COUNT - finished);
}
});

Expand All @@ -49,9 +47,9 @@ fn main() {
let req = world.immediate_barrier();
coll.add(req);
}
let mut result = vec![None; COUNT ];
let mut result = vec![];
coll.wait_all(&mut result);
assert!(result.iter().all(|elm| elm.is_some()));
assert_eq!(result.len(), COUNT);
});

// Try test_any()
Expand All @@ -76,20 +74,11 @@ fn main() {
let req = world.immediate_barrier();
coll.add(req);
}
let mut result = vec![None; COUNT];
let mut result = vec![];
let mut finished = 0;
while coll.incomplete() > 0 {
let count = coll.test_some(&mut result);
finished += count;
if count > 0 {
let mut i = 0;
for elm in result.iter() {
if let Some(_) = elm {
i += 1;
}
}
assert_eq!(i, count);
}
coll.test_some(&mut result);
finished += result.len();
assert_eq!(coll.incomplete(), COUNT - finished);
}
assert_eq!(finished, COUNT);
Expand All @@ -101,12 +90,12 @@ fn main() {
let req = world.immediate_barrier();
coll.add(req);
}
let mut result = vec![None; COUNT];
let mut result = vec![];
while coll.incomplete() > 0 {
if coll.test_all(&mut result) {
assert_eq!(coll.incomplete(), 0);
}
}
assert!(result.iter().all(|elm| elm.is_some()));
assert_eq!(result.len(), COUNT);
});
}
49 changes: 21 additions & 28 deletions examples/immediate_multiple_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn main() {

// Test wait_any()
let mut result: Vec<i32> = vec![0; COUNT];
let prev_proc = (rank - 1 + size) % size;
let next_proc = (rank + 1) % size;
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
let prev_proc = if rank > 0 { rank - 1 } else { size - 1 };
let next_proc = (rank + 1) % size;
for _ in 0..result.len() {
let sreq = world
.process_at_rank(next_proc)
Expand Down Expand Up @@ -56,8 +56,6 @@ fn main() {
let mut result: Vec<i32> = vec![0; COUNT];
// Test wait_some()
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
let prev_proc = if rank > 0 { rank - 1 } else { size - 1 };
let next_proc = (rank + 1) % size;
for _ in 0..result.len() {
let sreq = world
.process_at_rank(next_proc)
Expand All @@ -72,18 +70,18 @@ fn main() {
}
let mut send_count = 0;
let mut recv_count = 0;
let mut some_buf: Vec<Option<(usize, Status, &i32)>> = vec![None; 2 * COUNT];
let mut some_buf = vec![];
let mut finished = 0;
while coll.incomplete() > 0 {
let count = coll.wait_some(&mut some_buf);
println!("wait_some(): {} request(s) completed", count);
assert!(some_buf.iter().any(|elm| elm.is_some()));
for elm in some_buf.iter() {
if let Some((_, _, result)) = elm {
if **result == rank {
send_count += 1;
} else {
recv_count += 1;
}
coll.wait_some(&mut some_buf);
println!("wait_some(): {} request(s) completed", some_buf.len());
finished += some_buf.len();
assert_eq!(coll.incomplete(), 2 * COUNT - finished);
for &(_, _, result) in some_buf.iter() {
if *result == rank {
send_count += 1;
} else {
recv_count += 1;
}
}
}
Expand All @@ -94,8 +92,6 @@ fn main() {
let mut result: Vec<i32> = vec![0; COUNT];
// Test wait_all()
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
let prev_proc = if rank > 0 { rank - 1 } else { size - 1 };
let next_proc = (rank + 1) % size;
for _ in 0..result.len() {
let sreq = world
.process_at_rank(next_proc)
Expand All @@ -108,12 +104,13 @@ fn main() {
.immediate_receive_into(scope, val);
coll.add(rreq);
}
let mut out: Vec<Option<(usize, Status, &i32)>> = vec![None; 2 * COUNT];

let mut out = vec![];
coll.wait_all(&mut out);
assert_eq!(out.len(), 2 * COUNT);
let mut send_count = 0;
let mut recv_count = 0;
for elm in out {
let (_, _, result) = elm.unwrap();
for (_, _, result) in out {
if *result == rank {
send_count += 1;
} else {
Expand All @@ -127,13 +124,9 @@ fn main() {
// Check wait_*() with a buffer of increasing values
let x: Vec<i32> = (0..COUNT as i32).collect();
let mut result: Vec<i32> = vec![0; COUNT];
mpi::request::multiple_scope(COUNT, |scope, coll| {
let prev_proc = if rank > 0 { rank - 1 } else { size - 1 };
let next_proc = (rank + 1) % size;
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
for elm in &x {
let sreq = world
.process_at_rank(next_proc)
.immediate_send(scope, elm);
let sreq = world.process_at_rank(next_proc).immediate_send(scope, elm);
coll.add(sreq);
}
for val in result.iter_mut() {
Expand All @@ -142,9 +135,9 @@ fn main() {
.immediate_receive_into(scope, val);
coll.add(rreq);
}
let mut out: Vec<Option<(usize, Status, &i32)>> = vec![None; 2 * COUNT];
let mut out: Vec<(usize, Status, &i32)> = vec![];
coll.wait_all(&mut out);
assert!(out.iter().all(|elm| elm.is_some()));
assert_eq!(out.len(), 2 * COUNT);
});
// Ensure the result and x are an incrementing array of integers
result.sort();
Expand Down
39 changes: 18 additions & 21 deletions examples/immediate_multiple_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Example showing usage of test_any(), test_some() and test_all().
use mpi;
use mpi::Rank;
use mpi::request::{RequestCollection, Scope};
use mpi::traits::*;
use mpi::request::{Scope, RequestCollection};
use mpi::Rank;

const COUNT: usize = 128;

Expand All @@ -17,9 +17,7 @@ fn send_recv<'a, C: Communicator, S: Scope<'a> + Copy>(
recv: &'a mut [[i32; 4]],
) {
for elm in x {
let sreq = world
.process_at_rank(next_proc)
.immediate_send(scope, elm);
let sreq = world.process_at_rank(next_proc).immediate_send(scope, elm);
coll.add(sreq);
}
for elm in recv.iter_mut() {
Expand Down Expand Up @@ -51,9 +49,11 @@ fn main() {
let next_proc = (rank + 1) % size;
let prev_proc = if rank > 0 { rank - 1 } else { size - 1 };

let x: Vec<[i32; 4]> = (0..COUNT as i32).map(|i| [i, i + 1, i + 2, i + 3]).collect();
let x: Vec<[i32; 4]> = (0..COUNT as i32)
.map(|i| [i, i + 1, i + 2, i + 3])
.collect();
let mut recv: Vec<[i32; 4]> = vec![[0, 0, 0, 0]; COUNT];
mpi::request::multiple_scope(COUNT, |scope, coll| {
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
send_recv(world, scope, coll, next_proc, prev_proc, &x, &mut recv);

let mut buf = vec![];
Expand All @@ -66,32 +66,29 @@ fn main() {
});

let mut recv: Vec<[i32; 4]> = vec![[0, 0, 0, 0]; COUNT];
mpi::request::multiple_scope(COUNT, |scope, coll| {
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
send_recv(world, scope, coll, next_proc, prev_proc, &x, &mut recv);

let mut complete = vec![None; 2 * COUNT];
let mut complete = vec![];
let mut buf = vec![];
while coll.incomplete() > 0 {
let count = coll.test_some(&mut complete);
if count > 0 {
println!("test_some(): {} request(s) completed", count);
for elm in complete.iter() {
if let Some((_, _, data)) = elm {
buf.push(**data);
}
}
coll.test_some(&mut complete);
println!("test_some(): {} request(s) completed", complete.len());
for &(_, _, data) in complete.iter() {
buf.push(*data);
}
}
check_result_buffer(&x, buf);
});

let mut recv: Vec<[i32; 4]> = vec![[0, 0, 0, 0]; COUNT];
mpi::request::multiple_scope(COUNT, |scope, coll| {
mpi::request::multiple_scope(2 * COUNT, |scope, coll| {
send_recv(world, scope, coll, next_proc, prev_proc, &x, &mut recv);

let mut complete = vec![None; 2 * COUNT];
while !coll.test_all(&mut complete) { }
let buf: Vec<[i32; 4]> = complete.iter().map(|elm| *elm.unwrap().2).collect();
let mut complete = vec![];
while !coll.test_all(&mut complete) {}
assert_eq!(complete.len(), 2 * COUNT);
let buf: Vec<[i32; 4]> = complete.iter().map(|elm| *elm.2).collect();
check_result_buffer(&x, buf);
});
}
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![warn(unused_extern_crates)]
#![warn(unused_import_braces)]
#![warn(unused_qualifications)]
#![allow(clippy::unknown_clippy_lints)]
#![allow(unknown_lints)]
#![allow(renamed_and_removed_lints)]
#![allow(clippy::needless_doctest_main)]
#![warn(clippy::cast_possible_truncation)]
Expand Down Expand Up @@ -179,8 +179,8 @@ pub type Count = c_int;
pub type Tag = c_int;
/// An address in memory
pub type Address = MPI_Aint;
/// Rank of each process.
pub type Rank = c_int;
/// Reexport the Rank type
pub use crate::topology::Rank;

/// IntArray is used to translate Rust bool values to and from the int-bool types preferred by MPI
/// without incurring allocation in the common case.
Expand Down
6 changes: 1 addition & 5 deletions src/point_to_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,7 @@ pub trait Destination: AsCommunicator {
/// # Standard section(s)
///
/// 3.7.2
fn immediate_send<'a, Sc, Buf: ?Sized>(
&self,
scope: Sc,
buf: &'a Buf,
) -> Request<'a, Buf, Sc>
fn immediate_send<'a, Sc, Buf: ?Sized>(&self, scope: Sc, buf: &'a Buf) -> Request<'a, Buf, Sc>
where
Buf: 'a + Buffer,
Sc: Scope<'a>,
Expand Down

0 comments on commit 007f5bb

Please sign in to comment.