Test::Test() { QUrl con(QString("amqp://*****:*****@localhost:5672/")); client_ = new QAMQP::Client(this); client_->open(con); exchange_ = client_->createExchange("test.test2"); exchange_->declare("fanout"); queue_ = client_->createQueue("test.my_queue", exchange_->channelNumber()); queue_->declare(); queue2_ = client_->createQueue("test.my_queue2"); queue2_->declare(); exchange_->bind(queue_); exchange_->bind(queue2_); connect(queue2_, SIGNAL(declared()), this, SLOT(declared())); connect(queue_, SIGNAL(messageRecieved()), this, SLOT(newMessage())); connect(queue2_, SIGNAL(messageRecieved()), this, SLOT(newMessage())); }
void SXFunctionInternal::generateBody(CodeGenerator& g) const { // Which variables have been declared vector<bool> declared(sz_w(), false); // Run the algorithm for (vector<AlgEl>::const_iterator it = algorithm_.begin(); it!=algorithm_.end(); ++it) { // Indent g.body << " "; if (it->op==OP_OUTPUT) { g.body << "if (res[" << it->i0 << "]!=0) " << "res["<< it->i0 << "][" << it->i2 << "]=" << "a" << it->i1; } else { // Declare result if not already declared if (!declared[it->i0]) { g.body << "real_t "; declared[it->i0]=true; } // Where to store the result g.body << "a" << it->i0 << "="; // What to store if (it->op==OP_CONST) { g.body << g.constant(it->d); } else if (it->op==OP_INPUT) { g.body << "arg[" << it->i1 << "] ? arg[" << it->i1 << "][" << it->i2 << "] : 0"; } else { int ndep = casadi_math<double>::ndeps(it->op); casadi_math<double>::printPre(it->op, g.body); for (int c=0; c<ndep; ++c) { if (c==0) { g.body << "a" << it->i1; } else { casadi_math<double>::printSep(it->op, g.body); g.body << "a" << it->i2; } } casadi_math<double>::printPost(it->op, g.body); } } g.body << ";" << endl; } }
void SXFunctionInternal::spAllocOpenCL() { // OpenCL return flag cl_int ret; // Generate the kernel source code stringstream ss; const char* fcn_name[2] = {"sp_evaluate_fwd", "sp_evaluate_adj"}; for (int kernel=0; kernel<2; ++kernel) { bool use_fwd = kernel==0; ss << "__kernel void " << fcn_name[kernel] << "("; bool first=true; for (int i=0; i<nIn(); ++i) { if (first) first=false; else ss << ", "; ss << "__global unsigned long *x" << i; } for (int i=0; i<nOut(); ++i) { if (first) first=false; else ss << ", "; ss << "__global unsigned long *r" << i; } ss << ") { " << endl; if (use_fwd) { // Which variables have been declared vector<bool> declared(n_w_, false); // Propagate sparsity forward for (vector<AlgEl>::iterator it=algorithm_.begin(); it!=algorithm_.end(); ++it) { if (it->op==OP_OUTPUT) { ss << "if (r" << it->i0 << "!=0) r" << it->i0 << "[" << it->i2 << "]=" << "a" << it->i1; } else { // Declare result if not already declared if (!declared[it->i0]) { ss << "ulong "; declared[it->i0]=true; } // Where to store the result ss << "a" << it->i0 << "="; // What to store if (it->op==OP_CONST || it->op==OP_PARAMETER) { ss << "0"; } else if (it->op==OP_INPUT) { ss << "x" << it->i1 << "[" << it->i2 << "]"; } else { int ndep = casadi_math<double>::ndeps(it->op); for (int c=0; c<ndep; ++c) { if (c==0) { ss << "a" << it->i1; } else { ss << "|"; ss << "a" << it->i2; } } } } ss << ";" << endl; } } else { // Backward propagation // Temporary variable ss << "ulong t;" << endl; // Declare and initialize work vector for (int i=0; i<n_w_; ++i) { ss << "ulong a" << i << "=0;"<< endl; } // Propagate sparsity backward for (vector<AlgEl>::reverse_iterator it=algorithm_.rbegin(); it!=algorithm_.rend(); ++it) { if (it->op==OP_OUTPUT) { ss << "if (r" << it->i0 << "!=0) a" << it->i1 << "|=r" << it->i0 << "[" << it->i2 << "];" << endl; } else { if (it->op==OP_INPUT) { ss << "x" << it->i1 << "[" << it->i2 << "]=a" << it->i0 << "; "; ss << "a" << it->i0 << "=0;" << endl; } else if (it->op==OP_CONST || it->op==OP_PARAMETER) { ss << "a" << it->i0 << "=0;" << endl; } else { int ndep = casadi_math<double>::ndeps(it->op); ss << "t=a" << it->i0 << "; "; ss << "a" << it->i0 << "=0; "; ss << "a" << it->i1 << "|=" << "t" << "; "; if (ndep>1) { ss << "a" << it->i2 << "|=" << "t" << "; "; } ss << endl; } } } } ss << "}" << endl << endl; } // Form c-string std::string s = ss.str(); if (verbose()) { userOut() << "Kernel source code for sparsity propagation:" << endl; userOut() << " ***** " << endl; userOut() << s; userOut() << " ***** " << endl; } const char* cstr = s.c_str(); // Parse kernel source code sp_program_ = clCreateProgramWithSource(sparsity_propagation_kernel_.context, 1, static_cast<const char **>(&cstr), 0, &ret); casadi_assert(ret == CL_SUCCESS); casadi_assert(sp_program_ != 0); // Build Kernel Program compileProgram(sp_program_); // Create OpenCL kernel for forward propatation sp_fwd_kernel_ = clCreateKernel(sp_program_, fcn_name[0], &ret); casadi_assert(ret == CL_SUCCESS); // Create OpenCL kernel for backward propatation sp_adj_kernel_ = clCreateKernel(sp_program_, fcn_name[1], &ret); casadi_assert(ret == CL_SUCCESS); // Memory buffer for each of the input arrays sp_input_memobj_.resize(nIn(), static_cast<cl_mem>(0)); for (int i=0; i<sp_input_memobj_.size(); ++i) { sp_input_memobj_[i] = clCreateBuffer(sparsity_propagation_kernel_.context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, inputNoCheck(i).size() * sizeof(cl_ulong), reinterpret_cast<void*>(inputNoCheck(i).ptr()), &ret); casadi_assert(ret == CL_SUCCESS); } // Memory buffer for each of the output arrays sp_output_memobj_.resize(nOut(), static_cast<cl_mem>(0)); for (int i=0; i<sp_output_memobj_.size(); ++i) { sp_output_memobj_[i] = clCreateBuffer(sparsity_propagation_kernel_.context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, outputNoCheck(i).size() * sizeof(cl_ulong), reinterpret_cast<void*>(outputNoCheck(i).ptr()), &ret); casadi_assert(ret == CL_SUCCESS); } }