并行 STL 算法是否符合std::back_insert_iterator??
我可能误解了std::par和之间的区别std::par_vec,是否std::par_vec意味着需要预先分配输出范围?
代码示例:
auto numbers = {1,2,3,4,5,6};
auto squared = std::vector<int>{};
std::transform(
**std::par/std::par_vec,**
numbers.begin(),
numbers.end(),
std::back_inserter(squared),
[](auto val) {
return val*val;
}
);
Run Code Online (Sandbox Code Playgroud)
更新
简化问题作为我的第一个问题是误读文章的结果。
I have an IEnumerable<IEnumerable<T>> method called Batch that works like
var list = new List<int>() { 1, 2, 4, 8, 10, -4, 3 };
var batches = list.Batch(2);
foreach(var batch in batches)
Console.WriteLine(string.Join(",", batch));
Run Code Online (Sandbox Code Playgroud)
-->
1,2
4,8
10,-4
3
Run Code Online (Sandbox Code Playgroud)
The problem I've having is that I'm to optimize something like
foreach(var batch in batches)
ExecuteBatch(batch);
Run Code Online (Sandbox Code Playgroud)
by
Task[] tasks = batches.Select(batch => Task.Factory.StartNew(() => ExecuteBatch(batch))).ToArray();
Task.WaitAll(tasks);
Run Code Online (Sandbox Code Playgroud)
or
Action[] executions = batches.Select(batch => new Action(() => ExecuteBatch(batch))).ToArray();
var options = new ParallelOptions …Run Code Online (Sandbox Code Playgroud) 我可以使用具有多个 CPU 内核(即 56 个)的计算机,并且在使用 Tensorflow 训练模型时,我希望通过使每个内核成为模型的独立训练器来最大限度地利用上述内核。
在 Tensorflow 的文档中,我发现这两个参数(Inter 和 Intra Op 并行度)在训练模型时控制并行度。但是,这两个参数不允许执行我的意图。
我怎样才能让每个核心成为独立的工人?(即,一批样本由每个worker分片,然后每个worker根据分配的样本计算梯度。最后,每个worker根据它的梯度更新变量(由所有worker共享)计算过。
我第一次使用线程库是为了加快我的 SARIMAX 模型的训练时间。但代码不断失败并出现以下错误
Bad direction in the line search; refresh the lbfgs memory and restart the iteration.
This problem is unconstrained.
This problem is unconstrained.
This problem is unconstrained.
Run Code Online (Sandbox Code Playgroud)
以下是我的代码:
import numpy as np
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA
import statsmodels.tsa.api as smt
from threading import Thread
def process_id(ndata):
train = ndata[0:-7]
test = ndata[len(train):]
try:
model = smt.SARIMAX(train.asfreq(freq='1d'), exog=None, order=(0, 1, 1), seasonal_order=(0, 1, 1, 7)).fit()
pred = model.get_forecast(len(test))
fcst = pred.predicted_mean
fcst.index = test.index
mapelist …Run Code Online (Sandbox Code Playgroud) 我正在 R 中运行一些模拟,代码在不使用并行计算的情况下运行良好。但是,当我修改一行代码并尝试使用并行计算时,R 卡住了,并且每次都卡在不同的迭代时间。当 R 卡住时,我必须手动停止它运行,有时会有一些警告说
Warning messages:
1: closing unused connection 13 (<-localhost:11688)
2: closing unused connection 12 (<-localhost:11688)
3: closing unused connection 9 (<-localhost:11688)
4: closing unused connection 8 (<-localhost:11688)
5: closing unused connection 7 (<-localhost:11688)
6: closing unused connection 6 (<-localhost:11688)
Run Code Online (Sandbox Code Playgroud)
或者类似的东西
Warning message:
In .Internal(get(x, envir, mode, inherits)) :
closing unused connection 6 (<-localhost:11688)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
for (iter in 1:100){
*Simulate data matrix X and Y, and initial start Z0*
for (i in 1:100){
*Calculate input matrix …Run Code Online (Sandbox Code Playgroud) 这段代码给我带来了一个错误: Error in checkCluster(cl): not a valid cluster
library(parallel)
numWorkers <-8
cl <-makeCluster(numWorkers, type="PSOCK")
res.mat <- parLapply(1:10, function(x) my.fun(x))
stopCluster(cl)
Run Code Online (Sandbox Code Playgroud)
如果没有并行化尝试,这完全可以正常工作:
res.mat <- lapply(1:10, function(x) my.fun(x))
Run Code Online (Sandbox Code Playgroud)
这个例子也很有效:
workerFunc <- function(n){return(n^2)}
library(parallel)
numWorkers <-8
cl <-makeCluster(numWorkers, type ="PSOCK")
res <- parLapply(cl, 1:100, workerFunc)
stopCluster(cl)
print(unlist(res))
Run Code Online (Sandbox Code Playgroud)
我该如何解决我的问题?
我发现例如
class(cl)
[1] "SOCKcluster" "cluster"
Run Code Online (Sandbox Code Playgroud)
cl 是:
cl
socket cluster with 8 nodes on host ‘localhost’
Run Code Online (Sandbox Code Playgroud) 我有以下while并行运行的循环。(这logProcess是我之前在脚本中定义的一个函数。)
while read LINE; do
logProcess $LINE &
done <<< "$ELS_LOGS"
wait
Run Code Online (Sandbox Code Playgroud)
我需要找到一种方法来限制正在运行的进程数。我知道有并行进程在运行。如何转换循环以使用该命令?
我需要使用我的模型在 python 中批量和并行地进行预测。如果我加载模型并在常规 for 循环中创建数据框并使用 predict 函数,它就没有问题。如果我在 python 中使用 multiprocessing 并行创建不相交的数据帧,然后使用 predict 函数 for 循环无限期冻结。为什么会出现这种行为?
这是我的代码片段:
with open('models/model_test.pkl', 'rb') as fin:
pkl_bst = pickle.load(fin)
def predict_generator(X):
df = X
print(df.head())
df = (df.groupby(['user_id']).recommender_items.apply(flat_map)
.reset_index().drop('level_1', axis=1))
df.columns = ['user_id', 'product_id']
print('Merge Data')
user_lookup = pd.read_csv('data/user_lookup.csv')
product_lookup = pd.read_csv('data/product_lookup.csv')
product_map = dict(zip(product_lookup.product_id, product_lookup.name))
print(user_lookup.head())
df = pd.merge(df, user_lookup, on=['user_id'])
df = pd.merge(df, product_lookup, on=['product_id'])
df = df.sort_values(['user_id', 'product_id'])
users = df.user_id.values
items = df.product_id.values
df.drop(['user_id', 'product_id'], axis=1, inplace=True)
print('Prediction Step')
prediction = …Run Code Online (Sandbox Code Playgroud) 如果已经有人问过这个问题,我深表歉意,但我已经阅读了大量文档,但仍然不确定如何做我想做的事情。
我想同时在多个内核上运行 Python 脚本。
我在一个目录中有 1800 个 .h5 文件,名称为“snapshots_s1.h5”、“snapshots_s2.h5”等,每个文件的大小约为 30MB。这个 Python 脚本:
完成后,脚本然后从目录中读取下一个 h5py 文件并遵循相同的过程。因此,在进行这项工作时,没有一个处理器需要与任何其他处理器通信。
脚本如下:
import h5py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import cmocean
import os
from mpi4py import MPI
de.logging_setup.rootlogger.setLevel('ERROR')
# Plot writes
count = 1
for filename in os.listdir('directory'): ### [PERF] Applied to ~ 1800 .h5 files
with h5py.File('directory/{}'.format(filename),'r') as file:
### Manipulate 'filename' data. ### [PERF] Each fileI ~ 0.03 TB in …Run Code Online (Sandbox Code Playgroud) 我正在测试该类cv::ParallelLoopBody的图像处理代码。
我首先开始实现归一化,在那里我必须为每个通道划分具有特定值的所有像素,这是一个简单的并行代码。
但是,在测试它时,我没有看到任何区别。
我在这里做错了吗?
这是我的课:
class Parallel_process : public cv::ParallelLoopBody
{
private:
cv::Mat img; //my image to normalize
std::vector<int> A;
int diff;
public:
Parallel_process(cv::Mat inputImage, std::vector<int> AA, int diffVal)
: img(inputImage), A(AA), diff(diffVal){}
virtual void operator()(const cv::Range& range) const
{
for(int i = range.start; i < range.end; i++)
{
//in is a patch of my original image
cv::Mat in(img, cv::Rect(0, (img.rows/diff)*i, img.cols, img.rows/diff));
std::vector<int> AAA (A);
in.forEach<cv::Vec3f>
(
[&AAA](cv::Vec3f &pixel, const int* po) -> void
{
pixel[0]/=AAA[0];
pixel[1]/=AAA[1]; …Run Code Online (Sandbox Code Playgroud) c++ ×2
python ×2
r ×2
.net ×1
arima ×1
asynchronous ×1
bash ×1
c# ×1
c++17 ×1
connection ×1
lambda ×1
lightgbm ×1
linq ×1
memory ×1
mpi4py ×1
opencv ×1
python-2.7 ×1
stl ×1
tensorflow ×1