git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@130 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
atantar 2006-12-30 14:10:44 +00:00
commit a6fe42664b
743 changed files with 67629 additions and 0 deletions

View file

@ -0,0 +1,85 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "comm.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <vector>
#include <map>
#include <cassert>
#include "communicable.h"
static std :: vector <Communicable *> key_to_comm (1); /* Vector of registered cooperators */
static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of registered cooperators */
unsigned Communicable :: num_comm = 0;
Communicable :: Communicable () {
comm_to_key [this] = key = ++ num_comm;
key_to_comm.push_back (this);
sem_init (& sem_lock, 0, 1);
sem_init (& sem_stop, 0, 0);
}
Communicable :: ~ Communicable () {
}
COMM_ID Communicable :: getKey () {
return key;
}
Communicable * getCommunicable (COMM_ID __key) {
assert (__key < key_to_comm.size ());
return key_to_comm [__key];
}
COMM_ID getKey (const Communicable * __comm) {
return comm_to_key [__comm];
}
void Communicable :: lock () {
sem_wait (& sem_lock);
}
void Communicable :: unlock () {
sem_post (& sem_lock);
}
void Communicable :: stop () {
sem_wait (& sem_stop);
}
void Communicable :: resume () {
sem_post (& sem_stop);
}

View file

@ -0,0 +1,62 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "communicable.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __communicable_h
#define __communicable_h
#include <semaphore.h>
typedef unsigned COMM_ID;
class Communicable {
public :
Communicable ();
virtual ~ Communicable ();
COMM_ID getKey ();
void lock (); /* It suspends the current process if the semaphore is locked */
void unlock (); /* It unlocks the shared semaphore */
void stop (); /* It suspends the current process */
void resume (); /* It resumes ___________ */
protected :
COMM_ID key;
sem_t sem_lock;
sem_t sem_stop;
static unsigned num_comm;
};
extern Communicable * getCommunicable (COMM_ID __key);
//extern COMM_ID getKey (const Communicable * __comm);
#endif

View file

@ -0,0 +1,56 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "cooperative.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __cooperative_h
#define __cooperative_h
#include "communicable.h"
#include "runner.h"
typedef unsigned COOP_ID;
class Cooperative : public Communicable {
public :
Runner * getOwner ();
void setOwner (Runner & __runner);
virtual void pack () = 0;
virtual void unpack () = 0;
void send (Cooperative * __coop);
virtual void notifySending ();
private :
Runner * owner;
};
extern Cooperative * getCooperative (COOP_ID __key);
#endif

View file

@ -0,0 +1,47 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "eoPop_comm.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __eoPop_comm_h
#define __eoPop_comm_h
#include <eoPop.h>
#include "messaging.h"
template <class EOT> void pack (const eoPop <EOT> & __pop) {
pack ((unsigned) __pop.size ());
for (unsigned i = 0; i < __pop.size (); i ++)
pack (__pop [i]);
}
template <class EOT> void unpack (eoPop <EOT> & __pop) {
unsigned n;
unpack (n);
__pop.resize (n);
for (unsigned i = 0; i < n; i ++)
unpack (__pop [i]);
}
#endif

View file

@ -0,0 +1,53 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "eoVector_comm.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __eoVector_comm_h
#define __eoVector_comm_h
#include <eoVector.h>
#include "messaging.h"
template <class F, class T> void pack (const eoVector <F, T> & __v) {
pack (__v.fitness ()) ;
unsigned len = __v.size ();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (__v [i]);
}
template <class F, class T> void unpack (eoVector <F, T> & __v) {
F fit;
unpack (fit);
__v.fitness (fit);
unsigned len;
unpack (len);
__v.resize (len);
for (unsigned i = 0 ; i < len; i ++)
unpack (__v [i]);
}
#endif

View file

