我在C++中编写了一个非常简单的类,即http://www.cplusplus.com/doc/tutorial/classes/中的Rectangle类.特别是这里是Header文件(Rectangle.h)的内容:
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle {
private:
double m_x;
double m_y;
public:
Rectangle();
Rectangle(double, double);
void setXY(double, double);
double getArea();
};
#endif
Run Code Online (Sandbox Code Playgroud)
这是实现(Rectangle.cpp):
#include "Rectangle.h"
Rectangle::Rectangle() {
setXY(1, 1);
}
Rectangle::Rectangle(double x, double y) {
setXY(x, y);
}
void Rectangle::setXY(double x, double y) {
m_x = x;
m_y = y;
}
double Rectangle::getArea(void) {
return m_x * m_y;
}
Run Code Online (Sandbox Code Playgroud)
现在,我应该在我的主类中包含矩形标题,即:
#include <stdlib.h>
#include <iostream>
#include "Rectangle.h"
using namespace std;
int main(void) {
Rectangle a;
cout << …Run Code Online (Sandbox Code Playgroud) 当我试图在MySQL数据库上使用C3P0执行一些简单的读取(SELECT)操作时,发生中断异常(java.lang.InterruptedException).当我将并行线程数增加到100以上(我尝试过5,10,20,60和100)时会发生异常.我执行的语句很简单:
SELECT `Model.id` FROM `Model` LIMIT 100;
Run Code Online (Sandbox Code Playgroud)
我的连接是从ComboPooledDataSource汇集的,它使用以下属性配置(另请参阅C3P0手册):
c3p0.jdbcUrl=jdbc:mysql...
c3p0.debugUnreturnedConnectionStackTraces=true
c3p0.maxIdleTime=5
c3p0.maxPoolSize=1000
c3p0.minPoolSize=5
c3p0.initialPoolSize=5
c3p0.acquireIncrement=3
c3p0.acquireRetryAttempts=50
c3p0.numHelperThreads=20
c3p0.checkoutTimeout=0
c3p0.testConnectionOnCheckin=true
c3p0.testConnectionOnCheckout=true
user=***
password=***
Run Code Online (Sandbox Code Playgroud)
我运行测试的机器上的MySQL服务器配置为接受1024个连接,并且我运行的单元测试成功执行(数据按预期从数据库中检索).但是,在C3P0日志文件中,我发现以下警告:
15:36:11,449 WARN BasicResourcePool:1876 - com.mchange.v2.resourcepool.BasicResourcePool@9ba6076 -- Thread unexpectedly interrupted while performing an acquisition attempt.
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Run Code Online (Sandbox Code Playgroud)
我想知道这个警告的原因,其次是它对软件稳健性和稳定性的可能影响.请注意,在使用之后,我会关闭结果集,SQL语句和连接.最后,一旦测试结束,我通过调用方法关闭池ComboPooledDataSource#close().更奇怪的(似乎是揭示同步问题)是,如果我使用以下内容给游泳池足够的时间......
Thread.sleep(10000); // wait for some time
datasource.close();
Run Code Online (Sandbox Code Playgroud)
日志中不会出现任何警告!你觉得这会给C3P0带来一个线程安全问题,还是我做错了什么?
更新1:
让我提一下Thread.sleep(10000),除了已经提到的内容之外,删除以下信息会在MySQL日志文件中记录:
110221 14:57:13 [Warning] Aborted connection 9762 to db: 'myDatabase' user: 'root'
host: 'localhost' (Got an error …Run Code Online (Sandbox Code Playgroud) 我正在用一些新的基准测试结果更新我的问题(我还重新提出了更具体的问题并更新了代码)...
我使用共享内存遵循CUDA C编程指南,在CUDA C中实现了用于矩阵向量乘法的内核.让我首先介绍一些我在Jetson TK1(GPU:Tegra K1,计算能力3.2)上做的基准测试结果以及与cuBLAS的比较:


在这里,我猜cuBLAS做了一些魔术,因为它的执行似乎不受列数的影响A,这反过来暗示了沿着列的某种并行化A.
现在,这是我的内核的源代码和一个调用它的主机函数(文件:mv.cuh):
#include <cuda_runtime.h>
#define BLOCK_SIZE 16
/* Set to __restric__ */
#define RESTRICT
/**
* Performs matrix-vector multiplication on the device.
*
* @param dA Address of matrix `A` on the device
* @param dx Address of vector `x` on the device
* @param dev_ptr_y Address of result y = A*x
* @param nRows Number of rows of `A`
* @param nx Size of `x` (number of …Run Code Online (Sandbox Code Playgroud) 我编写了一些C代码,在使用MEX编译之后我将其称为MATLAB.在C代码中,我使用以下代码测量计算的一部分时间:
clock_t begin, end;
double time_elapsed;
begin = clock();
/* do stuff... */
end = clock();
time_elapsed = (double) ((double) (end - begin) / (double) CLOCKS_PER_SEC);
Run Code Online (Sandbox Code Playgroud)
经过的时间应该是以秒为单位的执行时间.
然后我将值输出time_elapsed到MATLAB(它被正确导出;我检查过).然后MATLAB端我调用这个C函数(在我使用MEX编译它之后)并使用tic和测量它的执行时间toc.结果是完全荒谬的是我使用tic和toc计算的时间是0.0011s(500次运行时的平均值,st.dev.1.4e-4),而C代码返回的时间是0.037s(平均500次运行,st.dev.00,616).
人们可能会注意到两个非常奇怪的事实:
这些计时器发生了什么事?
许多人遇到的错误与以下消息相关:
[Warning] Aborted connection 38 to db: 'database_name' user:
'root' host: 'localhost' (Got an error reading communication packets)
Run Code Online (Sandbox Code Playgroud)
这是在 MySQL 日志中找到的。就我而言,数据库是通过 java 客户端使用驱动程序和众所周知的 C3P0 池在本地访问的。com.mysql.jdbc.Driver我的 MySQL 服务器配置为接受相当多的连接,并且 max_allowed_packet 值设置为 64M。以下是我的 my.cnf 文件(MySQL 配置)的摘录:
[mysqld]
max_allowed_packet = 64M
thread_concurrency = 8
thread_cache_size = 8
thread_stack = 192K
query_cache_size = 0
query_cache_type = 0
max_connections = 1024
back_log = 50
innodb_thread_concurrency = 6
innodb_lock_wait_timeout = 120
log_warnings
Run Code Online (Sandbox Code Playgroud)
和
[mysqldump]
quick
quote-names
max_allowed_packet = 64M
Run Code Online (Sandbox Code Playgroud)
我的数据库中的表User具有以下简单结构:
CREATE TABLE …Run Code Online (Sandbox Code Playgroud) 我阅读了Stack Overflow上的两篇文章,即cublas内核功能是否会自动与主机同步?和CUDA动态并行化;从设备进行流同步,他们建议使用某些同步API,例如cudaDeviceSynchronize()在调用cuBLAS函数之后。我不确定使用这样的通用功能是否有意义。
这样做会更好吗?[如果我错了纠正我]:
cublasHandle_t cublas_handle;
cudaStream_t stream;
// Initialize the matrices
CUBLAS_CALL(
cublasDgemm(cublas_handle, CUBLAS_OP_N, CUBLAS_OP_N, M, M,
M, &alpha, d_A, M, d_B, M, &beta, d_C, M));
// cublasDgemm is non-blocking!
cublasGetStream(cublas_handle, &stream);
cudaStreamSynchronize(stream);
// Now it is safe to copy the result (d_C) from the device
// to the host and use it
Run Code Online (Sandbox Code Playgroud)
另一方面,cudaDeviceSynchronize如果大量流/句柄用于执行并行cuBLAS操作,则可以优先使用。cuBLAS手柄同步的“最佳实践”是什么?从同步的角度来看,cuBLAS句柄是否可以被视为流周围的包装器?
你认为你是一个java向导吗?
您是否精通反射API的秘密?
public @interface @a {}
public @interface @b {}
@Mark public @interface @c {}
@Mark public @interface @d {}
public @interface @e {}
public Class C
{
@a @b @c @d @e public void x();
}
public class Solver
{
public Annotation[] solve(Method m, Class c);
}
Run Code Online (Sandbox Code Playgroud)
你必须编写方法求解,所以如果在方法Cx()和Mark.class上调用它,它将返回{c,d}.
(这不是家庭作业,是我正在尝试开发的框架元编程框架的真正编程任务)
我在我的系统上安装了gfortran,libgfortran.a可以找到该文件/usr/lib/gcc/x86_64-linux-gnu/4.6/.使用nm我确保函数_gfortran_compare_string在那里定义:
$ nm /usr/lib/gcc/x86_64-linux-gnu/4.6/libgfortran.a | grep _gfortran_compare_string
Run Code Online (Sandbox Code Playgroud)
返回
0000000000000000 T _gfortran_compare_string
0000000000000000 T _gfortran_compare_string_char4
Run Code Online (Sandbox Code Playgroud)
但是,我的CUDA-C程序的链接器会抛出错误:
/usr/local/cuda-6.0/bin/nvcc --cudart static -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/home/chung/lapack-3.5.0 -link -o "pQP" ./src/pQP.o -lgfortran -llapacke -llapack -lcublas -lblas -lcurand
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
/home/chung/lapack-3.5.0/liblapack.a(ilaenv.o): In function `ilaenv_':
ilaenv.f:(.text+0x81): undefined reference to `_gfortran_compare_string'
Run Code Online (Sandbox Code Playgroud)
以及另一个错误,再次与libgfortran有关:
/home/chung/lapack-3.5.0/liblapack.a(xerbla.o): In function `xerbla_':
xerbla.f:(.text+0x49): undefined reference to `_gfortran_st_write'
xerbla.f:(.text+0x54): undefined reference to `_gfortran_string_len_trim' …Run Code Online (Sandbox Code Playgroud) 我正在迈出具有Java背景的C++的第一步.我需要清除C++中++运算符的一些特性.考虑以下程序:
#include <iostream>
using namespace std;
void __print(int x, int *px) {
cout << "(x, *px) = (" << x << ", " << *px << ")" << endl;
}
int main() {
int x = 99;
int *px = &x;
__print(x, px);
x++; __print(x, px);
x = x + 1; __print(x, px);
*px = *px + 1; __print(x, px);
*px++; __print(x, px);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,该程序打印:
(x, *px) = (99, 99)
(x, *px) = (100, 100)
(x, *px) = …Run Code Online (Sandbox Code Playgroud) 我正在尝试对__device__变量应用内核函数,根据规范,它位于"全局内存"中
#include <stdio.h>
#include "sys_data.h"
#include "my_helper.cuh"
#include "helper_cuda.h"
#include <cuda_runtime.h>
double X[10] = {1,-2,3,-4,5,-6,7,-8,9,-10};
double Y[10] = {0};
__device__ double DEV_X[10];
int main(void) {
checkCudaErrors(cudaMemcpyToSymbol(DEV_X, X,10*sizeof(double)));
vector_projection<double><<<1,10>>>(DEV_X, 10);
getLastCudaError("oops");
checkCudaErrors(cudaMemcpyFromSymbol(Y, DEV_X, 10*sizeof(double)));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
内核函数vector_projection定义my_helper.cuh如下:
template<typename T> __global__ void vector_projection(T *dx, int n) {
int tid;
tid = threadIdx.x + blockIdx.x * blockDim.x;
if (tid < n) {
if (dx[tid] < 0)
dx[tid] = (T) 0;
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我用cudaMemcpyToSymbol和cudaMemcpyFromSymbol …
我试图通过引用将矩阵传递给函数.该函数将替换A[i][j]矩阵的每个元素-A[i][j].我首先创建矩阵:
float a[3][4] =
{
{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{1.0f, 1.0f, 0.0f, 0.0f},
};
Run Code Online (Sandbox Code Playgroud)
然后,我获得指向这个矩阵的指针:
float*** pa = &a;
Run Code Online (Sandbox Code Playgroud)
然后,我介绍以下功能:
void process(float ***matrix, int nRows, int nCols){
short i;
short j;
for (i=0 ; i<nRows; i++){
for (j=0 ; j<nCols ; j++){
(*matrix)[i][j] *= -1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我称之为:
process(pa,3,4);
Run Code Online (Sandbox Code Playgroud)
我的程序无法执行并返回:
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
答案摘要:基于此问题收到的问题的一些注释:
I.可以使用上述功能,只要a有点不同地初始化以便成为a float**.特别是:
int numberOfRows = 3;
int numberOfColumns = 4;
float **a …Run Code Online (Sandbox Code Playgroud) 我正在使用ipython笔记本执行我的第一步,并将其成功安装在我的远程服务器上(通过SSH),并使用以下命令启动它:
ipython notebook --ip='*' ---pylab=inline --port=7777
Run Code Online (Sandbox Code Playgroud)
然后我检查了http://myserver.sth:7777 /并且笔记本运行正常.然后我想关闭与服务器的SSH连接并让ipython在后台运行.当我这样做时,我无法连接到myserver.sth:7777.一旦我通过SSH再次连接到远程服务器,我就可以再次连接到笔记本电脑.然后我尝试使用screen启动ipython:我创建了一个新的屏幕screen -S ipy,我开始上面的ipython笔记本,我曾经Ctrl+A,D分离屏幕并退出到TTY.我仍然可以远程连接到笔记本电脑.然后我关闭了SSH连接,404 NOT FOUND当我尝试访问我之前存储的笔记本时遇到错误,我无法在http://myserver.sth:7777 /的笔记本列表中看到它.我试图创建一个新的笔记本,但我有一个500 Internal Server Error.
我也尝试过ipython notebook使用和不使用sudo.
有任何想法吗?