Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % fib_small_uc.pl %
- % %
- % Scheduling of a parallel fibonacci %
- % computation on a homogeoneous system %
- % (uniform communication costs) %
- % %
- % Declarative Programming %
- % 2014-2015 %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%%%
- %%% Cores %%%
- %%%%%%%%%%%%%%%%
- % The cores of the machine
- % core(Id): a core with unique identifier 'Id'.
- core(c1).
- core(c2).
- core(c3).
- core(c4).
- %%%%%%%%%%%%%%%%%%
- %%% Tasks %%%
- %%%%%%%%%%%%%%%%%%
- % The tasks the application is made up of, which are to be scheduled.
- % task(Id): a task with unique identifier 'Id'.
- task(t7).
- task(t1).
- task(t6).
- task(t2).
- task(t4).
- task(t3).
- task(t5).
- %%%%%%%%%%%%%%%%%%
- %% Dependencies %%
- %%%%%%%%%%%%%%%%%%
- % The execution order dependencies between tasks
- % depends_on(Ta,Tb,Data): before task 'Ta' can be executed,
- % task 'Tb' must have been executed and thereafter 'Data' megabytes of data (result of/produced by 'Tb') must have been moved from the processor that executed 'Tb' to the processor that will execute 'Ta'.
- % %In this benchmark tasks are interdependent, but no data is communicated between tasks.
- depends_on(t7,t2,0).
- depends_on(t7,t6,0).
- depends_on(t6,t4,0).
- depends_on(t6,t5,0).
- depends_on(t2,t1,0).
- depends_on(t4,t3,0).
- depends_on(t3,t1,0).
- depends_on(t5,t3,0).
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%% Processing Costs %%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Specifies how long the processing of each task takes on each core.
- % process_cost(T,C,Time): It takes 'Time' ms to execute task 'T' on core 'C'.
- %In this benchmark any task takes as long on any core (i.e. homogeneous system)
- process_cost(T,C,10) :- task(T), core(C).
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%% Channel Properties %%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Specifies the properties of the communication channel between each of the cores
- % channel(Ca,Cb,Latency,Bandwidth): The channel to communicate from core 'Ca' to core 'Cb' has a latency 'Latency' and bandwidth 'Bandwidth'.
- % Note that sending 'X' megabytes of data, over a channel, takes Latency + X/Bandwidth ms.
- %In this benchmark sending a given message take as long, independent of sender/recipient/message size (uniform access).
- channel(C,C,15,1) :- !,core(C).
- channel(C1,C2,15,1) :- C1 \= C2, core(C1), core(C2).
- %:- use_module(library(clpfd)).
- :- use_module(library(clpq)).
- schedule(BestSchedule, BestTotTime) :-
- findall(T,task(T),Tasks),
- findall(C,core(C),Cores),
- init_time,
- const_time(Tasks,Schedule,Cores,TotTime),
- assign_processor(Schedule,Cores, TotTime),
- %const_channel(Schedule),
- minimize(TotTime),
- update_time(Schedule, TotTime),
- write(TotTime), writeln(Schedule),
- fail
- ;
- bestsofar(BestSchedule,BestTotTime)
- .
- %Setting Time Contraints on certain variables
- const_time([],[], _ ,TotTime).
- const_time([T|Ts], [task(T,Start,Duration,Core)|Rest], Cores,TotTime) :-
- %member(Core,Cores),
- %process_cost(T,Core,Duration), %Duration is based on core and task
- { Start >= 0,
- Start + Duration =< TotTime }, %Set TotTime as maximum of all end task time
- const_time(Ts, Rest, Cores,TotTime),
- const_order(task(T,Start,Duration,Core), Rest).
- %Set constarints for start time based on dependancy and channel communication
- const_order(_,[]).
- const_order(task(T,S,D,_),[task(T2,S2,D2,_)|Rest]) :-
- (depends_on(T,T2,_),!, { S2 + D2 =< S };
- depends_on(T2,T,_),!, { S + D =< S2 };
- true),
- const_order(task(T,S,D,_),Rest).
- %Set constarints for start time based on dependancy and channel communication
- const_channel([]).
- const_channel([task(T,S,D,C)|Rest]) :-
- const_channel(task(T,S,D,C), Rest),
- const_channel(Rest).
- const_channel(_,[]).
- const_channel(task(T,S,D,C),[task(T2,S2,D2,C2)|Rest]) :-
- (depends_on(T,T2,Da),channel(C,C2,L,B),!, { S2 + D2 =< S };
- depends_on(T2,T,Da),channel(C2,C,L,B),!, { S + D =< S2 };
- true),
- const_channel(task(T,S,D,C),Rest).
- assign_processor([], _, _).
- assign_processor([task(T,S,D,C)|Rest], Cores, TotTime) :-
- assign_processor(Rest,Cores,TotTime),
- %member(C,Cores),
- core(C),
- process_cost(T,C,D),
- const_resource(task(T,S,D,C),Rest),
- bestsofar(_,CurrentBestTime),
- {TotTime < CurrentBestTime}.
- const_resource(_,[]).
- const_resource(Task,[Task2|Rest]) :-
- no_data(Task,Task2),
- no_conflict(Task,Task2),
- const_resource(Task, Rest).
- no_conflict(task(_,S,D,C),task(_,S2,D2,C2)) :-
- C \== C2,!;
- { S+D =< S2;
- S2+D2 =< S }.
- no_data(task(T,S,D,C), task(T2,S2,D2,C2)) :-
- depends_on(T,T2,_),channel(C,C2,L,_),!, { S2 + D2 =< S - L };
- depends_on(T2,T,_),!,channel(C2,C,L,_),!, { S + D =< S2 - L};
- true.
- init_time :-
- retract(bestsofar(_,_)), fail
- ;
- assert(bestsofar(foobar, 1000)).
- update_time(Schedule,TotTime) :-
- retract(bestsofar(_,_)),!,
- assert(bestsofar(Schedule,TotTime)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement