当前位置: 首页 > news >正文

sgetrf M N is 103040 时报错,这是个bug么 lapack and Openblas the same,修复备忘

号外:

$ clang-format   -style="{BasedOnStyle: llvm, IndentWidth: 4}"   -i  hello.cpp

$ clang-format   -style="{BasedOnStyle: llvm, IndentWidth: 4}"   -i  hello.cpp

IndentWidth:4不错,默认2太下了

1,现象

M=N=103040时,调用 sgetrf_ 时,无论是 LAPACK 还是 OpenBLAS,都出错:

openblas:

lapack:

2, 复现代码

出现问题的应该是由于M和N相对数字太大,乘积超出32bit整数的表达范围,而接收此参数的类型其实为 unsigned long int,导致误传非常大的值后造成越界。

如下是已经修复的代码,可以正常运行了:

extern "C" void sgetrf_(int* M, int* N, float* A, int *lda, int* piv, int* info);#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <iostream>#define ORDER (10304)
//#define ORDER (51520)void print_matrix(int M, int N, float* A, int lda)
{for(unsigned long int i=0; i<M; i++){for(unsigned long int j=0; j<N; j++){printf(" %7.4f", A[i + j*lda]);}printf("\n");}
}void init_matrix(int M, int N, float* A, unsigned long int lda, int seed)
{srand(seed);for(unsigned long int i=0; i<M; i++){for(unsigned long int j=0; j<N; j++){A[i + j*lda] =((float) rand())/RAND_MAX;}}
}int main()
{float* A = NULL;int M = ORDER;int N = M;int lda = M;unsigned long int MM = M;unsigned long int NN = N;unsigned long int ldaa = lda;unsigned long int min_MN = std::min(M, N);int *piv = NULL;int *info = NULL;printf("lda * N * sizeof(float) bytes = %ld\n", (ldaa * NN * sizeof(float)));printf("lda * N * sizeof(float) bytes = %f GB\n", (ldaa * NN * sizeof(float))/1024.0/1024.0/1024.0);A = (float*)malloc(ldaa * NN * sizeof(float));if(A==NULL){printf("failed malloc()\n");}piv = (int*)malloc(min_MN*sizeof(int));info = (int*)malloc(1*sizeof(int));init_matrix(M, N, A, lda, 2024);//printf("A =\n");	print_matrix(7, 7, A, lda);printf("A[%ld] = %7.3f\n", MM -1 + (NN-1)*ldaa, A[MM -1 + (NN-1)*ldaa]);sgetrf_(&M, &N, A, &lda, piv, info);  printf("LU=\n");	print_matrix(7, 7, A, lda);free(A);free(piv);free(info);return 0;
}

3,结论

遇到非负整数,比如阶数、数组下标等,尽量用 signed long int 类型,代替使用 int 类型,现在的数据量太大了,下标/ 数据量 动辄超过 512M/ 2GB 等;

openblas中的 lapack_int 数据类型:

                             #define lapack_int        int64_t

                                                                       ^

                             typedef __int64_t         int64_t;

                                                 ^

typedef signed long int    __int64_t;

详情如下:

 third-party/openblas/local/include/lapack.h


#ifndef lapack_int
#if defined(LAPACK_ILP64)
#define lapack_int        int64_t
#else
#define lapack_int        int32_t
#endif
#endif

third-party/openblas/OpenBLAS-0.3.27/Makefile.system
LAPACK_CFLAGS +=  -DLAPACK_ILP64

# 1 "/usr/include/x86_64-linux-gnu/bits/stdint-intn.h" 1 3 4
# 24 "/usr/include/x86_64-linux-gnu/bits/stdint-intn.h" 3 4
typedef __int8_t int8_t;
typedef __int16_t int16_t;
typedef __int32_t int32_t;
typedef __int64_t int64_t;

typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;

http://www.lryc.cn/news/423703.html

相关文章:

  • [后端代码审计] PHP 数组知识汇总
  • 单点Redis中面临哪些问题
  • 数学建模--蒙特卡洛算法之电子管更换刀片寿命问题
  • 如何解码Linux下事件响应工具evtest的时间戳
  • 基于STM32开发的智能门禁系统
  • EasyExcel-高性能的 Java Excel 处理库
  • 精益生产培训秘籍:六步策略,助力企业降本增效——张驰咨询
  • 【第19章】Spring Cloud之Gateway自定义Logback配置
  • Java流式编程
  • 高可用集群keepalived从部署到实战一篇解决
  • 22222222222
  • springboot宠物相亲平台-计算机毕业设计源码16285
  • 警惕:手机被监听时会出现这些情况
  • Windows 系统下 MongoDB和PostgreSQL数据库数据的备份和恢复
  • 必应Bing国内搜索广告开户收费标准公示
  • 大模型汇总:文心一言大模型、腾讯混元大模型、通义千问大模型、字节豆包大模型、智普清言大模型、KIMI 大模型、紫东太初大模型、讯飞星火大模型
  • C语言——结构体、共用体、枚举、位运算
  • [LitCTF 2024]exx
  • kafka运维常用命令
  • 笔记:在WPF中OverridesDefaultStyle属性如何使用
  • MATLAB/Simulink 与Gazebo联合仿真
  • 并查集-应用方向以及衍生汇总+代码实现(c++)-学习一个数据结构就会做三类大题!
  • 设计模式六大原则-开放封闭原则(二)
  • C# 截取两个点之间的线段,等距分割线
  • 打造聊天流式回复效果:Spring Boot+WebSocket + JS实战
  • 202年版最新Python下载安装+PyCharm下载安装激活和使用教程!(附安装包+激活码)
  • 【面试宝典】spring常见面试题总结[上]
  • NC单链表的排序
  • 阿里云部署open-webui实现openai代理服务(持续更新)
  • Vue3简介和快速体验