根据我的理解,我可以使用single指令做与sections仅使用添加nowait标志相同的工作
与section指令相比,以下代码对我没有什么不同:
void main(){
#pragma omp parallel
{
int tid = omp_get_thread_num();
#pragma omp single nowait
{
printf("Thread %d in #1 single construct.\n", tid);
}
#pragma omp single nowait
{
printf("Thread %d in #2 single construct.\n", tid);
}
#pragma omp single nowait
{
printf("Thread %d in #3 single construct.\n", tid);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谁能给我一些在不同场景中使用sections和single指令的例子?
一开始,我尝试过conda install dill,conda但无法在互联网上找到它。
然后我从这里下载了默认 IPython 目录中的.tgz和.zip文件:https :
//pypi.python.org/pypi/dill
之后我尝试了以下命令:
conda install dill-0.2b1.zip
conda install "C:\<rest_of_the_complete_path>\dill-0.2b1.zip"
对于.tgz. 所有四次尝试都产生了错误:
No packages found matching:
我做错了什么?我正在尝试重复以下链接中给出的示例:http : //nbviewer.ipython.org/gist/minrk/5241793
编辑 1:我dill通过运行.exe来自https://pypi.python.org/pypi/dill的文件安装在我的系统上。这一步安装dill在我的系统 python ( C:\Python27) 上,但没有安装在我的 Anaconda Python 上。我假设这两个numpypython是分开的,因为我可以在两者上导入常用模块(例如)——我通过的 pythoncmd和我通过我的 IPython 笔记本访问的那个——但我dill只能在我访问的 python 上导入cmd而不是在我的 IPython 笔记本中。
正如标题中所说,我想知道该-k选项(强烈)是否会影响 GNU 并行的速度。
在man parallel_tutorial存在关于讨论--ungroup和--line-buffer,其声称--linebuffer,其unmixes输出线,比要慢得多--ungroup。那么-k当工作数量很大时,也许也会导致大幅放缓?
(我没有在man parallel或 中找到这个主题man parallel_tutorial;我也没有在谷歌上找到任何东西。不过我还没有完成man parallel,所以如果我错过了一些搜索较少的东西,请原谅。)
我目前正在学习 OpenCL 并遇到了这个代码片段:
int gti = get_global_id(0);
int ti = get_local_id(0);
int n = get_global_size(0);
int nt = get_local_size(0);
int nb = n/nt;
for(int jb=0; jb < nb; jb++) { /* Foreach block ... */
pblock[ti] = pos_old[jb*nt+ti]; /* Cache ONE particle position */
barrier(CLK_LOCAL_MEM_FENCE); /* Wait for others in the work-group */
for(int j=0; j<nt; j++) { /* For ALL cached particle positions ... */
float4 p2 = pblock[j]; /* Read a cached particle position */
float4 d = …Run Code Online (Sandbox Code Playgroud) 我想并行化以下代码段,但我是 openmp 和创建并行代码的新手。
std::vector<DMatch> good_matches;
for (int i = 0; i < descriptors_A.rows; i++) {
if (matches_RM[i].distance < 3 * min_dist) {
good_matches.push_back(matches_RM[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
我试过了
std::vector<DMatch> good_matches;
#pragma omp parallel for
for (int i = 0; i < descriptors_A.rows; i++) {
if (matches_RM[i].distance < 3 * min_dist) {
good_matches[i] = matches_RM[i];
}
}
Run Code Online (Sandbox Code Playgroud)
和
std::vector<DMatch> good_matches;
cv::DMatch temp;
#pragma omp parallel for
for (int i = 0; i < descriptors_A.rows; i++) {
if (matches_RM[i].distance < 3 * min_dist) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试将“旧方式”循环转换为基于流的方法。该循环采用一大组元素并返回一个落在给定半径内的子集。结果按距离排序,并且结果本身具有方便的计算距离(用于演示)。它以旧方式工作正常,我不需要对它进行 Java8 化。但我真的很想。:-) 如果只是为了能够在这个傻瓜上使用 .parallel() 就好了。
问题是……我的 filter() 使用了一个计算值(距离),然后我需要在后续的 map() 步骤中使用它(以构建“with distance”实例)。假设距离计算很昂贵。这是 Java 7 的方式……向下滚动以查看 getNearestStations() 方法:
public interface Coordinate {
double distanceTo(Coordinate other);
}
public class Station {
private final String name;
private final Coordinate coordinate;
public Station(String name, Coordinate coordinate) {
this.name = name;
this.coordinate = coordinate;
}
public String getName() {
return name;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
public class StationWithDistance extends Station implements Comparable<StationWithDistance> {
private final double distance;
public …Run Code Online (Sandbox Code Playgroud) 我在 C++ AMP 中处理大型数组(超过 65536 个元素)时遇到问题。我正在使用 C++ amp 来计算多边形列表的法线、切线和双切线向量。输入由位置数组(每个位置 3 个浮点数)和 uv 坐标数组(每个顶点 2 个浮点数)组成。在我的parallel_for_each函数中,我计算法线、切线和双切线(每组3个顶点各1个)。我将它们写回数组(封装在 array_view 中)。该算法如下所示:
concurrency::extent<2> ePositions(positionsVector.size() / 3, 3);
concurrency::array_view<const float, 2> positions(ePositions, positionsVector);
concurrency::extent<2> eUVs(uvsVector.size() / 2, 2);
concurrency::array_view<const float, 2> UVs(eUVs, uvsVector);
concurrency::extent<2> eNormalDirections(normalDirectionsVector.size() / 3, 3);
concurrency::array_view<float, 2> normalDirections(eNormalDirections, normalDirectionsVector);
normalDirections.discard_data();
concurrency::extent<2> eTangentDirections(tangentDirectionsVector.size() / 3, 3);
concurrency::array_view<float, 2> tangentDirections(eTangentDirections, tangentDirectionsVector);
tangentDirections.discard_data();
concurrency::extent<2> eBitangentDirections(bitangentDirectionsVector.size() / 3, 3);
concurrency::array_view<float, 2> bitangentDirections(eBitangentDirections, bitangentDirectionsVector);
bitangentDirections.discard_data();
concurrency::parallel_for_each(eNormalDirections.tile<1, 3>(), [=](concurrency::tiled_index<1, 3> t_idx) restrict(amp)
{
< ... calculate the normals, tangents …Run Code Online (Sandbox Code Playgroud) 我已经使用pmap. 使用该-p选项在一台机器上的性能改进非常好。现在我想在多台机器上运行。
我--machinefile在 julia start 上使用了这个选项。它可以工作,但它只在远程机器上启动一个进程。我想在每台机器上运行多个进程。选项-p仅在本地机器上启用多个进程。有没有办法指定远程机器上的进程数?
我有一个关于我应该如何使用ThreadLocal.
背景和情况
有几个单例对象用于ThreadLocal为每个线程创建一个副本。这个单例对象有一个函数foo()。
public class SingletonA {
protected static ThreadLocal<SingletonA> singleton = new ThreadLocal<SingletonA>() {
@Override
protected SingletonA initialValue() {
return new SingletonA();
}
};
private SingletonA() { ... }
public static SingletonA getInstance() { return singleton.get(); }
public static void remove() { singleton.remove(); }
public static void foo() { ... }
}
Run Code Online (Sandbox Code Playgroud)
... 有 SingletonB、SingletonC 等等。
有一个单例存储库可以缓存ThreadLocal上面的单例。这个类也是一个ThreadLocal单例——
public class SingletonRepo {
protected static ThreadLocal<SingletonRepo> singleton = new ThreadLocal<SingletonRepo>() { …Run Code Online (Sandbox Code Playgroud) 我有一系列文档(约 50,000 个),我已经将这些文档转换为语料库并使用 R 中的 topicmodels 包构建 LDA 对象。不幸的是,为了测试 150 多个主题,需要几个小时。
到目前为止,我发现我可以使用以下方法同时测试几个不同的集群大小:
library(topicmodels)
library(plyr)
library(foreach)
library(doMC)
registerDoMC(5) # use 5 cores
dtm # my documenttermmatrix
seq <- seq(200,500, by=50)
models <- llply(seq, function(d){LDA(dtm, d)}, .parallel=T)
Run Code Online (Sandbox Code Playgroud)
有没有办法并行化 LDA 函数,使其运行得更快(而不是一次运行多个 LDA)?