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

113 次查看(过去 30 天)
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.

采纳的回答

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