parfor loop & fprint not working
Afficher commentaires plus anciens
I have two nested loops
The top loop is a parfor loop the inner loop is a regular for
I am trying to write the results to a file using fprintf, comma seperated. If I eliminate the parfor and make the loop a for loop the file is written properly; however speed is dramatically reduced on my quad core computer. When I change to parfor, the output on some lines is perfect and others is messed up. Part of the line on one with some of another in the middle and the rest in the end. I think this is because the two processes are writing at the same time. Is there a way to resolve this. I tried opening the file with
fname = fopen('result.csv', 'a'); and fname = fopen('result.csv', 'w');
I tried putting the open and close outside of the loop, in the outer loop and in the inner loop but this didn't resolve
Réponse acceptée
Plus de réponses (1)
Titus Edelhofer
le 27 Août 2011
1 vote
Hi,
exactly: your code put's in arbitrary order at arbitrary times lines into the file (interupting each other). I would suggest to do the following: inside your parfor loop put the output instead of into a file in some cellarray and output the cellarray after the parfor loop into the file.
Titus
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!