Question regarding calling the destructor of a broadcast variable in parfor.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
When I run PARfor script, with parfor having final loop index a number higher or equal than six times (nEnemies>=6), the destructor of Mage is called exactly 6 times while parfor executes. I do not understand why the destructor is even called, and much less why exactly 6 times.
If the parfor has the final loop index less or equal than six times (nEnemies<=6), the number of calls to Mage's destructor is equal to the value of the final loop index. I do not understand why the destructor is called.
As a side note, I know that doDamage method of Mage is not robust and can led to bugs related to Enemy's health, but it is not the point of this question.
0 Commenti
Risposta accettata
Matt J
il 13 Ott 2024
Modificato: Matt J
il 13 Ott 2024
It is because you have 6 workers in your parpool. Therefore, a copy of Mage is sent to each worker, for a total of 6, during parfor, and those 6 are destroyed when parfor terminates.
When your loop has fewer N<6 iterations, only N of the workers have any work to do, and so only N object copies are broadcasted.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!