ifndef FUN_HPP
define FUN_HPP
if defined(USE_EXPORT)
define EXPORT export
else
define EXPORT
endif
EXPORT
template
void print_typeof(T const&);
if !defined(USE_EXPORT)
include"fun.cpp"
endif // !ined(USE_EXPORT)
endif // FUN_HPP
可以灵活使用,不过有的编译器不支持。
export不能和inline同时使用
一个.hpp,另一个.hpp实例化即可
一个.hpp,一个.cpp,包含.cpp即可
一个.h,一个.hpp,一个.cpp初始化,主函数调用;
//.cu
include <stdio.h>
include <time.h>
include
global void HelloFromGPU(void)
{
printf("Hello from GPU\n");
}
void HelloCpu()
{
for (int i = 0; i < 10; i++)
{
printf("i = %d\n", i);
}
}
int main(void)
{
pragma omp parallel for
for (int i = 0; i < 2; i++)
{
HelloCpu();
}
clock_t start, start2, finish, finish2;
double totaltime;
double totaltime2;
start = clock();
HelloCpu();
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
std::cout << "\n此程序的运行时间为" << totaltime << "秒!" << std::endl;
start2 = clock();
HelloFromGPU << <1, 5 >> > ();
finish2 = clock();
cudaDeviceReset();
totaltime2 = (double)(finish2 - start2) / CLOCKS_PER_SEC;
std::cout << "\n此程序的运行时间为" << totaltime2 << "秒!" << std::endl;
return 0;
}
标签:hpp,clock,void,打印,EXPORT,CUDA,cpp,include,模板 From: https://www.cnblogs.com/timapi/p/16711215.html