C++代码是否合法,或者我的编译器有问题吗?代码被编译到一个共享库中使用
gcc版本4.4.6 20110731(Red Hat 4.4.6-3)(GCC)
和openMP然后通过R 2.15.2调用.
int it=0;
#pragma omp parallel sections shared(it)
{
#pragma omp section
{
std::cout<<"Entering section A"<<std::endl;
for(it=0;it<10;it++)
{
std::cout<<"Iteration "<<it<<std::endl;
}
std::cout<<"Leaving section A with it="<<it<<std::endl;
}
#pragma omp section
{
std::cout<<"Entering section B with it="<<it<<std::endl;
while(it<10)
{
1;
}
std::cout<<"Leaving section B"<<std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我获得了以下输出(对于从2个线程交织输出的道歉,但我认为它是可解释的):
Entering section A
Iteration Entering section B with it=0
0
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 7
Iteration 8
Iteration 9 …Run Code Online (Sandbox Code Playgroud) 我想通过分面 geom_function 创建 ggplot2 图,以便函数的参数在网格中变化。例如这样的东西:
my_function<-function(x, par)
{
if(par==1)
{
return(sin(x))
}
else
{
return(cos(x))
}
}
> head(data)
x parameter
1 -1.00 1
2 -0.99 1
3 -0.98 1
4 -0.97 1
5 -0.96 1
6 -0.95 1
> tail(data)
x parameter
397 0.95 2
398 0.96 2
399 0.97 2
400 0.98 2
401 0.99 2
402 1.00 2
> my_plot<-ggplot(data, aes(x)) + geom_function(fun = my_function, args=list(par=parameter)+facet_wrap(~parameter)
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为“参数”不在 geom_function 的 args 参数范围内。这可能吗?