我正在尝试使用 assign 方法分配给向量,但是相同的代码在我的笔记本电脑上出现段错误,但在我们的计算集群上有效。段错误源于对分配的调用,
double* val = mat.address_data();
int* rp = mat.address_major();
int* cp = mat.address_minor();
// assign to the reserved location
row_pointer_data.assign( rp,
rp+(m+1) );
col_index_data.assign( cp,
cp+nz );
value_data.assign( val,
val+nz );
其中 mat 是一个 MTL4 矩阵,通过指向 int 和 double 的指针指向其内部数据。这些指针分别指向 nz 双精度块、m+1 个整数和 nz 个整数块。我在两个环境中都使用英特尔 c++ 编译器,所有代码都是相同的,对于两个 shell,即 bash shell,堆栈大小是无限的。
但是, col_index_data.assign() 调用在我的笔记本电脑和集群上出现分段错误,它运行良好。
使用 gdb 或 valgrind 指向与相关的同一行,我猜是在调用分配方法中使用的汇编命令 _memmove_sse3(),即,
> #0 __memmove_ssse3 () at ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:2928
> #1 0x000000000042df49 in VibroSys::read_triplet_data (mat=Traceback (most recent call last): File
> "/home/utab/external_libraries/gdb_printers/python/mtl/printers.py",
> line 124, in to_string
> A= empty_matrix(nr, nc) File "/home/utab/external_libraries/gdb_printers/python/mtl/printers.py",
> line 38, in empty_matrix
> return [copy.deepcopy(nr * ['0']) for c in range(nc)] MemoryError
>
> , row_pointer_data=std::vector of length 19173284840251003, capacity
> 429530399489 = {...}, row_index_data=<error reading variable: Cannot
> access memory at address 0xa3bf88>,
> col_index_data=<error reading variable: Cannot access memory at address 0x100008>, value_data=std::vector of length 0, capacity
> 4764228, col_indices_on_row=Traceback (most recent call last): File
> "/home/utab/external_libraries/stl_printers/python/libstdcxx/v6/printers.py",
> line 427, in children
> rep_type = find_type(self.val.type, '_Rep_type') File "/home/utab/external_libraries/stl_printers/python/libstdcxx/v6/printers.py",
> line 43, in find_type
> field = typ.fields()[0] IndexError: list index out of range
>
> std::map with 25701680 elements, is_symmetric=false) at
> /home/utab/vibroSys/src/boost_matrix_utilities.cc:354
> #2 0x000000000042e172 in VibroSys::extract_sub_matrix (input_matrix=Traceback (most recent call last): File
> "/home/utab/external_libraries/gdb_printers/python/mtl/printers.py",
> line 124, in to_string
> A= empty_matrix(nr, nc) File "/home/utab/external_libraries/gdb_printers/python/mtl/printers.py",
> line 38, in empty_matrix
> return [copy.deepcopy(nr * ['0']) for c in range(nc)] MemoryError
>
> , sub_index1=std::vector of length 19173284840251003, capacity
> 429530399489 = {...}, sub_index2=<error reading variable: Cannot
> access memory at address 0xa3bf88>, sub_matrix=
> <error reading variable: Cannot access memory at address 0x100000>) at /home/utab/vibroSys/src/boost_matrix_utilities.cc:995
> #3 0x000000000040f93a in main (argc=36433120, argv=0xa3c000) at timing_test.cc:145
相同代码在两个不同环境中出现这两种不同行为的原因可能是什么?