@ -0,0 +1,119 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "messaging.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __mess_h
#define __mess_h
#include <utility>
/* Char */
extern void pack (const char & __c);
/* Float */
extern void pack (const float & __f, int __nitem = 1);
/* Double */
extern void pack (const double & __d, int __nitem = 1);
/* Integer */
extern void pack (const int & __i, int __nitem = 1);
/* Unsigned int. */
extern void pack (const unsigned int & __ui, int __nitem = 1);
/* Short int. */
extern void pack (const short & __sh, int __nitem = 1);
/* Unsigned short */
extern void pack (const unsigned short & __ush, int __nitem = 1);
/* Long */
extern void pack (const long & __l, int __nitem = 1);
/* Unsigned long */
extern void pack (const unsigned long & __ul, int __nitem = 1);
/* String */
extern void pack (const char * __str);
/* Pointer */
template <class T> void pack (const T * __ptr) {
pack ((unsigned long) __ptr);
}
/* Pair */
template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
pack (__pair.first);
pack (__pair.second);
}
//
/* Float */
extern void unpack (char & __c);
/* Float */
extern void unpack (float & __f, int __nitem = 1);
/* Double */
extern void unpack (double & __d, int __nitem = 1);
/* Integer */
extern void unpack (int & __i, int __nitem = 1);
/* Unsigned int. */
extern void unpack (unsigned int & __ui, int __nitem = 1);
/* Short int. */
extern void unpack (short & __sh, int __nitem = 1);
/* Unsigned short */
extern void unpack (unsigned short & __ush, int __nitem = 1);
/* Long */
extern void unpack (long & __l, int __nitem = 1);
/* Unsigned long */
extern void unpack (unsigned long & __ul, int __nitem = 1);
/* String */
extern void unpack (char * __str);
/* Pointer */
template <class T> void unpack (T * & __ptr) {
unsigned long p;
unpack (p);
__ptr = (T *) p;
}
/* Pair */
template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
unpack (__pair.first);
unpack (__pair.second);
}
#endif

View file

@ -0,0 +1,92 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_debug.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "peo_debug.h"
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <vector>
#include "peo_debug.h"
#define MAX_BUFF_SIZE 1000
#define DEBUG_PATH "./log/"
static bool debug = true;
static char host [MAX_BUFF_SIZE];
std :: vector <FILE *> files;
void setDebugMode (bool __dbg) {
debug = __dbg;
gethostname (host, MAX_BUFF_SIZE);
}
extern int getNodeRank ();
void initDebugging () {
mkdir (DEBUG_PATH, S_IRWXU);
// files.push_back (stdout);
char buff [MAX_BUFF_SIZE];
sprintf (buff, "%s/%d", DEBUG_PATH, getNodeRank ());
files.push_back (fopen (buff, "w"));
}
void endDebugging () {
for (unsigned i = 0; i < files.size (); i ++)
if (files [i] != stdout)
fclose (files [i]);
}
void printDebugMessage (const char * __mess) {
if (debug) {
char buff [MAX_BUFF_SIZE];
time_t t = time (0);
/* Date */
sprintf (buff, "[%s][%s: ", host, ctime (& t));
* strchr (buff, '\n') = ']';
for (unsigned i = 0; i < files.size (); i ++)
fprintf (files [i], buff);
/* Message */
sprintf (buff, "%s", __mess);
for (unsigned i = 0; i < files.size (); i ++) {
fputs (buff, files [i]);
fputs ("\n", files [i]);
fflush (files [i]);
}
}
}

View file

@ -0,0 +1,37 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_debug.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __peo_debug_h
#define __peo_debug_h
extern void initDebugging ();
extern void endDebugging ();
extern void setDebugMode (bool __dbg = true); /* (Des)activating the Debugging mode */
extern void printDebugMessage (const char * __mess); /* Print a new message both on the
standard output and a target
text-file in a subdirectory) */
#endif

View file

@ -0,0 +1,39 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_finalize.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "peo_fin.h"
#include "peo_debug.h"
#include "runner.h"
#include "rmc.h"
void peo :: finalize () {
printDebugMessage ("waiting for the termination of all threads");
joinRunners ();
finalizeRMC ();
printDebugMessage ("this is the end");
endDebugging ();
}

View file

@ -0,0 +1,32 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_finalize.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __peo_finalize_h
#define __peo_finalize_h
namespace peo {
extern void finalize ();
}
#endif

View file

View file

@ -0,0 +1,52 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_init.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <stdio.h>
#include "peo_init.h"
#include "peo_param.h"
#include "peo_debug.h"
#include "rmc.h"
namespace peo {
int * argc;
char * * * argv;
void init (int & __argc, char * * & __argv) {
argc = & __argc;
argv = & __argv;
/* Initializing the the Resource Management and Communication */
initRMC (__argc, __argv);
/* Loading the common parameters */
loadParameters (__argc, __argv);
/* */
initDebugging ();
}
}

View file

@ -0,0 +1,36 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_init.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __peo_init_h
#define __peo_init_h
namespace peo {
extern int * argc;
extern char * * * argv;
extern void init (int & __argc, char * * & __argv);
}
#endif

View file

View file

@ -0,0 +1,40 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_param.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <utils/eoParser.h>
#include "peo_param.h"
#include "peo_debug.h"
void peo :: loadParameters (int & __argc, char * * & __argv) {
eoParser parser (__argc, __argv);
/* Debug */
eoValueParam <std :: string> debug_param ("false", "debug", "?");
parser.processParam (debug_param);
if (debug_param.value () == "true")
setDebugMode ();
}

View file

