Again on prime numbers: program slower without semaphores?
samuell
Posts: 554
Hello all!
I've decided to take away all the semaphores from the prime calculation program I've posted here a way back. This was only because of curiosity, because I was obvioulsy doing something wrong and I wanted to see if the program produced bad results. Well, seemingly it didn't produced bad results, but it was a lot more slower. I was not expecting that, and it seems to go against logic.
Why the program still works correctly while having multiple cogs accessing the same values? And why is it a lot more slower without semaphores than with them?
It defies logic, IMHO. I've posted the source code of both the original and the version without semaphores, for SimpleIDE.
Kind regards, Samuel Lourenço
I've decided to take away all the semaphores from the prime calculation program I've posted here a way back. This was only because of curiosity, because I was obvioulsy doing something wrong and I wanted to see if the program produced bad results. Well, seemingly it didn't produced bad results, but it was a lot more slower. I was not expecting that, and it seems to go against logic.
Why the program still works correctly while having multiple cogs accessing the same values? And why is it a lot more slower without semaphores than with them?
It defies logic, IMHO. I've posted the source code of both the original and the version without semaphores, for SimpleIDE.
Kind regards, Samuel Lourenço
Comments
Kind regards, Samuel Lourenço
But if you could analyse, I would appreciate. Thanks in advance!
Actually looking at the program I don't really see that the lock is necessary -- it looks like each cog has its own queue, so they won't interfere with each other, and only cog 0 puts data into the queues.
Mind that the worker cogs are only blocked when reading or writing from the queue, but not during the calculation. But I think it would be a good idea to use multiple locks, one for each worker cog. Perhaps the efficiency will improve a bit.
Just to add, all cogs read and write from the common variables. I wonder if that is the issue.