Places: remove old code
This commit is contained in:
parent
7a4a287ca6
commit
1ebdb6a90b
|
@ -14,18 +14,17 @@
|
||||||
|
|
||||||
@; ----------------------------------------------------------------------
|
@; ----------------------------------------------------------------------
|
||||||
|
|
||||||
The PLT futures API enables the development of parallel programs which
|
The PLT Places API enables the development of parallel programs which
|
||||||
take advantage of machines with multiple processors, cores, or
|
take advantage of machines with multiple processors, cores, or
|
||||||
hardware threads.
|
hardware threads.
|
||||||
|
|
||||||
@defmodule[racket/place]{}
|
@defmodule[racket/place]{}
|
||||||
|
|
||||||
@defproc[(place [module-path module-path?] [start-proc proc?] [place-channel place-channel?]) place?]{
|
@defproc[(place [module-path module-path?] [start-proc proc?]) place?]{
|
||||||
Starts running @racket[start-proc] in parallel. @racket[start-proc] must
|
Starts running @racket[start-proc] in parallel. @racket[start-proc] must
|
||||||
be a function defined in @racket[module-path]. Each place is created with a racket[place-channel]
|
be a function defined in @racket[module-path]. The @racket[place]
|
||||||
that permits communication with the place originator. This initial channel can be overridden with
|
|
||||||
an optional @racket[place-channel] argument. The @racket[place]
|
|
||||||
procedure returns immediately with a place descriptor value representing the newly constructed place.
|
procedure returns immediately with a place descriptor value representing the newly constructed place.
|
||||||
|
Each place descriptor value is also a racket[place-channel] that permits communication with the place.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(place-wait [p place?]) exact-integer?]{
|
@defproc[(place-wait [p place?]) exact-integer?]{
|
||||||
|
@ -38,12 +37,12 @@ hardware threads.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(place-channel) (values place-channel? place-channel?)]{
|
@defproc[(place-channel) (values place-channel? place-channel?)]{
|
||||||
Returns two @racket[place-channel] objects.
|
Returns two @racket[place-channel] endpoint objects.
|
||||||
|
|
||||||
One @racket[place-channel] should be used by the current @racket[place] to send
|
One @racket[place-channel] endpoint should be used by the current @racket[place] to send
|
||||||
messages to a destination @racket[place].
|
messages to a destination @racket[place].
|
||||||
|
|
||||||
The other @racket[place-channel] should be sent to a destination @racket[place] over
|
The other @racket[place-channel] endpoint should be sent to a destination @racket[place] over
|
||||||
an existing @racket[place-channel].
|
an existing @racket[place-channel].
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,15 +64,18 @@ hardware threads.
|
||||||
Returns an immutable message received on channel @racket[ch].
|
Returns an immutable message received on channel @racket[ch].
|
||||||
}
|
}
|
||||||
|
|
||||||
@section[#:tag "example"]{How Do I Keep Those Cores Busy?}
|
@section[#:tag "example"]{Basic Example?}
|
||||||
|
|
||||||
This code launches two places passing 1 and 2 as the initial channels
|
This code launches two places, echos a message to them and then waits for the places to complete and return.
|
||||||
and then waits for the places to complete and return.
|
|
||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
(let ((pls (map (lambda (x) (place "place-worker.ss" 'place-main x))
|
(let ([pls (for/list ([i (in-range 2)])
|
||||||
(list 1 2))))
|
(place "place-worker.rkt" 'place-main))])
|
||||||
(map place-wait pls))
|
(for ([i (in-range 2)]
|
||||||
|
[p pls])
|
||||||
|
(place-channel-send p i)
|
||||||
|
(printf "~a~n" (place-channel-recv p)))
|
||||||
|
(map place-wait pls))
|
||||||
]
|
]
|
||||||
|
|
||||||
This is the code for the place-worker.ss module that each place will execute.
|
This is the code for the place-worker.ss module that each place will execute.
|
||||||
|
@ -82,8 +84,8 @@ This is the code for the place-worker.ss module that each place will execute.
|
||||||
(module place-worker racket
|
(module place-worker racket
|
||||||
(provide place-main)
|
(provide place-main)
|
||||||
|
|
||||||
(define (place-main x)
|
(define (place-main ch)
|
||||||
(printf "IN PLACE ~a~n" x)))
|
(place-channel-send ch (format "Hello from place ~a" (place-channel-recv ch)))))
|
||||||
]
|
]
|
||||||
|
|
||||||
@section[#:tag "place-channels"]{Place Channels}
|
@section[#:tag "place-channels"]{Place Channels}
|
||||||
|
|
|
@ -73,7 +73,7 @@ void scheme_init_place(Scheme_Env *env)
|
||||||
|
|
||||||
plenv = scheme_primitive_module(scheme_intern_symbol("#%place"), env);
|
plenv = scheme_primitive_module(scheme_intern_symbol("#%place"), env);
|
||||||
|
|
||||||
PLACE_PRIM_W_ARITY("place", scheme_place, 1, 3, plenv);
|
PLACE_PRIM_W_ARITY("place", scheme_place, 2, 2, plenv);
|
||||||
PLACE_PRIM_W_ARITY("place-sleep", scheme_place_sleep, 1, 1, plenv);
|
PLACE_PRIM_W_ARITY("place-sleep", scheme_place_sleep, 1, 1, plenv);
|
||||||
PLACE_PRIM_W_ARITY("place-wait", scheme_place_wait, 1, 1, plenv);
|
PLACE_PRIM_W_ARITY("place-wait", scheme_place_wait, 1, 1, plenv);
|
||||||
PLACE_PRIM_W_ARITY("place?", scheme_place_p, 1, 1, plenv);
|
PLACE_PRIM_W_ARITY("place?", scheme_place_p, 1, 1, plenv);
|
||||||
|
@ -161,29 +161,25 @@ Scheme_Object *scheme_place(int argc, Scheme_Object *args[]) {
|
||||||
place_data = MALLOC_ONE(Place_Start_Data);
|
place_data = MALLOC_ONE(Place_Start_Data);
|
||||||
place_data->ready = ready;
|
place_data->ready = ready;
|
||||||
|
|
||||||
if (argc == 2 || argc == 3 ) {
|
if (argc == 2) {
|
||||||
Scheme_Object *so;
|
Scheme_Object *so;
|
||||||
so = scheme_places_deep_copy_in_master(args[0]);
|
so = scheme_places_deep_copy_in_master(args[0]);
|
||||||
place_data->module = so;
|
place_data->module = so;
|
||||||
so = scheme_places_deep_copy_in_master(args[1]);
|
so = scheme_places_deep_copy_in_master(args[1]);
|
||||||
place_data->function = so;
|
place_data->function = so;
|
||||||
place_data->ready = ready;
|
place_data->ready = ready;
|
||||||
if (argc == 2) {
|
|
||||||
|
/* create channel */
|
||||||
|
{
|
||||||
Scheme_Place_Bi_Channel *channel;
|
Scheme_Place_Bi_Channel *channel;
|
||||||
channel = scheme_place_bi_channel_create();
|
channel = scheme_place_bi_channel_create();
|
||||||
place->channel = (Scheme_Object *) channel;
|
place->channel = (Scheme_Object *) channel;
|
||||||
channel = scheme_place_bi_peer_channel_create(channel);
|
channel = scheme_place_bi_peer_channel_create(channel);
|
||||||
place_data->channel = (Scheme_Object *) channel;
|
place_data->channel = (Scheme_Object *) channel;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Scheme_Object *channel;
|
|
||||||
channel = args[2];
|
|
||||||
place_data->channel = channel;
|
|
||||||
place->channel = channel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scheme_wrong_count_m("place", 1, 2, argc, args, 0);
|
scheme_wrong_count_m("place", 2, 2, argc, args, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
collection_paths = scheme_current_library_collection_paths(0, NULL);
|
collection_paths = scheme_current_library_collection_paths(0, NULL);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user