@ -0,0 +1,32 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_param.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __peo_param_h
#define __peo_param_h
namespace peo {
extern void loadParameters (int & __argc, char * * & __argv);
}
#endif

View file

@ -0,0 +1,34 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_run.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "peo_init.h"
#include "peo_run.h"
#include "rmc.h"
#include "runner.h"
void peo :: run () {
startRunners ();
runRMC ();
}

View file

@ -0,0 +1,32 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "peo_run.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __peo_run_h
#define __peo_run_h
namespace peo {
extern void run ();
}
#endif

View file

View file

@ -0,0 +1,51 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "reac_thread.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "reac_thread.h"
static bool the_end = false;
static std :: vector <ReactiveThread *> reac_threads;
ReactiveThread :: ReactiveThread () {
reac_threads.push_back (this);
sem_init (& sem, 0, 0);
}
void ReactiveThread :: sleep () {
sem_wait (& sem);
}
void ReactiveThread :: wakeUp () {
sem_post (& sem);
}
void stopReactiveThreads () {
the_end = true;
for (unsigned i = 0; i < reac_threads.size (); i ++)
reac_threads [i] -> wakeUp ();
}

View file

@ -0,0 +1,50 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "reac_thread.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef REAC_THREAD_H_
#define REAC_THREAD_H_
#include <semaphore.h>
#include "thread.h"
class ReactiveThread : public Thread {
public:
/* Ctor */
ReactiveThread ();
void sleep ();
void wakeUp ();
private:
sem_t sem;
};
extern void stopReactiveThreads ();
#endif /*THREAD_H_*/

View file

@ -0,0 +1,40 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "ring_topo.cpp"
// (c) OPAC Team, LIFL, September 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "ring_topo.h"
void RingTopology :: setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to) {
__from.clear () ;
__to.clear () ;
int len = mig.size () ;
for (int i = 0 ; i < len ; i ++)
if (mig [i] == __mig) {
__from.push_back (mig [(i - 1 + len) % len]) ;
__to.push_back (mig [(i + 1) % len]) ;
break;
}
}

View file

@ -0,0 +1,39 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "ring_topo.h"
// (c) OPAC Team, LIFL, September 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __ring_topo_h
#define __ring_topo_h
#include "topology.h"
class RingTopology : public Topology {
public :
void setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to);
};
#endif

View file

@ -0,0 +1,33 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "rmc.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __rmc_h
#define __rmc_h
extern void initRMC (int & __argc, char * * & __argv);
extern void runRMC (); /* Resource Management and Communication */
extern void finalizeRMC ();
#endif

View file

View file

@ -0,0 +1,119 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "runner.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <vector>
#include "runner.h"
#include "reac_thread.h"
#include "peo_debug.h"
#include "messaging.h"
static unsigned num_act = 0; /* Number of active runners */
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
static std :: vector <Runner *> the_runners;
static unsigned num_runners = 0;
Runner :: Runner () {
id = ++ num_runners;
the_runners.push_back (this);
sem_init (& sem_start, 0, 0);
num_act ++;
}
extern int getNodeRank ();
extern int getNumberOfNodes ();
void unpackTerminationOfRunner () {
RUNNER_ID id;
unpack (id);
num_act --;
printDebugMessage ("I'm noticed of the termination of a runner");
if (! num_act) {
printDebugMessage ("all the runners have terminated. Now stopping the reactive threads.");
stopReactiveThreads ();
}
}
bool atLeastOneActiveRunner () {
return num_act;
}
RUNNER_ID Runner :: getID () {
return id;
}
void Runner :: start () {
setActive ();
sem_post (& sem_start);
run ();
terminate ();
}
void Runner :: notifySendingTermination () {
/*
char b [1000];
sprintf (b, "Il reste encore %d !!!!!!!!!!!!", n);
printDebugMessage (b);
*/
printDebugMessage ("je suis informe que tout le monde a recu ma terminaison");
setPassive ();
}
void Runner :: waitStarting () {
sem_wait (& sem_start);
}
Runner * getRunner (RUNNER_ID __key) {
return dynamic_cast <Runner *> (getCommunicable (__key));
}
void startRunners () {
/* Runners */
for (unsigned i = 0; i < the_runners.size (); i ++)
if (the_runners [i] -> isLocal ()) {
addThread (the_runners [i], ll_threads);
the_runners [i] -> waitStarting ();
}
printDebugMessage ("launched the parallel runners");
}
void joinRunners () {
joinThreads (ll_threads);
}

View file

View file

