Why did my mat file corrupt? How can I recover it?

조회 수: 113 (최근 30일)
Daigo
Daigo 2022년 1월 14일
댓글: DGM 2023년 10월 6일
I saved a matrix variable as a mat file on a GPU cluster (Linux, MATLAB R2019, GPU: Tesla V100) and tried to load it in my local PC (Windows10, MATLAB R2020a, CPU) but got the following error:
Error using load
Unable to read MAT-file C:\...\results\PSFs_seed0_v1_val5.mat. File might be corrupt.
I'm wondering what is causing this issue. My mat file can be downloaded from here. Below is the overview of my code to get this mat file:
clear all; close all;
seed = 0;
v = 1;
gpu_psf_save = zeros(N, N, num_samples, 'gpuArray');
for iter = 1:num_samples
gpu_psf_save(:,:,iter) = my_function(my_inputs);
end
% Retrieve from GPU to CPU
psf_save = gather(gpu_psf_save);
% Save as a mat file
name = sprintf('results/PSFs_seed%d_v%d_val5.mat', seed, v);
save(name, 'psf_save', '-v7.3');
I found some relevant posts but none of them solved my problem so far.
1. In this post: Unable to load, File may be corrupt, Jason mentioned that the use of cluster may be related to the problem:
"You mention that you are using a cluster. Is it possible that multiple processes are trying to write to the same file simultaneously? This will inevetabaly lead to corruption."
I'm using a cluster but I'm not using the save command simultaneously so this is probabliy not the reason for my corruption.
2. In this post: How do I recover data from a corrupt MAT-file?, the Mathworks support team provides the splitmat function to cope with this issue. I used this function and got the following:
splitmat PSFs_seed0_v1_val5
Found bad 0-byte size at variable #1.
ans =
0
Do you have any idea what caused the corruption? Not a few people have posted questions on this matter but has it been resolved? Note that I don't necessarily have to recover the mat file. Rather, I want to know how to avoid this problem.
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 1월 14일
The splitmat function is only for -v7 and lower files, and does not apply to -v7.3 files.

댓글을 달려면 로그인하십시오.

채택된 답변

Daigo
Daigo 2022년 1월 15일
I've found the cause. The problem was in the cluster side, not in the code side. My home directory on the GPU cluster was almost full and it didn't have enough space to save my output. As a result, the saving process was terminated in the middle, leading to the corruption of the mat file.
  댓글 수: 2
Krunal
Krunal 2023년 10월 6일
편집: Krunal 2023년 10월 6일
what you did find out this problem? I have same error, but I am unable to recover the file and not able to make my function so that this problem don't come again. Hope to get reply.
DGM
DGM 2023년 10월 6일
@Daigo already said what the problem was. It's right there.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by