在访问共享内存时,Kepler的费用是Fermi的2倍还是4倍?
编程指南说明:"每个存储区每两个时钟周期带宽为32位"(对于2.X),"每个存储区的每个时钟周期带宽为64位"(3.X),因此暗示了4倍?
由于我怀疑“黑匣子”(GPU)在某些较大的代码(可能还有其他代码)中没有完全关闭,因此我会cudaDeviceReset()在main(). 可是等等!这将在析构函数Segmentation fault中main()使用非平凡的 CUDA 代码静态创建的所有类实例,对吗?例如
class A {
public:
cudaEvent_t tt;
cudaEvent_t uu;
A() {
cudaEventCreate(&tt);
cudaEventCreate(&uu);
}
~A(){
cudaEventDestroy(tt);
cudaEventDestroy(uu);
}
};
Run Code Online (Sandbox Code Playgroud)
静态实例化:
int main() {
A t;
cudaDeviceReset();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
退出时出现段错误。问题:可能cudaDeviceReset()在退出时自动调用main()?
否则整个有用的代码main()应该转移到 some run(),并且cudaDeviceReset()应该是 中的最后一个命令main(),对吗?
在最简单的Spring(Boot)应用程序中,我会观察到控制器的以下行为
@CrossOrigin
@RestController
public class MyController {
//...
@RequestMapping(value = {"/lazy-dog"})
@ResponseBody
public Rest lazyDog() {
//...
Thread.sleep(10000);
//
return Message("Dog exiting")
}
@RequestMapping(value = {"/quick-fox"})
@ResponseBody
public Rest quickFox() {
//...
return Message("Fox exiting")
}
}
Run Code Online (Sandbox Code Playgroud)
即:同步进入lazyDog()是不允许的(从两个浏览器标签调用两次持续20sec),而并发执行lazyDog(),并quickFox()允许(如狗等待,狐狸可以快速执行,说在不同的浏览器选项卡).
应该做些什么来允许并发执行两个或多个调用lazyDog()?
注意:我目前正在通过以下方式启动该应用:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud) 为了学习boost :: thread的组合,我正在为线程实现一个简单的屏障(BR)来锁定一个普通的互斥锁(M).但是,就我转到BR.wait()而言,互斥锁上的锁定没有释放,因此为了让所有线程都到达BR,需要手动释放M上的锁定.所以我有以下代码:
boost::barrier BR(3);
boost::mutex M;
void THfoo(int m){
cout<<"TH"<<m<<" started and attempts locking M\n";
boost::lock_guard<boost::mutex> ownlock(M);
cout<<"TH"<<m<<" locked mutex\n";
Wait_(15); //simple wait for few milliseconds
M.unlock(); //probably bad idea
//boost::lock_guard<boost::mutex> ~ownlock(M);
// this TH needs to unlock the mutex before going to barrier BR
cout<<"TH"<<m<<" unlocked mutex\n";
cout<<"TH"<<m<<" going to BR\n";
BR.wait();
cout<<"TH"<<m<<" let loose from BR\n";
}
int main()
{
boost::thread TH1(THfoo,1);
boost::thread TH2(THfoo,2);
boost::thread TH3(THfoo,3);
TH2.join(); //but TH2 might end before TH1, and so destroy BR …Run Code Online (Sandbox Code Playgroud) 执行这个简单的代码:
int foo(int* a){
cout <<"a="<<a;
*a=1;
cout <<", *a="<<*a<<endl;
return 0;}
int main () {
int* ptr;
ptr=new int[2];
ptr[0]=0;
ptr[1]=0;
cout<< foo(ptr) <<" "<< ptr <<" *ptr="<< *ptr <<endl;
cout<< foo(ptr) <<" "<< ptr <<" *ptr="<< *ptr <<endl;
return 0;}
Run Code Online (Sandbox Code Playgroud)
导致(linux):
a=0x939f008, *a=1
0 0x939f008 *ptr=0
a=0x939f008, *a=1
0 0x939f008 *ptr=1
Run Code Online (Sandbox Code Playgroud)
请解释为什么*ptr = 0在第二行,但不在第四行; 可能是,"东西" cout从右到左被"取出" ?比 - 它如何真正起作用(在运行时一步一步)?
c++ pointers side-effects function-calls operator-precedence
我对gcc 4.5.2有一个有趣的问题.以下代码
#include<thread>
#include<iostream>
using std::cout;
void foo(int a){
cout<<a;
}
template <typename T>
void goo(void (*fn)(T),T c){
fn(c);
}
int main(void)
{
std::thread TH;
void (*ptr)(int)=foo;
TH= std::thread(goo<int>,ptr,1);
TH.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
..不会在gcc 4.5.2上编译,error: cannot bind ‘void(void (*)(int), int)’ lvalue to ‘void (&&)(void (*)(int), int)’后面跟着第二个错误initializing argument 1 of ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void(void (*)(int), int), _Args = {void (*&)(int), int}]’
但是,这个代码在template删除时会编译,并且它也会使用gcc 4.7.0(template在适当的位置)进行编译.
即使这是编译器问题,有人可以解释这样的错误意味着什么吗?我很乐意找到一种方法来进行绑定(即使这是gcc 4.7中的自动).
假设我们需要使用8MB堆栈,并希望使用标准C++数组.
这是真的吗?
const int MX = 10000;
int DP[MX][MX];
int main() {
printf("%likB\n", (sizeof(DP))>>10);
}
Run Code Online (Sandbox Code Playgroud)
使用堆内存,因此不会出现段错误(与DP声明时相反main)?它是经由内存分配不同的new/ malloc在main(除了free问题)?
c++ ×4
cuda ×2
boost-mutex ×1
boost-thread ×1
c++11 ×1
gpgpu ×1
gpu ×1
nvidia ×1
pointers ×1
side-effects ×1
spring ×1
spring-boot ×1
spring-mvc ×1
templates ×1