>
> I thought of parallel-map first but I wanted to do a bit more than that,
> otherwise I could just write a script that handles one and feed it to
> GNU parallel. I wanted to achieve more than what I can with GNU parallel
> (which is able to parallelize on multiple cores and writes correctly to
> stdout by not mixing the outputs of several tasks). Since I know the
> count ahead I wanted to suppress the git output and instead show a
> progress bar with some results, e.g. if the pull/fetch was successful or
> not. The only way I can imagine that is by message passing. But as I
> explained the threads don't seem to work as I expect, the recieving
> thread doesn't get to "speak up" until it's too long. Is there any way
> one can make a particular thread higher priority or come up right when
> it gets a message? Also, when does factor end? I have a bunch of threads
> that are waiting for I/O or network response and it finishes anyway. My
> problem with threads is that I don't understand what's happening behind
> the scenes, who goes when, how many of them at once, etc.


Here is a simple example of ``n`` worker threads that do some number of
work (in this case sleeping and then doing "1" unit of work) and then push
that work into a mailbox.  The main thread does a mailbox-get and adds that
work to its total and updates a progress-bar, finishing when all the
expected work is done:

:: start-thread-example1 ( n -- )

    <mailbox> :> box

    n iota [
        '[
            _ 100 * milliseconds sleep
            1 box mailbox-put
        ] "Worker" spawn drop
    ] each

    0 [
        box mailbox-get +
        dup n / 70 make-progress-bar print
        dup n <
    ] loop drop ;


In the ``progress-bars.model`` vocabulary we have a visual model that can
be used in a GUI, or you can just print it to standard-out.

If you wanted to see how the count-downs code might look (without
progress-bars), maybe something like this:

:: start-thread-example2 ( n -- )

    n <count-down> :> coord

    n iota [
        '[
            _ 100 * milliseconds sleep
            coord count-down
        ] "Worker" spawn drop
    ] each

    coord await ;

There are a lot of ways to solve the problem, but without knowing more
about what you're looking for, I'll just leave these here.

Best,
John.
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to