-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
102 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[build] | ||
# For generic x86_64 architecture. | ||
[x86_64-unknown-linux-gnu] | ||
rustflags = ["-C", "target-cpu=native"] | ||
|
||
# Can also specify your simd flags like avx512 etc. | ||
# Use +avx512 to enable avx512. | ||
# https://rust-lang.github.io/packed_simd/perf-guide/target-feature/rustflags.html | ||
# rustflags = ["-C", "target-cpu=native", "-C", "target-feature=+avx,+fma"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{ | ||
iter::ParallelIterator, | ||
slice::{ParallelSlice, ParallelSliceMut}, | ||
}; | ||
|
||
#[allow(clippy::ptr_arg, clippy::manual_memcpy, unused_variables)] | ||
pub fn copy(c: &mut Vec<f64>, a: &Vec<f64>, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
#[inline(never)] | ||
pub fn copy(c: &mut [f64], a: &[f64], n: usize) -> f64 { | ||
let c_iter = c.par_chunks_mut(n); | ||
let a_iter = a.par_chunks(n); | ||
|
||
c.par_iter_mut().enumerate().for_each(|(i, x)| *x = a[i]); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in 0..n { | ||
// c[i] = a[i]; | ||
// } | ||
|
||
// Parallel version | ||
c_iter.for_each(|c_slice| { | ||
c_slice | ||
.iter_mut() | ||
.enumerate() | ||
.for_each(|(i, val)| *val = a[i]) | ||
}); | ||
|
||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut}; | ||
|
||
#[allow(clippy::ptr_arg, unused_variables)] | ||
pub fn daxpy(a: &mut Vec<f64>, b: &Vec<f64>, scalar: f64, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
#[inline(never)] | ||
pub fn daxpy(a: &mut [f64], b: &[f64], scalar: f64, n: usize) -> f64 { | ||
let a_iter = a.par_chunks_mut(n); | ||
|
||
a.par_iter_mut() | ||
.enumerate() | ||
.for_each(|(i, x)| *x += scalar * b[i]); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in 0..n { | ||
// a[i] += scalar * b[i]; | ||
// } | ||
|
||
// Parallel version | ||
a_iter.for_each(|a_slice| { | ||
a_slice | ||
.iter_mut() | ||
.enumerate() | ||
.for_each(|(i, val)| *val = b[i].mul_add(scalar, *val)) | ||
}); | ||
|
||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut}; | ||
|
||
#[allow(clippy::ptr_arg, unused_variables)] | ||
pub fn init(b: &mut Vec<f64>, scalar: f64, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
#[inline(never)] | ||
pub fn init(b: &mut [f64], scalar: f64, n: usize) -> f64 { | ||
let b_iter = b.par_chunks_mut(n); | ||
|
||
b.par_iter_mut().for_each(|x| *x = scalar); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in b.iter_mut().take(n) { | ||
// *i = scalar; | ||
// } | ||
|
||
// Parallel version | ||
b_iter.for_each(|b_slice| b_slice.iter_mut().for_each(|val| *val = scalar)); | ||
|
||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut}; | ||
|
||
#[allow(clippy::ptr_arg, unused_variables)] | ||
pub fn sdaxpy(a: &mut Vec<f64>, b: &Vec<f64>, c: &Vec<f64>, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
pub fn sdaxpy(a: &mut [f64], b: &[f64], c: &[f64], n: usize) -> f64 { | ||
let a_iter = a.par_chunks_mut(n); | ||
|
||
a.par_iter_mut() | ||
.enumerate() | ||
.for_each(|(i, x)| *x += b[i] * c[i]); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in 0..n { | ||
// a[i] += b[i] * c[i]; | ||
// } | ||
|
||
// Parallel version | ||
a_iter.for_each(|a_slice| { | ||
a_slice | ||
.iter_mut() | ||
.enumerate() | ||
.for_each(|(i, val)| *val = c[i].mul_add(b[i], *val)) | ||
}); | ||
|
||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut}; | ||
|
||
#[allow(clippy::ptr_arg, unused_variables)] | ||
pub fn striad(a: &mut Vec<f64>, b: &Vec<f64>, c: &Vec<f64>, d: &Vec<f64>, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
pub fn striad(a: &mut [f64], b: &[f64], c: &[f64], d: &[f64], n: usize) -> f64 { | ||
let a_iter = a.par_chunks_mut(n); | ||
|
||
a.par_iter_mut() | ||
.enumerate() | ||
.for_each(|(i, x)| *x = b[i] + d[i] * c[i]); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in 0..n { | ||
// a[i] = b[i] + d[i] * c[i]; | ||
// } | ||
|
||
// Parallel version | ||
a_iter.for_each(|a_slice| { | ||
a_slice | ||
.iter_mut() | ||
.enumerate() | ||
.for_each(|(i, val)| *val = c[i].mul_add(d[i], b[i])) | ||
}); | ||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut}; | ||
|
||
#[allow(clippy::ptr_arg, unused_variables)] | ||
pub fn triad(a: &mut Vec<f64>, b: &Vec<f64>, c: &Vec<f64>, scalar: f64, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
#[inline(never)] | ||
pub fn triad(a: &mut [f64], b: &[f64], c: &[f64], scalar: f64, n: usize) -> f64 { | ||
let a_iter = a.par_chunks_mut(n); | ||
|
||
a.par_iter_mut() | ||
.enumerate() | ||
.for_each(|(i, x)| *x = b[i] + scalar * c[i]); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in 0..n { | ||
// a[i] = b[i] + scalar * c[i]; | ||
// for i in 0..(n * 8) { | ||
// a[i] = c[i].mul_add(scalar, b[i]); | ||
// } | ||
|
||
// Parallel version | ||
a_iter.for_each(|a_slice| { | ||
a_slice | ||
.iter_mut() | ||
.enumerate() | ||
.for_each(|(i, val)| *val = c[i].mul_add(scalar, b[i])) | ||
}); | ||
|
||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
use std::time::Instant; | ||
|
||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator}; | ||
use rayon::{iter::ParallelIterator, slice::ParallelSliceMut}; | ||
|
||
#[allow(clippy::ptr_arg, unused_variables)] | ||
pub fn update(b: &mut Vec<f64>, scalar: f64, n: usize) -> f64 { | ||
let s = Instant::now(); | ||
pub fn update(b: &mut [f64], scalar: f64, n: usize) -> f64 { | ||
let b_iter = b.par_chunks_mut(n); | ||
|
||
b.par_iter_mut().for_each(|x| *x += scalar); | ||
let s = Instant::now(); | ||
|
||
// Serial version | ||
// for i in b.iter_mut().take(n) { | ||
// *i += scalar; | ||
// } | ||
|
||
// Parallel version | ||
b_iter.for_each(|b_slice| b_slice.iter_mut().for_each(|val| *val += scalar)); | ||
|
||
s.elapsed().as_secs_f64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters