我正在为具有不同数据结构和技术(向量,数组和OpenMP)的矩阵实现C++乘法,我发现了一个奇怪的情况......我的动态数组版本运行得更好:
时间:
openmp mult_1:time:5.882000 s
array mult_2:time:1.478000 s
我的编译标志是:
/ usr/bin/g ++ -fopenmp -pthread -std = c ++ 1y -O3
C++矢量版
typedef std::vector<std::vector<float>> matrix_f;
void mult_1 (const matrix_f & matrixOne, const matrix_f & matrixTwo, matrix_f & result) {
const int matrixSize = (int)result.size();
#pragma omp parallel for simd
for (int rowResult = 0; rowResult < matrixSize; ++rowResult) {
for (int colResult = 0; colResult < matrixSize; ++colResult) {
for (int k = 0; k < matrixSize; ++k) {
result[rowResult][colResult] += …Run Code Online (Sandbox Code Playgroud) 我正在将Rust 中的多态性解决方案应用于我的问题。我想使用这个解决方案,Box<_>因为它看起来最直接和简单,但它不起作用。
#[derive(Clone, Copy)]
pub struct NewPost;
#[derive(Clone, Copy)]
pub struct Post;
#[derive(Clone, Copy)]
pub struct PgConnection;
#[derive(Clone, Copy)]
pub struct DBPost;
pub trait DBAdapter {
fn create(self, post: NewPost) -> Post;
fn read(self) -> Vec<Post>;
}
impl DBPost {
// DATABASE classes
pub fn establish_connection(self) -> PgConnection {
unimplemented!()
}
}
impl DBAdapter for DBPost {
fn create(self, _post: NewPost) -> Post {
unimplemented!()
}
fn read(self) -> Vec<Post> {
unimplemented!()
}
}
struct GetPostsCase …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Rust中配置一个示例项目.
我的结构是:
src/potter.rstests/tests.rs和我的 Cargo.toml
[package]
name = "potter"
version = "0.1.0"
authors = ["my name"]
[dependencies]
Run Code Online (Sandbox Code Playgroud)
我的potter.rs包含:
pub mod potter {
pub struct Potter {
}
impl Potter {
pub fn new() -> Potter {
return Potter {};
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的tests.rs包含:
use potter::Potter;
#[test]
fn it_works() {
let pot = potter::Potter::new();
assert_eq!(2 + 2, 4);
}
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
error[E0432]: unresolved import `potter`
--> tests/tests.rs:1:5
|
1 | use potter::Potter;
| ^^^^^^ Maybe a missing …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 rust 中设置对象/结构的哈希图......但我不明白这个具体问题(终身错误)。
#[derive(Hash, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Node<'a> {
identifier: &'a str,
sha_id: Vec<u8>,
successor_id: Option<Vec<u8>>,
predecessor_id: Option<Vec<u8>>,
}
impl<'a> Node<'a> {
...
..
.
}
pub struct Application<'a> {
hash_map: HashMap<&'a str, Node>,
}
impl<'a> Application<'a> {
fn join(&self, node: &Node) {
self.hash_map.insert(node.identifier, node);
}
}
Run Code Online (Sandbox Code Playgroud)
错误是缺少生命周期说明符hash_map: HashMap<&'a str, Node>,我试图解决将 Node 更改为 Node<'a> 的问题,但是当我尝试插入时它会引发“类型不匹配”错误...
我不知道为什么我有这个问题错过了整个生命周期而且我没有找到解决方案..
更新:
#[derive(Hash, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Node<'a> {
identifier: &'a str,
sha_id: Vec<u8>,
successor_id: Option<Vec<u8>>, …Run Code Online (Sandbox Code Playgroud)