I am trying to transcribe a python code in Julia. I have a matrix
test = [2.0 3.0 4.0
3.0 4.0 5.0
4.0 5.0 6.0]
Run Code Online (Sandbox Code Playgroud)
I am computing the (Moore-Penrose) pseudo-inverse of a matrix in Python using numpy.linalg.pinv and the result is
[[-8.33333333e-01 -1.66666667e-01 5.00000000e-01]
[-1.66666667e-01 -7.86535165e-17 1.66666667e-01]
[ 5.00000000e-01 1.66666667e-01 -1.66666667e-01]]
Run Code Online (Sandbox Code Playgroud)
while in Julia the result of LinearAlgebra.pinv(test) is
3×3 Array{Float64,2}:
-1.33333 -0.166667 1.0
-0.166667 -6.59195e-17 0.166667
1.0 0.166667 -0.666667
Run Code Online (Sandbox Code Playgroud)
I would like to ask if anybody knows why …
我编写了以下函数,它接受一个对象 ( element),在现有向量 ( elements) 中为它腾出空间,并通过添加新对象来更新向量:
void addElement(const ElementType& element) {
if (numElements == elements.size()) {
elements.resize(boost::extents[numElements+1]);
}
elements[numElements] = element;
numElements++;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它对 MPI 线程安全?据我了解,每个线程都知道的大小elements是多少,因此我不明白为什么这个函数不是线程安全的。numElements在此函数外初始化为零,并且是elements向量的大小。
编辑:我使用上面写的函数和 mtx 锁定和解锁如下,但最终elements向量仍然只包含来自第一级的数据。
#pragma omp parallel for collapse(3) schedule(static)
for (long n0 = mgr->startN0; n0 < mgr->startN0 + mgr->localN0; n0++) {
for (int n1 = 0; n1 < ?; n1++) {
for (int n2 = 0; n2 < ?; n2++) {
ElementType element;
std::mutex …Run Code Online (Sandbox Code Playgroud)