@ -0,0 +1,73 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "runner.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __runner_h
#define __runner_h
#include <eoFunctor.h>
#include "communicable.h"
#include "thread.h"
typedef unsigned RUNNER_ID;
class Runner : public Communicable, public Thread {
public :
Runner ();
void start ();
void waitStarting ();
bool isLocal ();
void terminate ();
virtual void run () = 0;
RUNNER_ID getID ();
void packTermination ();
void notifySendingTermination ();
private :
sem_t sem_start;
unsigned id;
};
extern bool atLeastOneActiveRunner ();
extern void unpackTerminationOfRunner ();
extern Runner * getRunner (RUNNER_ID __key);
extern void startRunners ();
extern void joinRunners ();
#endif

View file

View file

@ -0,0 +1,73 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "service.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "service.h"
void Service :: setOwner (Thread & __owner) {
owner = & __owner;
}
Thread * Service :: getOwner () {
return owner;
}
Service * getService (SERVICE_ID __key) {
return dynamic_cast <Service *> (getCommunicable (__key));
}
void Service :: notifySendingData () {
}
void Service :: notifySendingResourceRequest () {
num_sent_rr --;
if (! num_sent_rr)
notifySendingAllResourceRequests ();
}
void Service :: notifySendingAllResourceRequests () {
}
void Service :: packData () {
}
void Service :: unpackData () {
}
void Service :: execute () {
}
void Service :: packResult () {
}
void Service :: unpackResult () {
}

View file

@ -0,0 +1,65 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "service.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __service_h
#define __service_h
#include "communicable.h"
#include "thread.h"
typedef unsigned SERVICE_ID;
class Service : public Communicable {
public :
void setOwner (Thread & __owner);
Thread * getOwner ();
void requestResourceRequest (unsigned __how_many = 1);
void packResourceRequest ();
virtual void packData ();
virtual void unpackData ();
virtual void execute ();
virtual void packResult ();
virtual void unpackResult ();
virtual void notifySendingData ();
virtual void notifySendingResourceRequest ();
virtual void notifySendingAllResourceRequests ();
private :
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
};
extern Service * getService (SERVICE_ID __key);
#endif

View file

View file

@ -0,0 +1,96 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "thread.cpp"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include <map>
#include "thread.h"
static std :: vector <Thread *> threads;
unsigned num_act = 0;
Thread :: Thread () {
threads.push_back (this);
act = false;
}
Thread :: ~ Thread () {
/* Nothing ! */
}
extern int getNodeRank ();
void Thread :: setActive () {
if (! act ) {
act = true;
num_act ++;
// if (getNodeRank () == 1)
// printf ("On passe a %d\n", num_act);
}
}
void Thread :: setPassive () {
if (act) {
act = false;
num_act --;
// if (getNodeRank () == 1)
// printf ("On passe a %d\n", num_act);
}
}
bool atLeastOneActiveThread () {
return num_act;
}
unsigned numberOfActiveThreads () {
return num_act;
}
static void * launch (void * __arg) {
Thread * thr = (Thread *) __arg;
thr -> start ();
return 0;
}
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
pthread_t * ll_thr = new pthread_t;
__ll_threads.push_back (ll_thr);
pthread_create (ll_thr, 0, launch, __hl_thread);
}
void joinThreads (std :: vector <pthread_t *> & __threads) {
for (unsigned i = 0; i < __threads.size (); i ++)
pthread_join (* __threads [i], 0);
}

View file

View file

@ -0,0 +1,63 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "thread.h"
// (c) OPAC Team, LIFL, August 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef THREAD_H_
#define THREAD_H_
#include <vector>
/* A high-level thread */
class Thread {
public:
/* Ctor */
Thread ();
/* Dtor */
virtual ~ Thread ();
/* Go ! */
virtual void start () = 0;
void setActive ();/* It means the current process is going to send messages soon */
void setPassive ();/* The current process is not going to perform send operations
(but it may receive messages) */
private :
bool act;
};
extern void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads);
extern void joinThreads (std :: vector <pthread_t *> & __ll_threads);
extern bool atLeastOneActiveThread (); /* It returns 'true' iff at least one process is going
to send messages */
extern unsigned numberOfActiveThreads ();
#endif /*THREAD_H_*/

View file

View file

@ -0,0 +1,35 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "topo.cpp"
// (c) OPAC Team, LIFL, September 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#include "topology.h"
Topology :: ~ Topology () {
/* Nothing ! */
}
void Topology :: add (Cooperative & __mig) {
mig.push_back (& __mig) ;
}

View file

@ -0,0 +1,48 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "topology.h"
// (c) OPAC Team, LIFL, September 2005
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __topology_h
#define __topology_h
#include <vector>
#include "cooperative.h"
class Topology {
public:
virtual ~Topology ();
void add (Cooperative & __mig);
virtual void setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to) = 0;
protected:
std :: vector <Cooperative *> mig ;
};
#endif

View file