- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to transpose a sparse matrix. I used the mkl_sparse_convert_csr function as
mkl_sparse_convert_csr(csrA,SPARSE_OPERATION_TRANSPOSE,&csrB);
(1) Immediately after this step, I would like to destroy csrA. I assumed csrB will have its own memory space. However, my program will crash if I access csrB. It seems csrB share the memory with csrA. It works fine if I destroy csrA after all steps. Can someone confirm this?
(2) I'm also wondering if this is the best way to transpose a sparse matrix. The mkl_?csrcsc is depreciated.
Thanks
Jiaen
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi John,
Which compiler (Intel, gcc...) and version di you use?
Also, can you provide me with the sample with minimal workload so that I can reproduce the issue?
Please include instruction on how to compile and link the sample.
Thanks,
Khang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jiaen,
As for your questions:
1) Your program shouldn't crash when you tried to access csrB. That is why we asked for the sample to reproduce the error.
2) There is no direct function to do that; you will need to call mkl_sparse_convert_csr with operation for transpose, then call mkl_sparse_export_csr, then call mkl_sparse_?_create_csc (since CSC representation of a matrix mathematically is the same as transposed CSR).
Khang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Khang
Thanks for your response. The problem can be repeated if the following order is carried out and the sparse matrix is large enough (e.g., non zero elements more than 104). Now I'm quite sure about how to avoid the problem.I feel it's easier to describe it than changing my code to be general enough.
mkl_sparse_convert_csr(csrA,SPARSE_OPERATION_TRANSPOSE,&csrB);
mkl_sparse_destroy(csrA);
mkl_sparse_export_csr(csrB,&indexing,
&mjunk,&njunk,
&rows_start,&rows_end,&col_indx,&value);
memcpy(col_indx_output,col_indx,sizeof(MKL_INT)*nnz); // col_indx_output is the pointer to the allocated output memory.
mkl_sparse_destroy(csrB);
The program will crash if mkl_sparse_destroy(csrA) is before memcpy. I closely monitored the memory use. mkl_sparse_destroy(csrB) actually doesn't reduce memory use significantly. This suggests the memory allocated for the transposed matrix B is stored in csrA rather than csrB.
Jiaen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jiaen,
I am no sure what happens in your code still. I'd appreciate if you provide an example (at least the data and the exact code snippet, where you create csrA and convert to csrB). On which line does the code crash? csrB after calling the converter should have all the memory for the transposed data which contradicts what you suggested.
Please, provide us the code so that we can investigate.
Best,
Kirill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jiaen,
Thank you for providing more information about this issue.
However, I still think it would be best if you can provide us with a code sample to reproduce the issue. This way we can be sure that we are looking at the exact issue.
Best regards,
Khang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure. I attached the code here. This is Matlab mexfunction. The compile and link options are in the file. Currently, I have mkl_sparse_destroy(csrA) and mkl_sparse_destroy(csrB) near the end. But if mkl_sparse_destroy(csrA) is before the memcpy functions, it will crash when the nnz is large.
To call this from matlab. Run [vt,ct,rt]=mkl_sp_transpose_double(v,c,r,int64(m),int64(n)) in matlab. Here, v is the data vector, c is the column index and r the row pointer, m number of rows and n number of columns. Make sure v is a double here.
If will be great if this can be improved because people can release csrA earlier to reduce the peak memory use.
Thanks
John
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page