begin process at 2012 02 13 01:32:16
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Applications Linux

 > PARALLEL OBJECT PROGRAMMING IN C++ (POP-C++) : DEMO

PARALLEL OBJECT PROGRAMMING IN C++ (POP-C++) : DEMO


 Information sur la source

Note :
Aucune note
Catégorie :Applications Linux Classé sous :parallèle, sockets, threads, tcpip, orienté objet Niveau :Initié Date de création :22/06/2009 Vu / téléchargé :3 002 / 104

Auteur : lwinkler

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Voici un programme de démo qui a été écrit dans une extension de C++ (POP-C++). C'est un programme tout simple qui montre la création d'objets parallèles.

POP-C++ est un outil qui permet de faire tourner un programme orienté objet en parallèle sur plusieurs machines (sous Linux). C'est un logiciel libre qui étend le langage C++ et permet de transformer très simplement des classes C++ en des classes parallèles. Les objets parallèles générés peuvent alors tourner indépendamment sur plusieurs machines.

POP-C++ contient entre autre :
- Un parseur qui génère le code de ces objets parallèles
- Une gestion des threads pour permettre d'appeler des méthodes de manière synchrone/asynchrone ...
- Une gestion des protocoles de communication, en particulier les socket tcpip, afin de passer des structures de données complexes entre différents objets.
- ...

Si vous êtes intéressés ou désirez installer le programme, je vous invite à visiter le wiki de POP-C++ et en particulier la page tutoriel :

http://gridgroup.hefr.ch/popc/index.php/Quick_st art



Source

  • ////// Fichier POPCobject.ph
  • #ifndef POPCOBJECT_PH_
  • #define POPCOBJECT_PH_
  • #include <timer.h>
  • parclass POPCobject
  • {
  • classuid(1500);
  • public:
  • POPCobject(int newID, int wanted, int minp) @{od.power(wanted, minp);};
  • POPCobject(int newID, paroc_string machine) @{od.url(machine);};
  • ~POPCobject();
  • async seq void sendIDto([in] POPCobject &o);
  • sync conc int getID();
  • async conc void recAnID(int i);
  • sync mutex void wait(int sec);
  • private:
  • int iD;
  • Timer timer;
  • double initTime, computeTime;
  • };
  • #endif /*POPCOBJECT_PH_*/
  • ////// Fichier POPCobject.cc
  • #include "POPCobject.ph"
  • #include <unistd.h>
  • POPCobject::POPCobject(int newID, int wanted, int minp)
  • {
  • printf("POPCobject with ID=%d created (by JobMgr) on machine:%s\n", newID, (const char*)paroc_system::GetHost());
  • iD=newID;
  • }
  • POPCobject::POPCobject(int newID, paroc_string machine)
  • {
  • printf("POPCobject with ID=%d created on machine:%s\n", newID, (const char*)paroc_system::GetHost());
  • iD=newID;
  • }
  • POPCobject::~POPCobject()
  • {
  • printf("POPCobject:%d on machine:%s is being destroyed\n", iD, (const char*)paroc_system::GetHost());
  • iD=-1;
  • }
  • void POPCobject::sendIDto(POPCobject &o)
  • {
  • printf("POPCobject:%d on machine:%s is sending his iD to object:%d\n", iD, (const char*)paroc_system::GetHost(), o.getID());
  • o.recAnID(iD);
  • }
  • int POPCobject::getID()
  • {
  • return iD;
  • }
  • void POPCobject::recAnID(int i)
  • {
  • printf("POPCobject:%d on machine:%s is receiving id = %d\n", iD, (const char*)paroc_system::GetHost(), i);
  • }
  • void POPCobject::wait(int sec)
  • {
  • printf("POPCobject:%d on machine:%s is waiting %d sec.\n", iD, (const char*)paroc_system::GetHost(), sec);
  • sleep(sec);
  • }
  • @pack(POPCobject);
  • ////// Fichier main.cc
  • #include "POPCobject.ph"
  • int main(int argc, char** argv)
  • {
  • if (argc<2)
  • {
  • printf("Usage: parocrun objmap %s NbObjects machine1, machine2, .... \n", argv[0]);
  • return 0;
  • }
  • else
  • {
  • int nbObjects = atoi(argv[1]);
  • POPCobject** objects=new POPCobject*[nbObjects];
  • printf("\nSTART of %s program with %d objects\n", argv[0], nbObjects);
  • for (int i = 0; i<argc-2; i++){
  • if(argv[i+2][0]=='-'){
  • // objects created by job manager
  • objects[i]=new POPCobject(i+1, 60, 40);
  • }
  • else
  • {
  • // objects created on a given hostname
  • objects[i]=new POPCobject(i+1, argv[i+2]);
  • }
  • }
  • // The rest is created using hostname=localhost
  • for (int i = argc-2; i<nbObjects; i++) objects[i]=new POPCobject(i+1, (paroc_string)("localhost"));
  • // Send IDs to each other
  • for (int i=0; i<(nbObjects-1); i++) objects[i]->sendIDto(*(objects[i+1]));
  • objects[nbObjects-1]->sendIDto(*(objects[0]));
  • objects[nbObjects-1]->wait(2);
  • for (int i=0; i<nbObjects; i++) delete objects[i];
  • delete objects;
  • }
  • printf("\nEND of %s program\n", argv[0]);
  • return 0;
  • }
