我已经看到了并行合并排序的算法此文件.这是代码:
void mergesort_parallel_omp (int a[], int size, int temp[], int threads)
{
if ( threads == 1) { mergesort_serial(a, size, temp); }
else if (threads > 1)
{
#pragma omp parallel sections
{
#pragma omp section
mergesort_parallel_omp(a, size/2, temp, threads/2);
#pragma omp section
mergesort_parallel_omp(a + size/2, size - size/2, temp + size/2, threads - threads/2);
}
merge(a, size, temp);
} // threads > 1
}
Run Code Online (Sandbox Code Playgroud)
我在多核上运行它.发生的事情是,在树的叶子上,2个线程并行运行.完成工作后,其他2个线程开始,依此类推.即使我们有所有叶节点的免费核心.
我认为原因是这个OpenMP代码不会在并行区域内创建并行区域.我对么?
I am using RFECV for feature selection in scikit-learn. I would like to compare the result of a simple linear model (X,y) with that of a log transformed model (using X, log(y))
Simple Model:
RFECV and cross_val_score provide the same result (we need to compare the average score of cross-validation across all folds with the score of RFECV for all features: 0.66 = 0.66, no problem, results are reliable)
Log Model: the Problem: …
Sklearn 在#15075中有一个实现此功能的提案,但与此同时,eli5建议将其作为解决方案。但是,我不确定我是否以正确的方式使用它。这是我的代码:
from sklearn.datasets import make_friedman1
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR
import eli5
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = SVR(kernel="linear")
perm = eli5.sklearn.PermutationImportance(estimator, scoring='r2', n_iter=10, random_state=42, cv=3)
selector = RFECV(perm, step=1, min_features_to_select=1, scoring='r2', cv=3)
selector = selector.fit(X, y)
selector.ranking_
Run Code Online (Sandbox Code Playgroud)
有几个问题:
我不确定我是否以正确的方式使用交叉验证。PermutationImportance用于cv验证验证集的重要性,或者交叉验证应该仅使用RFECV? (在示例中,我cv=3在两种情况下都使用了,但不确定这是否是正确的做法)
如果我运行eli5.show_weights(perm),我会得到:AttributeError: 'PermutationImportance' object has no attribute 'feature_importances_'。这是因为我适合使用吗RFECV?我正在做的事情与这里的最后一个片段类似: https: //eli5.readthedocs.io/en/latest/blackbox/permutation_importance.html
cv作为一个不太重要的问题,当我设置时,这给了我一个警告eli5.sklearn.PermutationImportance:
.../lib/python3.8/site-packages/sklearn/utils/validation.py:68: FutureWarning: Pass …
以下代码基于OpenMP 4.0规范工作:
out和inout依赖类型.生成的任务将是所有先前生成的兄弟任务的从属任务,其引用入口,出口或入口依赖类型列表中的至少一个列表项.
这意味着task3变得依赖于task2.对?但它没有意义!为什么输入 - 输出依赖性任务应该是输入依赖性任务的依赖?
为了使它们独立,我需要做什么?ps:在Linux上使用g ++ 4.9进行代码测试.
#include <stdio.h>
#include <omp.h>
#include <unistd.h>
int main() {
int x,y;
#pragma omp parallel num_threads(10)
{
#pragma omp single nowait
{
#pragma omp task depend (out:x) //task1
{
x=1;
}
#pragma omp task depend(in:x) depend(out:y) //task2
{
sleep(2); //Does task3 wait for us? Yes!
y=x+1;
}
#pragma omp task depend (inout:x) //task3
{
x++;
printf("task3(x): %d\n" , x);
}
#pragma omp task depend (in:x,y) //task4
{
printf("task4 (x+y): %d\n" …Run Code Online (Sandbox Code Playgroud) 我想使用数组指针(带数组运算)作为非类型参数.我知道这个参数应该在编译时知道,但对于固定大小的全局数组不是这样吗?
此示例可以打印前两行,但不能打印第三行.这有什么解决方法吗?
编辑:我在寻找的不仅是一个答案aa+1,但所有aa+is其中i小于大小aa
#include <iostream>
void print (int n) {
printf("the value is: %d\n", n);
}
template <int *n>
void myWrapper() {
print(*n);
}
void myCall(void (*CALLBACK)(void)) {
CALLBACK();
}
int a = 1; int aa[4] = {2,3,4,5};
int main()
{
myCall(myWrapper<&a>); // prints 1
myCall(myWrapper<aa>); // prints 2
/* the following line gives error: no matches converting function 'myWrapper' to type 'void (*)()'
note: candidate is: template<int* n> void myWrapper()
*/ …Run Code Online (Sandbox Code Playgroud) 问题:如何使用" placement new "创建动态大小的数组?或者更具体地说,如何从预先分配的存储器中为数组元素分配存储器.
我使用以下代码:
void* void_array = malloc(sizeof(Int));
Int* final_array = new(void_array) Int;
Run Code Online (Sandbox Code Playgroud)
这保证了final_array*(数组指针)是从void_array*保留的位置分配的.但是final_array元素呢?我希望它们也可以从预先分配的内存中分配.
PS:我不得不说我正在使用一些API来给我一些控制瓦片架构.有一个函数与malloc完全相同,但也有其他功能,例如,让您控制分配的内存的属性.所以,我基本上需要做的是,使用类似malloc的函数来分配具有我所需属性的内存(例如从哪个内存库,缓存在哪里等等)
我想知道是否有任何技术可以使用for循环在OpenMp中创建并行部分。
例如,与创建n个不同的#pragma omp节不同,我想使用n个迭代的for循环创建它们,并为每个节使用一些更改的参数。
#pragma omp parallel sections
{
#pragma omp section
{
/* Executes in thread 1 */
}
#pragma omp section
{
/* Executes in thread 2 */
}
#pragma omp section
{
/* Executes in thread n */
}
}
Run Code Online (Sandbox Code Playgroud) template<typename C, typename Arg>
int foo(C* c, int (C::*func)(Arg), Arg a)
{
c->*func(a);
}
Run Code Online (Sandbox Code Playgroud)
要调用'foo',我们必须同时使用A*和&A :: bar,
foo(A*,&A::bar,var);
Run Code Online (Sandbox Code Playgroud)
有没有办法定义模板(例如作为结构),这样就不需要传递"A*"了?如何定义从"&A :: bar"获取A*的模板?