fopen and fprintf do not work within parfor or smpd running on grid

8 visualizaciones (últimos 30 días)
Hello everyone,
I met a problem to use fopen and fprintf within parfor or smpd when I run my codes on grid. Here are my codes:
spmd
fid = fopen(sprintf( 'worker_%d.csv', labindex ),'w');
fprintf(fid,'%s\r\n',vector1);
fclose(fid);
...
end
OR
parfor i=1:100
t = getCurrentTask();
fid = fopen(sprintf( 'worker_%d.csv', t.ID ),'w');
fprintf(fid,'%s\r\n',vector1);
fclose(fid);
...
end
Neither one would work, and both of them will generated the similar error messages:
spmd:
??? Error using ==> spmd_feval at 8
Error detected on lab(s) 2 15 16
Error in ==> BruteForce2>(spmd) at 103
spmd
Error in ==> BruteForce2 at 103
spmd
Caused by:
Invalid file identifier. Use fopen to generate a valid file identifier.
Error stack:
BruteForce2>(spmd body) at 105
Invalid file identifier. Use fopen to generate a valid file identifier.
Error stack:
BruteForce2>(spmd body) at 105
Invalid file identifier. Use fopen to generate a valid file identifier.
Error stack:
BruteForce2>(spmd body) at 105
PARFOR:
??? Error using ==> parallel_function at 598
Error in ==> BruteForce2>(parfor body) at 146
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> BruteForce2 at 105
parfor i = 1:g
The problem is my fopen, fid returns -1. The codes are running ok with local workers. So would it be some writing permission issues? I would like to know what the problem is, and where our admin should change on his side. Could anyone give me any suggestion? Thanks a lot!
Rui

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Mayo de 2013
fname = sprintf( 'worker_%d.csv', t.ID );
[fid, message] = fopen(fname, 'w');
if fid < 0;
fprintf(2, 'failed to open "%s" because "%s"\n', fname, message);
%and here, get out gracefully
end
  9 comentarios
Walter Roberson
Walter Roberson el 6 de Mayo de 2013
Are all the fopen() failing, or only some of them? Try something like,
fname = sprintf( 'worker_%d.csv', t.ID );
fprintf(2, 'About to open "%s"\n', fname);
[fid, message] = fopen(fname, 'w');
if fid < 0;
fprintf(2, 'failed to open "%s" because "%s"\n', fname, message);
%and here, get out gracefully
else
fprintf(2, 'Success opening "%s"\n', fname);
fprintf(fid,'%s\r\n',vector1);
fclose(fid);
fprintf(2,, 'Closed file "%s"\n', fname);
end
Rui
Rui el 6 de Mayo de 2013
Walter, Just some of them. I have 16 workers. With help of our local unix expert, we find that if I login into Permission-denied machine manually using ssh, then I do not have this problem anymore. So it looks like a configuration problem on server side. We have sent them emails. Thanks a lot for your help!
Lab 1 to 12:
About to open "worker_6.csv"
Success opening "worker_6.csv"
Closed file "worker_6.csv"
Lab 13:
About to open "worker_13.csv"
failed to open "worker_13.csv" because "Permission denied"

Iniciar sesión para comentar.

Más respuestas (2)

Jason Ross
Jason Ross el 6 de Mayo de 2013
It's possible that the workers are running under a different user name than yours. You haven't provided the specifics of the operating systems and what schedulers you are using, but you can get this information using
spmd
system('whoami')
end
And then make sure that username also has access to the directories where you want to open the files.
  1 comentario
Rui
Rui el 6 de Mayo de 2013
Jason, thanks for help! username is all right, we just figure out that this is possibly due to a configuration issue on server. Manually logging into machines using ssh could solve my problem. There may be something wrong with the interface between matlab and grid machines.

Iniciar sesión para comentar.


Jan
Jan el 4 de Mayo de 2013
  • Do you have write permissions to the current directory?
  • Is the file open already from a former crashing call? See fopen all.
  • Is the file opened from another application?
Using absolute filenames is an important strategy especially for parallel processing and multi-threading. Checking the success of FOPEN is a good programming practize also.
  2 comentarios
Rui
Rui el 4 de Mayo de 2013
Editada: Rui el 4 de Mayo de 2013
Hi Jan,
thanks for the help! Yes, I do have write permission to the directory, I can manually create folders under that directory. Matlab can create files there, too, if not using workers from grid. I closed matlab, then opened it again. It should release the all files, right? But the problem was still there. I do not think any other application will need it on server.
I could do a double check on everything on Monday. It seems to me that I have enough permission to do anything, and also matlab local workers, but not matlab grid workers... however, if I try spmd which... end or spmd type... end, they both work with no error report.
is it ever possible? what may lead to that?
Rui
Rui
Rui el 6 de Mayo de 2013
Jan,
Just checked everything again. fopen all shows that nothing is open. I do have the permission, but not the grid workers.

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by