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

120 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 14 Jan 2022
The splitmat function is only for -v7 and lower files, and does not apply to -v7.3 files.

Sign in to comment.

Accepted Answer

Daigo
Daigo on 15 Jan 2022
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 Comments
Krunal
Krunal on 6 Oct 2023
Edited: Krunal on 6 Oct 2023
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 on 6 Oct 2023
@Daigo already said what the problem was. It's right there.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!