1

我运行了如下所示的代码。但是,我认为所做的部分并没有tokio.spawn被执行。尽管我.await在调用该函数时仍然如此。我怎样才能解决这个问题?

pub async fn multi_features(
    chainlen: usize, floatlen: usize, atom_num: usize,
    c: &Array2<f32>, v: &Array2<f32>, 
) -> (Array2<f32>, Array3<f32>) {
    let ca_features = Arc::new(Mutex::new(Array2::<f32>::zeros((atom_num/4+1, (2*chainlen + floatlen)*8+3))));

    let ca_basics = Arc::new(Mutex::new(Array3::<f32>::zeros((atom_num/4+1, 3, 3))));


    for atom_id in 0..atom_num {
        let ca_features = ca_features.clone();
        let ca_basics = ca_basics.clone();

        tokio::spawn(async move {
            let mut ca_features = ca_features.lock().unwrap();
            let mut ca_basics = ca_basics.lock().unwrap();

            let basic = now_basic_vec(atom_id, atom_num, c);
            ca_basics.index_axis_mut(Axis(0), atom_id/4).assign(&basic);

            let now_feature = features(atom_id, chainlen, floatlen, atom_num, &basic, c, v);
            ca_features.index_axis_mut(Axis(0), atom_id/4).assign(&now_feature);
        }).await.unwrap();
    }
    (Arc::try_unwrap(ca_features).unwrap().into_inner().unwrap(), Arc::try_unwrap(ca_basics).unwrap().into_inner().unwrap(),)
}

#[tokio::main]
fn main() {

    let res = multi_features(50, 50, 1253,&c, &v).await; // this function is never end
}
4

0 回答 0