////// Fichier POPCobject.ph
#ifndef POPCOBJECT_PH_
#define POPCOBJECT_PH_

#include <timer.h>

parclass POPCobject
{
  classuid(1500);

  public:
    POPCobject(int newID, int wanted, int minp) @{od.power(wanted, minp);};
    POPCobject(int newID, paroc_string machine) @{od.url(machine);};
    ~POPCobject();
    
    async seq void sendIDto([in] POPCobject &o);
    sync conc int getID();
    async conc void recAnID(int i);
    sync mutex void wait(int sec);
  
  private:
    int iD;
    Timer timer;
    double initTime, computeTime;
    
};

#endif /*POPCOBJECT_PH_*/

////// Fichier POPCobject.cc

#include "POPCobject.ph"
#include <unistd.h>

POPCobject::POPCobject(int newID, int wanted, int minp)
{
  printf("POPCobject with ID=%d created (by JobMgr) on machine:%s\n", newID, (const char*)paroc_system::GetHost()); 
  iD=newID;
}

POPCobject::POPCobject(int newID, paroc_string machine)
{
  printf("POPCobject with ID=%d created on machine:%s\n", newID, (const char*)paroc_system::GetHost()); 
  iD=newID;
}

POPCobject::~POPCobject()
{
  printf("POPCobject:%d on machine:%s is being destroyed\n", iD, (const char*)paroc_system::GetHost()); 
  iD=-1;
}

void POPCobject::sendIDto(POPCobject &o)
{
  printf("POPCobject:%d on machine:%s is sending his iD to object:%d\n", iD, (const char*)paroc_system::GetHost(), o.getID()); 
  o.recAnID(iD);
}

int  POPCobject::getID()
{
  return iD;
}

void POPCobject::recAnID(int i)
{
  printf("POPCobject:%d on machine:%s is receiving id = %d\n", iD, (const char*)paroc_system::GetHost(), i);   
}

void POPCobject::wait(int sec)
{
  printf("POPCobject:%d on machine:%s is waiting %d sec.\n", iD, (const char*)paroc_system::GetHost(), sec);
  sleep(sec);
}

@pack(POPCobject);

////// Fichier main.cc
#include "POPCobject.ph"

int main(int argc, char** argv)

{
  if (argc<2)
  {
    printf("Usage: parocrun objmap %s NbObjects machine1, machine2, .... \n", argv[0]);
    return 0;
  }
  else
  {
    int nbObjects = atoi(argv[1]);
    POPCobject** objects=new POPCobject*[nbObjects]; 

    printf("\nSTART of %s program with %d objects\n", argv[0], nbObjects);

    for (int i = 0; i<argc-2; i++){ 
	  if(argv[i+2][0]=='-'){
		// objects created by job manager
		objects[i]=new POPCobject(i+1, 60, 40);	
	  }
	  else
	  {
		// objects created on a given hostname
		objects[i]=new POPCobject(i+1, argv[i+2]);
	  }
	}
    // The rest is created using hostname=localhost
    for (int i = argc-2; i<nbObjects; i++) objects[i]=new POPCobject(i+1, (paroc_string)("localhost"));
	    
    // Send IDs to each other
    for (int i=0; i<(nbObjects-1); i++) objects[i]->sendIDto(*(objects[i+1]));
    objects[nbObjects-1]->sendIDto(*(objects[0]));
    objects[nbObjects-1]->wait(2);
    for (int i=0; i<nbObjects; i++) delete objects[i];
    delete objects;
  }
  printf("\nEND of %s program\n", argv[0]);
  return 0;
} 

 Conclusion

L'output ressemble à cela :

parocrun object.map ./main 2 localhost 192.168.0.202

START of ./main program with 2 objects
POPCobject with ID=1 created on machine:160.98.20.78
POPCobject with ID=2 created on machine:192.168.0.202
POPCobject:1 on machine:160.98.20.78 is sending his iD to object:2
POPCobject:2 on machine:192.168.0.202 is receiving id = 1
POPCobject:2 on machine:192.168.0.202 is sending his iD to object:1
POPCobject:1 on machine:160.98.20.78 is receiving id = 2
POPCobject:2 on machine:192.168.0.202 is waiting 2 sec.

END of ./main program
POPCobject:1 on machine:160.98.20.78 is being destroyed
[objectmonitor.cc:82]Check parallel objects....0 object alive
/*------------------------------------------ -------------------------------------*/

Questions  et remarques sont les bienvenues !

PS:
Le code de POP-C++ ne tenait pas dans le .zip. Il faudra aller sur le site pour le télécharger. Je vous conseille vivement de prendre la version béta des sources de POP-C++. Le tutoriel ci-dessus explique l'installation.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   demoPOPC
    • main.ccTélécharger ce fichier [Réservé aux membres club]1 111 octets
    • MakefileTélécharger ce fichier [Réservé aux membres club]587 octets
    • POPCobject.ccTélécharger ce fichier [Réservé aux membres club]1 269 octets
    • POPCobject.phTélécharger ce fichier [Réservé aux membres club]566 octets
    • READMETélécharger ce fichier [Réservé aux membres club]518 octets

Télécharger le zip


 Sources de la même categorie

Source avec une capture COLORIMÈTRE NUMÉRIQUE LINUX par valchek
Source avec Zip TRAITEMENTS D'IMAGES AU FORMAT PGM AVEC LES ALGORITHMES DE C... par lemout
Source avec Zip ALGORITHME ACO INTERFACE GTK par RyBeN
Source avec Zip COMPRESSER SES SAUVEGARDES SMSBACKUPRESTORE (ANDROID) EN C A... par ThalLab
SIMPLE SCANNER DE PORTS par Vb6Malade

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture [DEV-C++] GESTION DU PORT PARALLÈLE par victorcoasne
Source avec Zip TCP SOCKET CONNECTION par f_l_a_s_h_b_a_c_k
Source avec Zip Source avec une capture [CLIENT TCP/IP AVEC L'API WIN 32] REQUETEUR V2.0 par gf18
Source avec Zip Source avec une capture SNIFFER TCP AVEC LES RAW SOCKETS par lilxam7
Source avec Zip COMMUNICATION CLIENT SERVEUR , TRANSMITION DE DONNÉES PAR TR... par Bug_Bug

Commentaires et avis

Commentaire de exar le 23/06/2009 14:26:41

Hello !
Je n'ai fait que survoler, mais je peux dire deux choses: code propre et sujet intéressant !  Je m'y attarderai plus tard...
Bonne continuation !

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Threads & Sockets appliqués au jeu [ par LA_Tupac ] Salut à tous les progueurs !!J'ouvre ce post pour receuillir des infos sur les techniques de prog reseau sous les jeux videos.Je bosse actuellement su Thread en GTK+ [ par Yunchi ] Bonjour,J'avais un projet gtk en C et il y'avait des threads dedans.J'aimerais savoir si il est possible de faire pareil avec GTK+Quand j'essaye de re Communication en C avec le Port Parallèle ou série [ par No limite ] Bonjour Je suis à la recherche d'info ou de tuto. pour la communication vers le port Parallèle ou série.Je début et je cherche a le faire en mode cons A la recherche d'un cour pour les sockets MFC (visual studio 2008) [ par youssef_sympas ] Bonjour tout le monde,Je cherche un cour pour la gestion des sockets avec les MFC pour visual studio 2008. Si vous avez un cour entre vos mains aidez Rapidité des systèmes temps réel [ par morpheux74 ] Bonjour,Voila je suis en ce moment sur un projet de traitement d'image qui doit fonctionner avec la meilleure performance possible.Je m'explique:J'ai Port Parallèle en Input, Mode SPP [ par laulau47 ] Bonjour,        Je tente de faire fonctionner en C un port parallèle en lecture (mode HighZ input). Le driver du port parallèle est un driver ECP, son sockets [ par coucoumiya ] bonjour, moi je travaille avec les sockets sous le procole de transmission TCP/IP. mon client est programmé avec Builderc++ sous windows. mon serveur aide sur les sockets en c [ par minuh ] salut à vous je tente d'écrire une application sur les sockets en c j'ai lu dans un tutoriel qu'il fallait utiliser la fonction WSAStartup() quand je Lecture du port parallèle sous XP par interruption externe [ par mfilleau ] Bonjour, Je réalise un système de commande domotique à l'aide d'un micro PC portable (tournant sous Windows XP) ne possèdant pas de port série RS232, acces à une machine distance avec les sockets [ par marwamouna ] Bonsoir tout le monde, J'ai un projet à faire qui consiste se connecter à une machine distante en utilisant les sockets sans aucun protocole prédéfin


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,655 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales