------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Cheddar is a GNU GPL real-time scheduling analysis tool. -- This program provides services to automatically check schedulability and -- other performance criteria of real-time architecture models. -- -- Copyright (C) 2002-2020, Frank Singhoff, Alain Plantec, Jerome Legrand, -- Hai Nam Tran, Stephane Rubini -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285, Université de Bretagne Occidentale -- -- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008. -- Since 2008, Ellidiss technologies also contributes to the development of -- Cheddar and provides industrial support. -- -- The full list of contributors and sponsors can be found in AUTHORS.txt and SPONSORS.txt -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- -- -- Contact : cheddar@listes.univ-brest.fr -- ------------------------------------------------------------------------------ -- Last update : -- $Rev$ -- $Date$ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Paes_Utilities; use Paes_Utilities; with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Debug; use Debug; procedure paes_general_form is -- for parallel execution -- a ToDo and a Done lists, protected by a mutex ToDoSolList : array (0 .. MAX_SLAVES) of solution; ToDoIndex : integer := 0; DoneSolList : array (0 .. MAX_SLAVES) of solution; DoneIndex : integer := 0; F6 : Ada.Text_IO.File_Type; nb_rejectedSol,k : Integer; task type Mutex is entry P; entry V; entry E; end Mutex; task body Mutex is finished : boolean := false; begin loop select accept P; or accept E do finished := true; -- loop end E; end select; if (not finished) then accept V; else exit; end if; end loop; end Mutex; DoneSolMutex : mutex; TodoSolMutex : mutex; task type slave_task; task body slave_task is found : integer; tomute : solution; eidx : integer; begin loop loop found := 0; ToDoSolMutex.P; if ToDoIndex > 0 then ToDoIndex := ToDoIndex - 1; tomute := ToDoSolList (ToDoIndex); found := 1; end if; ToDoSolMutex.V; if found = 1 then exit; end if; delay 0.5; end loop; eidx := tomute.grid_loc; if eidx < 0 then -- marked for ending task exit; end if; mutate (tomute, eidx); evaluate (tomute, eidx); DoneSolMutex.P; DoneSolList (DoneIndex) := tomute; DoneIndex := DoneIndex + 1; DoneSolMutex.V; end loop; --Put_Line("I am dead"); end slave_task; RunningSlaves : array (1 .. MAX_SLAVES) of slave_task; mfound : integer; begin -- Initializing the current solution c, -- the initial_system -- and the list of all possible Fitness functions Append (Data3, "iteration" & " " & "Missed_deadline" &" " &"bell" &" " & "biba" &" "& ASCII.LF); init; ------------------------- -- begin the main loop -- ------------------------- --Parallel running of first mutations --useless tasks are told to die if slaves > 0 then ToDoSolMutex.P; for i in 0..MAX_SLAVES-1 loop ToDoSolList(i) := c; if i < slaves then ToDoSolList(i).grid_loc := i; else ToDoSolList(i).grid_loc := -1; end if; end loop; ToDoIndex := MAX_SLAVES; ToDoSolMutex.V; else --killing all tasks (except mutex) ToDoSolMutex.P; for i in 0..MAX_SLAVES-1 loop ToDoSolList(i).grid_loc := -1; end loop; ToDoIndex := MAX_SLAVES; ToDoSolMutex.V; end if; for i in 1..iterations loop Put_Debug("==iter "& i'img ); -- copy the current solution m := c; -- in sequential: -- mutate (m, 0); -- in parallel, when deployed: -- run_mutate(m, i); -- for test of reentrant code if slaves < 1 then mutate(m, 0); --sequential evaluate(m,0); Append (Data3, i'img & " " & m.obj(1)'img &" " &m.obj(2)'img &" " & m.obj(3)'img &" "& ASCII.LF); else mfound := 0; loop DoneSolMutex.P; if DoneIndex > 0 then DoneIndex := DoneIndex - 1; m := DoneSolList(DoneIndex); mfound := 1; end if; DoneSolMutex.V; if mfound = 1 then exit; end if; delay 0.5; end loop; end if; Selection_and_archiving; if slaves > 0 then if i <= (iterations - slaves) then ToDoSolMutex.P; ToDoSolList(ToDoIndex) := c; ToDoSolList(ToDoIndex).grid_loc := slaves + i; ToDoIndex := ToDoIndex + 1; ToDoSolMutex.V; end if; end if; end loop; nb_rejectedSol := nb_InitSol+iterations-arclength; Append (Data3," " & ASCII.LF); Append (Data3," " & ASCII.LF); Append (Data3,"Number of rejected solution during the archiving process : " & nb_rejectedSol'img & ASCII.LF); Append (Data3,"Number of non feasible solution during mutations : " & nb_NoFeasible_Sol'img & ASCII.LF); Create(F6,Ada.Text_IO.Out_File,"PAES_Execution_iter.dat"); Unbounded_IO.Put_Line(F6, Data3); Close(F6); --send invalid task to end the slaves if slaves > 0 then ToDoSolMutex.P; for i in 0..slaves-1 loop ToDoSolList(i) := c; ToDoSolList(i).grid_loc := -1; end loop; ToDoIndex := slaves; ToDoSolMutex.V; end if; -- end all tasks ToDoSolMutex.E; DoneSolMutex.E; end paes_general_form;