Commit 0323caf1 authored by Thomas Jund's avatar Thomas Jund
Browse files

ajout de fichier (sauvegarde) pr le rendu

parent 5d17a127
tjund@sashimis.u-strasbg.fr
tjund@sashimis.u-strasbg.fr
tjund@sashimis.u-strasbg.fr
jund@elvis.u-strasbg.fr
jund@elvis.u-strasbg.fr
jund@elvis.u-strasbg.fr
jund@cgogn.u-strasbg.fr
jund@cgogn.u-strasbg.fr
jund@cgogn.u-strasbg.fr
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <iomanip>
#include <wait.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <algorithm>
using namespace std;
int getdir (string dir, std::vector<string> &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
if(string(dirp->d_name).find(".pov")!=string::npos) {
files.push_back(string(dirp->d_name));
}
}
closedir(dp);
return 0;
}
main()
{
std::vector<std::string> files;
std::vector<std::string> hosts;
std::vector<bool> hosts_b;
std::ifstream infile ("listeMachine.txt", std::ios_base::in);
std::string line;
while (getline(infile, line))
{
// add line to vector
hosts.push_back (line);
}
for(int i=0;i<hosts.size();++i)
hosts_b.push_back(false);
// int max=1000;
int used = 0;
getdir(".",files);
sort(files.begin(),files.end());
int i=0;
std::cout << "STARTING" << std::endl;
while(i<files.size())
{
std::cout << files[i] << std::endl;
std::cout << getpid() << " i = " << i << std::endl;
for(int k=0;k<hosts.size();++k)
std::cout << hosts[k] << " " << hosts_b[k] << std::endl;
if(used<hosts.size())
{
int use;
for(int j=0;j<hosts.size();j++)
if(!hosts_b[j])
{
use = j;
hosts_b[j] = true;
std::cout << "utilisation : " << hosts[j] << " " << hosts_b[j] << std::endl;
break;
}
if(!fork())
{
std::cout << "iam " << hosts[use] << std::endl;
// for(int p=0;p<10;++p)
// {
// sleep(rand()/(float(RAND_MAX)+1));
// }
std::ostringstream oss;
oss << "scp " << files[i] << " " << hosts[use] << ":~/ && ";
oss << "ssh " << hosts[use] << " 'nice -19 ./povray-3.6/povray -W800 -H600 +Q9 +A +AM2 -J +L./povray-3.6/include " << files[i] << "'";
std::cout << "ouep : " << oss.str() << std::endl;
std::string chaine = oss.str();
int ret = system(chaine.c_str());
exit(use);
}
i++;
used++;
}
else
{
std::cout << "waiting" << std::endl;
int stat_val;
wait(&stat_val);
std::cout << "stat_val : " << WEXITSTATUS(stat_val) << std::endl;
hosts_b[WEXITSTATUS(stat_val)]=false;
used--;
}
}
std::cout << "FINISSHHHHHED" << std::endl;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment