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

This commit is contained in:
legrand 2006-12-20 13:04:18 +00:00
commit 8fe0255b24
58 changed files with 45668 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

Some files were not shown because too many files have changed in this diff Show more