factoring commands in M2 Parallel programming

hwholmes

Member
I have lost track of the thread where (i.e. IF) command factoring was described for (18)M2 parallell processing. Search doesn't like 2 letter words (IF) and I haven't come up with a combination ofother words that has located the thread from several months back

Is there a doc/writeup about this topic available?

Bert Holmes
 

hwholmes

Member
Thanks for the reply Hippy

I seem to recall seeing a thread shortly after the 18M2 was released describing a way to express IF conditionals and/or possibly other commands in multi program use of the M2 family.
My recall is fuzzy but I think that was needed because of timing??
Possibly there were some commands that should not be used with conditionals in the multi program environment but could be functionally duplicated with a series of more primitive commands. Sorry for being so vague but "I don't know what it is I don't know."

I was just trying to investigate using a count command under start1 and the base program which had been working prior to introducing the 2nd program miss-functioned.

I don't know which code is faulty but I am trying to locate the information I thought I remembered before bothering anyone with my code specifics.
 

westaust55

Moderator
I suggest that you post your entire code comprising all parallel sections with a clear explanation of what is not performing as you desire.
Then folks here can help you investigate and rectify the problem
 

hippy

Ex-Staff (retired)
I also think it would be best to post your code and explain in what way the code doesn't do as expected.

If I'm right, I think the issue discussed was in interaction between two tasks, similar to this ...

Start0:
Do
Count C.0, 10, w0
Loop

Start1:
Do
If w0 > 1000 Then : SerTxd( "Count=", #w0, CR, LF ) : End If
Loop

Because task 0 getting the count is interleaved between task 1 commands, it's possible that a count of 2000 is read and the IF test passes, then task 0 runs again and perhaps gets a count of 15 before the SERTXD runs, so the output displayed is "Count=15" which would not be expected.

The problem is that 'w0' can change at any time between commands and the solution is to only grab 'w0' at a specific time and move it to a different variable which retains its value until explicitly overwritten ...

Start1:
Do
w1 = w0
If w1 > 1000 Then : SerTxd( "Count=", #w1, CR, LF ) : End If
Loop
 

hwholmes

Member
Hippy - I finally found the thread I was looking for.

On 28-08-2010 14:58 in Thread titled "18M2 Multitasking" Post #35



You said:
hippy
For IF the switch to another task occurs before the THEN. You have to break the high-level block command down into the lowest level commands as the PICAXE implements them ...

If b0 = b1 Then
b2 = 1
Else
b2 = 2
End If

becomes ...

If b0 <> b1 THEN Label1
b2 = 1
Goto Label2
Label1:
b2 = 2
Label2:

the whole of that IF-THEN-Label command is executed and execution will have passed to the next command ( ignoring labels ) so the PICAXE is poised to execute "b2=1" or "b2=2" but will switch to another task if there is another.

Similar things happen within CASE and in BINTOASCII etc but most times it's not something that has to be worried about.
I would appreciate a clear explaination of how much of an IF command is executed in a single pass through a task comparing the examples above with the form where the whole IF conditional is on a single line.

By the way: there were a number of other useful items discussed in that thread which might be helpful to novice multitaskers.
I would be interested in seeing a summary of do's and don'ts for multitasking.​
 
Last edited:

westaust55

Moderator
To give some further guidance on easy ways to put text in quote or code tags.

1. Quotes - If not using Reply with Quote.
1.1 Paste the text into post window
1.2 Select the entire text
1.3 click on the quote icon (looks like a speech bubble towards the right hand end of the formatting toolbar(s) at the top of your post/edit window

2. Adding [code] and [/code] tags around progam listings:
2.1 Paste the code listing text into post window
2.2 Click on the Go Advanced button at the bottom right of the post/edit screen
2.3 Select the code text in your post
2.4 Click on the hash symbol (#) at the right hand end of the middle row of formatting icons at the top of the post/edit window
which wraps your code in the relevant [code] and [/code] markers.
 

hippy

Ex-Staff (retired)
Hippy - I finally found the thread I was looking for.
Good sleuthing and thanks for letting us know.

I would appreciate a clear explaination of how much of an IF command is executed in a single pass through a task comparing the examples above with the form where the whole IF conditional is on a single line.
If <condition> Then <label>

The whole of the command will execute and then a task switch can occur.

If <condition> Then

For block structured IF-ENDIF, IF-ELSE-ENDIF, and one line IF commands, the command will execute up to the THEN and then a task switch can occur.

So if you had "If b0=1 Then Gosub MySub" the task switch can occur between the THEN and GOSUB and, whether GOSUB called or not, can occur before the command on the next line after the IF.
 

nick12ab

Senior Member
@hwholmes
To include someone's name in a post, you need to put after '[QUOTE' an = then the name then optionally include a colon and the post ID to add a link to the post in question. The post ID is the number at the end of the link to the post available by mousing over the post number by each post.
EXAMPLE:
[QUOTE="hwholmes, post: 180196"]Last edited by hwholmes; Today at 13:50. Reason: repair[/QUOTE]
turns into:
Last edited by hwholmes; Today at 13:50. Reason: repair
Also the last button in the bottom right of each quote is the MULTIQUOTE button which makes it easy to reply to multiple posts in one post by pressing MULTIQUOTE for each post you want to reply to then clicking 'Reply To Thread' at the bottom of the thread and multiple
tags will be inserted.
 
Top