Unable to load, File may be corrupt

94 views (last 30 days)
lina
lina on 27 Feb 2013
Commented: Walter Roberson on 4 Apr 2022
Hi
I have met with this(Unable to load, File may be corrupt) problem for several times lately. I also found a seems possible solution, which is at
However this solution does not always work, this time when I run splitmat, I got the message : 'Found bad 0-byte size at variable #1'. I don't understand this, and I really want to know a better solution to this, the reason for problem, or any suggestion of easy and more trustworthy way of saving data in matlab instead of .mat?
Thanks very much. Lina
  3 Comments
lina
lina on 28 Feb 2013
Thanks for your reply, I'm using matlab R2011b (7.13.0.564) on a 64 bit linux cluster. In terms of the mat file version, since I did not specify when I saved it, so I think it should be version 7, by creating, I just use save(filename, variablename). I have been able to successfully load it several days ago, but since yesterday, it was told to be corrupted.
What could be the potential reasons for mat file to be corrupted?
Thanks
gire
gire on 13 Jun 2013
Hi, I am having exactly the same issue, only difference is I am using Windows server 2008 (no cluster).
There is no obvious reason for the mat files to be corrupted (no concurrent writing, no HD failure).

Sign in to comment.

Answers (1)

Jason Ross
Jason Ross on 28 Feb 2013
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.
An example situation would be if you are saving a file to a shared location with the same filename, so N MATLAB processes are trying to save (for example) /home/lina/myoutputs.mat .
  3 Comments
Jordan Tackett
Jordan Tackett on 4 Apr 2022
Hi, How can we write multiple thinks to the same file then?
Walter Roberson
Walter Roberson on 4 Apr 2022
If you have multiple processes on the same host, often the easiest approach is to call a system file lock function and when you are told that the lock is granted, make the file changes and release the lock. If you are using a network file system then it depends on the network file system as to whether you can use the same technique.
If you cannot use system locks, then take advantage of the fact that renaming a file is an "atomic" operation
  • before you start any of this computation going on any host, make sure that the file exists. Do not do this per-worker, this is something outside of all of the workers
  • Per worker, create a global unique file name. tempname() can help with that
  • per worker, start a loop.
  • test whether the mat file exists.
  • if not, pause a random amount of time and then go back to the beginning of the loop
  • having determined that the mat file exists, ask to movefile (rename file) to the unique name
  • check to see if the rename was successful. If not then someone beat you to the race, pause a random time and go back to the beginning of the loop
  • if the rename was successful, then you won control. Go ahead and add or modify the mat file using the unique name. When done, rename it back to the original name, and exit the loop
  • provided that you have the permission to rename the file and the file existed before all this started, and the process doing the writing succeeds in renaming it back, statistically you will eventually win the race and get to write the file.

Sign in to comment.

Categories

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

Community Treasure Hunt

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

Start Hunting!