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:
spmdfid = fopen(sprintf( 'worker_%d.csv', labindex ),'w');fprintf(fid,'%s\r\n',vector1);fclose(fid);...end
OR
parfor i=1:100t = 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 8Error detected on lab(s) 2 15 16Error in ==> BruteForce2>(spmd) at 103spmdError in ==> BruteForce2 at 103spmdCaused 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 598Error in ==> BruteForce2>(parfor body) at 146Invalid file identifier. Use fopen to generate a valid file identifier.Error in ==> BruteForce2 at 105parfor 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
Best Answer