How many cogs are running?
DRMorrison
Posts: 81
I was wondering if there was some way to determine during run time how many, or which cogs were running/active.
I couldn't find anything in the book; the SPR looked promising, but not quite.
Daniel
I couldn't find anything in the book; the SPR looked promising, but not quite.
Daniel
Comments
Basically, you have a tiny pasm (or spin) program that just terminates. The you try and start that program in each cog. If success is returned then that cog is free.
So some sort of loop to cycle through the cogs and test them, if I understand correctly.
SOrry, but I could not find the file you were refering to. _Vers.spin
Daniel
It's in the OSxxx.zip file and is _VER.spin here http://forums.parallax.com/showthread.php/138251-A-Propeller-OS-that-can-run-on-multiple-hardware...?p=1204709&viewfull=1#post1204709
Here's an extract...
I think this is an insoluble problem in the general case.
But then it is good enough for most normal Spin applications.
In the "insoluble" general case you would need to maintain a table of cogs that are running, and use a lock to prevent other cogs from starting/stopping cogs and changing the table while you're checking it.
Yes, I think a common COG management system with locks would need to be in place to make this fool proof.
large and complex program, but might be okay for a small one that only uses a couple of cogs at most.
You could then check sogStatus to find out how many, and which cogs were running.
I'm not sure if this would work or not. Let me know.
{There seems to be a bug that prevents me from placing the percent sign and 00 in front of those CON values; it strips them off. It wouldn't even allow
them in this part of the text! I typed a percent 00 here, after the colon: , but it gets stripped.}
original text from text editor. Strange behavior.
Daniel
I think it's more for diagnostic purposes to determine if the cog count matches the expected number of active cogs.
yes there are problems with the forum software and percent signs.
your code would work (concept) but you would be better to define cog 0 = 00000001
try thiss...
cog0 = 1<<0
cog1 = 1<<1
etc
But I know that cog0 is always running, I was just trying to come up with a way to check and see if another cog was running, and if so, which one. Or, just check to see
if a particular cog was running. As I said, this would really only work if you started specific methods into specific cogs; basically assign cogs to methods and don't allow
the run time method to arbitrarily assign cogs.
A spin app that I'm working on has a set number of cog-run methods, and it would be easy to keep track of them by assigning them to specific cogs by number.
i.e. MethodA always runs in cog1, MethodB always runs in cog2 etc.
Daniel
You see propgcc can indeed use FCACHE in combination with OpenMP to start and stop COGs with out there being any explicit cogstart or whatever calls in your code:
The following will spread the body of the for loop over many COGs as and when required:
I played with that quite a lot a while back. But yes, it is a bit esoteric for most Propeller uses/users.
If it was easy, anybody could do it.
Sandy
Also, it is considered poor practice to specify which cogs load which objects. In my PropOS, I set flags up to indicate what cogs are doing what processes. Catalina does a similar thing. A few of us tried unsuccessfully to make a standard.