我正在使用concurrent.futures来实现多处理.我得到一个队列.全错误,这是奇怪的,因为我只分配10个工作.
A_list = [np.random.rand(2000, 2000) for i in range(10)]
with ProcessPoolExecutor() as pool:
pool.map(np.linalg.svd, A_list)
Run Code Online (Sandbox Code Playgroud)
错误:
Exception in thread Thread-9:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/process.py", line 251, in _queue_management_worker
shutdown_worker()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/process.py", line 209, in shutdown_worker
call_queue.put_nowait(None)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/multiprocessing/queues.py", line 131, in put_nowait
return self.put(obj, False)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/multiprocessing/queues.py", line 82, in put
raise Full
queue.Full
Run Code Online (Sandbox Code Playgroud) python parallel-processing multiprocessing concurrent.futures
我在我的反应层次结构的顶层有一个元素数组,我想用一个带有元素值(一个字符串)的参数来设置onClick函数.但是,当我尝试打印此值时,将打印"代理"对象:Proxy {dispatchConfig: null, _targetInst: null, isDefaultPrevented: null, isPropagationStopped: null, _dispatchListeners: null…}
这是我的渲染函数中的代码:
return collapseChoices.map((choice) => {
console.log(choice)
return (
<div className="collapseChoice"
onClick={(choice) => this.handleCollapse(choice)}>
{choice}
</div>
);
Run Code Online (Sandbox Code Playgroud)
这是handleCollapse函数:
handleCollapse(mark){
console.log(mark);
}
Run Code Online (Sandbox Code Playgroud)
我确保this在构造函数中绑定
constructor(){
super();
this.handleCollapse = this.handleCollapse.bind(this);
}
Run Code Online (Sandbox Code Playgroud) 所以我尝试用 Cython 包装一些 C 代码。我阅读了有关执行此操作的应用 Cython 的教程(1、2),但是这些教程没有过多说明如何在使用 Cython 包装代码后编译代码,因此我收到错误消息,指出它找不到我的 C代码。
首先,我的 cython 脚本(“calcRMSD.pyx”):
import numpy as np
cimport numpy as np
cdef extern from "rsmd.h":
double rmsd(int n, double* x, double* y)
#rest of the code ommited
Run Code Online (Sandbox Code Playgroud)
我试图包装的 C 代码(“rmsd.h”):
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
extern "C" {
// svd from lapack
void dgesvd_(char*,char*,int*,int*,double*,int*,double*,double*,int*,double*,
int*,double*,int*,int*);
}
double rmsd(int n, double* x, double* y)
{
//code omitted
}
Run Code Online (Sandbox Code Playgroud)
安装程序.py
from distutils.core import setup
from …Run Code Online (Sandbox Code Playgroud) 以下是数据的编写方式(浮点数的2-D矩阵.我不确定大小).
open(unit=51,file='rmsd/'//nn_output,form='unformatted',access='direct',status='replace',&
recl=Npoints*sizeofreal)
!a bunch of code omitted
write(51,rec=idx-nstart+1) (real(dist(jdx)),jdx=1,Npoints)
Run Code Online (Sandbox Code Playgroud)
f = open(inputfilename,'rb')
field = np.fromfile(f,dtype='float64')
Run Code Online (Sandbox Code Playgroud)
但结果不正确.矩阵的对角线应为0(或非常接近),因为它是相似矩阵.我尝试了不同dtype的但我仍然无法得到正确的结果.
编辑:这是我得到的输出
array([ 1.17610188e+01, 2.45736970e+02, 7.79741823e+02, ...,
9.52930627e+05, 8.93743127e+05, 7.64186127e+05])
Run Code Online (Sandbox Code Playgroud)
我还没有为重塑而烦恼,因为值应该在0到20之间.
编辑2:这是指向文件前100行的链接:https: //drive.google.com/file/d/0B2Mz7CoRS5g5SmRxTUg5X19saGs/view?usp =sharing
编辑3:文件顶部的声明
integer,parameter :: real_kind=8
!valuables for MPI
integer :: comm, nproc, myid, ierr
integer,allocatable :: idneigh(:)
real :: tmp
real,allocatable :: traj(:,:)
real(real_kind),allocatable :: dist(:)
real(real_kind),allocatable :: xx(:,:),yy(:,:),rot(:),weight(:)
character(200) :: nn_traj, nn_output, nn_neigh
integer,parameter :: sizeofreal=4,sizeofinteger=4
Run Code Online (Sandbox Code Playgroud)