- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 cuSOLVER 中使用 QR 线性系统求解器,这个
#include <cusparse_v2.h>
#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include "device_launch_parameters.h"
#include <iostream>
#include <cassert>
#include <cublas_v2.h>
#include <cusolverDn.h>
#include <cusolverSp.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
using namespace thrust;
#define CUSPARSE_CHECK(x) {cusparseStatus_t _c=x; if (_c != CUSPARSE_STATUS_SUCCESS) {printf("cusparse fail: %d, line: %d\n", (int)_c, __LINE__); exit(-1);}}
void init_handlers_and_matr_descriptor(cusolverSpHandle_t& cusolverH,cusparseHandle_t& cusparseH,cusparseMatDescr_t& descrA) {
assert(CUSOLVER_STATUS_SUCCESS == cusolverSpCreate(&cusolverH));
assert(CUSPARSE_STATUS_SUCCESS == cusparseCreate(&cusparseH));
assert(CUSPARSE_STATUS_SUCCESS == cusparseCreateMatDescr(&descrA)); //CUSPARSE_INDEX_ZERO,CUSPARSE_MATRIX_TYPE_GENERAL
assert(CUSPARSE_STATUS_SUCCESS == cusparseSetMatIndexBase(descrA,CUSPARSE_INDEX_BASE_ZERO));
assert(CUSPARSE_STATUS_SUCCESS == cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL));
}
int sparse_solver_test() {
//Init csr format A and b for solving Ax = b
/*
A =
[ 1.0 2.0 0.0 0.0 0.0 0.0 ]
[ 3.0 4.0 5.0 0.0 0.0 0.0 ]
[ 0.0 6.0 7.0 8.0 0.0 0.0 ]
[ 0.0 0.0 9.0 10.0 11.0 0.0 ]
[ 0.0 0.0 0.0 12.0 13.0 14.0 ]
[ 0.0 0.0 0.0 0.0 15.0 16.0 ]
b = [0.0,2.0,4.0,6.0,8.0,10.0]^T
*/
int nnz_A = 16, m = 6;
cusolverSpHandle_t cusolverH = NULL;
cusparseHandle_t cusparseH = NULL; //cuBLAS or cuSPARSE?
cusolverStatus_t cusolver_status = CUSOLVER_STATUS_SUCCESS;
cusparseMatDescr_t descrA;
cudaError_t cudaStat;
init_handlers_and_matr_descriptor(cusolverH, cusparseH, descrA);
host_vector<double> h_csrValA(nnz_A), h_dataB(m), h_dataX(m);
host_vector<int> h_csrRowPtrA(m + 1), h_csrColIndA(nnz_A);
device_vector<double> d_csrValA(nnz_A), d_dataB(m), d_dataX(m);
device_vector<int> d_csrRowPtrA(m + 1), d_csrColIndA(nnz_A);
//Init matrix
for (auto i = 0; i < nnz_A; ++i) h_csrValA[i] = static_cast<double>(i + 1);
h_csrRowPtrA[0] = 0;
h_csrRowPtrA[1] = 2;
for (auto i = 2; i < m; ++i) h_csrRowPtrA[i] = h_csrRowPtrA[i - 1] + 3;
h_csrRowPtrA[m] = nnz_A;
h_csrColIndA[0] = 0;
int v[] = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5 };
for (auto i = 0; i < nnz_A; ++i) h_csrColIndA[i] = v[i];
for (auto i = 0; i < m; ++i) h_dataB[i] = static_cast<double>(2 * i);
//device memory and descriptor A init
d_csrValA = h_csrValA;
d_csrRowPtrA = h_csrRowPtrA;
d_csrColIndA = h_csrColIndA;
d_dataB = h_dataB;
//step4, solve the linear system?
int singularity;
cusolver_status = cusolverSpDcsrlsvqr(
cusolverH, m, nnz_A, descrA,
d_csrValA.data().get(), d_csrRowPtrA.data().get(), d_csrColIndA.data().get(), d_dataB.data().get(),
0.0, 0, d_dataX.data().get(), &singularity);
std::cout << "singularity = " << singularity << std::endl;
assert(CUSOLVER_STATUS_SUCCESS == cusolver_status);
h_dataX = d_dataX;
std::cout << "x = (";
for (auto i = 0; i < m; ++i) {
std::cout << h_dataX[i];
if (i < m - 1) std::cout << ", ";
}
std::cout << std::endl;
if (cusparseH)
cusparseDestroy(cusparseH);
if (cusolverH)
cusolverSpDestroy(cusolverH);
if (descrA)
cusparseDestroyMatDescr(descrA);
cudaDeviceReset();
return 0;
}
int main(int argc, char** argv) {
sparse_solver_test();
return 0;
}
不确定我的功能设置是否有误,有人可以帮忙吗?
更新 我使用 thrust 库稍微简化了代码,但错误仍然相同,但至少我摆脱了所有 malloc 等...
更新 按照建议更正了 csrIndColA
(相应地更改了代码)数组。现在求解器工作了(即我不再得到我之前得到的错误),尽管我得到的结果是 0。
更新 在我完成所有更改后,我也忘记了初始化 h_dataB
,以及 csrIndColA
中解决问题的索引,完整的代码在上面以供将来引用。
最佳答案
示例中的 csrColIndA
数组太短,因此 cuSOLVER 会尝试读取它的末尾。
According to the cuSOLVER documentation和常见的约定,列索引数组与非零矩阵条目的数组具有相同的长度,并存储每个非零元素的列索引(而不是像您的示例中那样仅存储每列中的第一个非零元素,这将限制格式到所有非零元素垂直连续的稀疏模式)。
所以你的示例输出应该有
csrColIndA = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5}
关于c++ - cuSolver 不返回正确的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49409745/
我只是想知道要安装哪个版本的 Visual Studio 2010(专业版或高级版)提示升级项目.. 项目包括:asp.net mvc、数据库和silverlight。 最佳答案 通常,由不同版本的相
目录 前言 1、常见 key-value 2、时效性强 3、计数器相关 4、高实时性 5、排行榜系列 6、文章小结 前言 在笔者 3 年的
目录 前言 四、技术选型 五、后端接口设计 5.1业务系统接口 5.2App 端接口 六、关键逻辑实现 6.1Red
目录 前言 一、需求分析 1.1发送通知 1.2撤回通知 1.3通知消息数 1.4通知消息列表 二、数据模型设计
目录 前言 一、多租户的概念 二、隔离模式 2.1独立数据库模式 2.2共享数据库独立数据架构 2.3共享数据库共享数据架构
导读: 虽然锁在一定程度上能够解决并发问题,但稍有不慎,就可能造成死锁。本文介绍死锁的产生及处理。 死锁的产生和预防 发生死锁的必要条件有4个,分别为互斥条件、不可剥夺条件、请求与保持条件和循环等待条
在浏览网页后,我找不到任何功能来执行此操作,我有可行的个人解决方案。也许它对某人有用。 **使用 Moment 插件转换日期。***moment(currentPersianDate).clone()
是否有一种解决方案可以很好地处理数字(1-10)手写?我试过tesseract,但我得到的只是垃圾。 理想情况下是 OSS,但商业也可以。 最佳答案 OpenCV 现在带有手写数字识别 OCR 示例。
在服务器应用程序上,我们有以下内容:一个称为 JobManager 的单例类。另一个类,Scheduler,不断检查是否需要向 JobManager 添加任何类型的作业。 当需要这样做时,调度程序会执
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
当您尝试从 GitHub 存储库安装某些 R 包时 install_github('rWBclimate', 'ropensci') 如果您遇到以下错误: Installing github repo
问题在以下链接中进行了描述和演示: Paul Stovell WPF: Blurry Text Rendering www.gamedev.net forum Microsoft Connect: W
我正在寻找一种解决方案,使用标准格式 a × 10 b 在科学记数法下格式化 R 中的数字。一些同行评审的科学期刊都要求这样做,并且手动修改图表可能会变得乏味。 下面是 R 标准“E 表示法”的示例,
已编辑解决方案(如下...) 我有一个启动画面,它被打包到它自己的 jar 中。它有效。 我可以通过以下方式从另一个 java 应用程序内部调用 Splash.jar: Desktop.getDesk
什么是创建像 PageFlakes 或 iGoogle 这样的门户网站的好框架/包? ?我们希望创建一个为员工提供 HR 服务的员工/HR 门户,但我们也需要一种足够灵活的产品,以便我们可以使用它来为
我正在寻找一种解决方案,使用标准格式 a × 10 b 在科学记数法下格式化 R 中的数字。一些同行评审的科学期刊都要求这样做,并且手动修改图表可能会变得乏味。 下面是 R 标准“E 表示法”的示例,
如何将 solr 与 heritrix 集成? 我想使用 heritrix 归档一个站点,然后使用 solr 在本地索引和搜索该文件。 谢谢 最佳答案 使用 Solr 进行索引的问题在于它是一个纯文本
完整日历不包含工作时间功能选项(在任何一天的议程 View 中选择第一行和最后一行 - 例如公司不工作)。我做到了类似的事情: viewDisplay: function(view){
我正在使用 bootstrap 作为我的下拉菜单。但有一个问题, 如果我的下拉菜单有多级子菜单,那么它会显示在屏幕上,并出现底部滚动条。 如何将子菜单保留在屏幕内,我需要一个 jQuery 解决方案。
我有一个要转换为 C# 的 Excel 宏。目前我手动转到一个已经打开的 IE 窗口,从中复制所有内容(html 表)并粘贴到 excel 工作表中。然后我正在处理数据。这非常有效,因为将 html
我是一名优秀的程序员,十分优秀!