Forums > Dev

cpu intensive offline processes: how to?

November 7, 2007 | 5:14 pm

Hi,

I have an external that performs a cpu intensive process and bangs out when that process is done. While my intensive processing is running, max is "on hold" and waits until completion before letting me access my patch again (little cycling rainbow circle on OS X). I have tried using defer and defer_low but this does not change anything.
What is the proper way to acheive this?
Any help will be appreciated.

thanks

ps: the cpu intensive process can be an offline analysis of an audio file for instance.


November 7, 2007 | 5:25 pm

To be more clear: I would like the cpu intensive process to have a low priority and run only when there are cpu cycles available. I do not care how long it takes really. I just need to be informed when it is done somehow.


November 7, 2007 | 6:10 pm

On Nov 7, 2007, at 9:25 AM, tirilo wrote:

>
> To be more clear: I would like the cpu intensive process to have a
> low priority and run only when there are cpu cycles available. I do
> not care how long it takes really. I just need to be informed when
> it is done somehow.

To do this in another thread, see the simplethread examples on my
share page. Otherwise you can use a qelem loop which performs small
chunks of your operation in your queue function and then calls
qelem_set until complete. This is similar to a "cooperative" multi-
threading model. There might be some other threads that discuss qelem
loops in the archives if this quick mention of it isn’t clear enough.

http://www.cycling74.com/twiki/bin/view/Share/JoshuaKitClayton

-Joshua


November 7, 2007 | 6:27 pm

thanks! I do not know anything really about threading and thread issues yet so I guess that’s a good opportunity to learn. Any pointers to a good doc/tutorial where I could get the basic ideas and concepts?
The vague idea I have of it so far is that you can get processes to run at different priority levels and that some memory areas must be locked somehow during critical operations so that two processes don’t mess up their common memory space. But I do not know any of the specifics. I also heard the concept of re-entrant but not really sure what it means. Thanks again.


November 7, 2007 | 7:07 pm

On Nov 7, 2007, at 10:27 AM, tirilo wrote:

>
> thanks! I do not know anything really about threading and thread
> issues yet so I guess that’s a good opportunity to learn. Any
> pointers to a good doc/tutorial where I could get the basic ideas
> and concepts?

I Like Andrew Tanenbaum’s "Modern Operating Sysems". One of the
chapters on threads is available online (link below), but I’d
recommend investing in it if you are interested in learning more.

http://www.cs.vu.nl/~ast/books/mos2/

-Joshua


November 7, 2007 | 7:37 pm

So if he does spawn a thread, how can he propagate the result? Does
he just set the output from the non-scheduler thread when the
operation finishes and then Max grabs that from the scheduler thread
and propagates on the next scheduler cycle?

I suppose this is similar to what metro does, right?

_Mark

On Nov 7, 2007, at 10:10 AM, Joshua Kit Clayton wrote:

>
> On Nov 7, 2007, at 9:25 AM, tirilo wrote:
>
>>
>> To be more clear: I would like the cpu intensive process to have a
>> low priority and run only when there are cpu cycles available. I do
>> not care how long it takes really. I just need to be informed when
>> it is done somehow.
>
> To do this in another thread, see the simplethread examples on my
> share page. Otherwise you can use a qelem loop which performs small
> chunks of your operation in your queue function and then calls
> qelem_set until complete. This is similar to a "cooperative" multi-
> threading model. There might be some other threads that discuss
> qelem loops in the archives if this quick mention of it isn’t clear
> enough.
>
> http://www.cycling74.com/twiki/bin/view/Share/JoshuaKitClayton
>
> -Joshua
>
>


November 7, 2007 | 8:18 pm

On Nov 7, 2007, at 11:37 AM, Mark Pauley wrote:

> So if he does spawn a thread, how can he propagate the result?
> Does he just set the output from the non-scheduler thread when the
> operation finishes and then Max grabs that from the scheduler
> thread and propagates on the next scheduler cycle?

One can schedule an event for execution in the scheduler thread with
schedule() or clock_delay(), or for the low priority queue execution
using defer(_low) or qelem_set(). The last of which I believe is the
strategy that the simplethread example employs. It it not safe or
recommended to make any outlet calls from any other threads.

> I suppose this is similar to what metro does, right?

metro doesn’t spawn another thread but it does use clock_delay()

-Joshua


November 7, 2007 | 9:17 pm

> One can schedule an event for execution in the scheduler thread with
> schedule() or clock_delay(), or for the low priority queue execution
> using defer(_low) or qelem_set(). The last of which I believe is the
> strategy that the simplethread example employs. It it not safe or
> recommended to make any outlet calls from any other threads.

That is excellent info! Thanks Josh!

_Mark


November 22, 2007 | 9:06 am

Everything now works fine. And I even can get data from the thread every once in a while if I need to. thanks!

For those as unexperienced as me who would be in the same situation:

The simplethread example for mach-o was the most helpful for me. Also I found a helpfull "pthread description and tutorial" at

http://vergil.chemistry.gatech.edu/resources/programming/threads.html

cheers


Viewing 9 posts - 1 through 9 (of 9 total)