Esempio n. 1
0
	void cApplication::run(HINSTANCE hInstance)
	{
		initialize();
		initException();
		setDebugLeakFlag();	

		if (_getCore()->initialize(hInstance, _wndProc))
		{
			if (initApp())
			{
				MSG msg;
				while (!m_quit)
				{
					while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
					{					
						TranslateMessage(&msg);
						DispatchMessage(&msg);
					}

					procedure();
				}
			}
		}

		terminate();
	}
Esempio n. 2
0
Status VoltDBDriver::search(const ComplexQuery& query, vector<string>* files) {
  vector<voltdb::Parameter> param_types(3);
  param_types[0] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
  param_types[1] = voltdb::Parameter(voltdb::WIRE_TYPE_BIGINT);
  param_types[2] = voltdb::Parameter(voltdb::WIRE_TYPE_BIGINT);
  voltdb::Procedure procedure("SearchFile", param_types);
  auto index_names = query.get_names_of_range_queries();
  auto name = index_names[0];
  const auto range_query  = query.range_query(name);
  int64_t lower = std::numeric_limits<int64_t>::min();
  int64_t upper = std::numeric_limits<int64_t>::max();
  if (!range_query->lower.empty()) {
    lower = std::stol(range_query->lower);
  }
  if (!range_query->upper.empty()) {
    upper = std::stol(range_query->upper);
  }
  voltdb::ParameterSet* params = procedure.params();
  params->addString(name).addInt64(lower).addInt64(upper);
  auto response = client_->client.invoke(procedure);
  if (response.failure()) {
    LOG(ERROR) << "Failed to search files: " << response.toString();
  }
  auto count = response.results()[0].rowCount();
  files->reserve(count);
  auto iter = response.results()[0].iterator();
  for (int i = 0; i < count; i++) {
    auto row = iter.next();
    files->push_back(row.getString(0));
  }
  return Status::OK;
}
Esempio n. 3
0
time_t timegm(struct tm * utc)
{
    synchronized procedure(timeMutex);
    setUtcTZ(); //YUCK, but this is apparently standard practice where timegm is not available
    time_t simple = mktime(utc);
    setLocalTZ();
    return simple;
}
Esempio n. 4
0
struct tm * gmtime_r(time_t const * simple, struct tm * utc)
{
    synchronized procedure(timeMutex);
    struct tm * ts = gmtime(simple);
    if(!ts) return NULL;
    memcpy(utc, ts, sizeof(struct tm));
    return utc;
}
Esempio n. 5
0
struct tm * localtime_r(time_t const * simple, struct tm * local)
{
    synchronized procedure(timeMutex);
    struct tm * ts = localtime(simple);
    if(!ts) return NULL;
    memcpy(local, ts, sizeof(struct tm));
    return local;
}
Esempio n. 6
0
ASTNode* Parser::program()
{
	ASTNode* progNode = new ASTNode("Simple", PROGRAM, 0);

	ASTNode* procNode = procedure();

	progNode->joinChild(procNode);

	ASTNode* prevProcNode;

	while (isKeyword("procedure")) {
		prevProcNode = procNode;
		procNode = procedure();

		prevProcNode->joinNext(procNode);
	}

	return progNode;
}
Esempio n. 7
0
void Dispatcher::contextProcedure() {
  assert(GetCurrentThreadId() == threadId);
  for (;;) {
    assert(!spawningProcedures.empty());
    std::function<void()> procedure = std::move(spawningProcedures.front());
    spawningProcedures.pop();
    procedure();
    reusableContexts.push(GetCurrentFiber());
    dispatch();
  }
}
Esempio n. 8
0
unique_id_t RemoteDataSourceServer::addDataSource(SessionId session, IFvDataSource * ds)
{
    RemoteDataEntry * newEntry = new RemoteDataEntry;
    newEntry->id = ++nextId;
    newEntry->session = session;
    newEntry->ds.set(ds);
    newEntry->subscription = querySessionManager().subscribeSession(session, this);

    //MORE: Register the session so if it dies then we get notified.
    CriticalBlock procedure(cs);
    entries.append(*newEntry);
    return newEntry->id;
}
Esempio n. 9
0
std::array<std::string, 2> Message::procedure_split(void) const {
    auto proc = procedure();
    auto pos = proc.find('@');
    if (pos>=0){
        return {
            proc.substr(0,pos),
            proc.substr(pos+1)
        };
    } else {
        return {
            proc,
            ""
        };
    }
}
Esempio n. 10
0
float Simulation::run_conf(std::vector<float> config, const float step, const int step_limit){

    while(x < step_limit) {
        if(!headless){
            if(v->done()){ //If user presses escape in window
                exit(EXIT_SUCCESS); //abort everything including sferes-backend
            }
        }
        procedure(config, step);
    }

    Eigen::Vector3d pos = rob->pos();
    //std::cout << "Fitness: " << -pos(0) << std::endl;
    return -pos(0);
}
Esempio n. 11
0
Status VoltDBDriver::import(const vector<string>& files) {
  vector<voltdb::Parameter> param_types(2);
  param_types[0] = voltdb::Parameter(voltdb::WIRE_TYPE_BIGINT);
  param_types[1] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
  voltdb::Procedure procedure("FILE_META.insert", param_types);
  for (const auto& file : files) {
    voltdb::ParameterSet* params = procedure.params();
    auto hash = PathUtil::path_to_hash(file);
    params->addInt64(hash).addString(file);
    auto response = client_->client.invoke(procedure);
    if (response.failure()) {
      LOG(ERROR) << "Failed to insert file: " << response.toString();
    }
  }
  return Status::OK;
}
Esempio n. 12
0
ByteArray ConnectorMySQL::Call(const ByteArray &command, ErrorCode &error_code)
{
	if (IsConnected())
	{
		mysql_real_query(&mysql_, command.data(), command.size());
		int error = mysql_errno(&mysql_);
		if (error != 0)
		{
			error_code.SetError(error, mysql_error(&mysql_));
			return ByteArray();
		}

		ByteArray bytes;
		MYSQL_RES *sql_result = mysql_store_result(&mysql_);
		if (sql_result != nullptr)
		{
			mysql_stuff::Serialize(sql_result, &bytes);
			mysql_free_result(sql_result);
		}
		else
		{
			ProcedureMySQL procedure(command);
			if (procedure.HasVariable())
			{
				ByteArray query_variable = procedure.QueryVariableValue();
				mysql_real_query(&mysql_, query_variable.data(), query_variable.size());
				int error = mysql_errno(&mysql_);
				if (error != 0)
				{
					error_code.SetError(error, mysql_error(&mysql_));
					return ByteArray();
				}

				MYSQL_RES *sql_result = mysql_store_result(&mysql_);
				mysql_stuff::Serialize(sql_result, &bytes);
				mysql_free_result(sql_result);
			}
		}
		return bytes;
	}
	else
	{
		throw NotConnected();
	}
}
Esempio n. 13
0
void     Courier::Programs::Program::addEntry(quint32 programCode, QString programName, quint16 versionCode, quint16 procedureCode, QString procedureName) {
	if (!programMap.contains(programCode)) {
		Courier::Programs::Program program(programCode, programName);
		programMap[programCode] = program;
	}
	Courier::Programs::Program& program = programMap[programCode];
	if (!program.contains(versionCode)) {
		program.addVersion(versionCode);
	}
	Courier::Programs::Version& version = program.versionMap[versionCode];
	if (version.contains(procedureCode)) {
        logger.error("Unexpected procedureCode = %d", procedureCode);
        COURIER_FATAL_ERROR();
	} else {
		Procedure procedure(procedureCode, procedureName);
		version.addPocedure(procedure);
	}
}
Esempio n. 14
0
int main()
{
    srand(time(NULL));
    printf("C'est parti :\n");

// Initialisation du options.ini
    int nbjours=10000, periode_herbe=1, intensite_herbe=5000 ,catastrophe=0;
    // Catastrophe : 0 si non présentes, 1 si présentes.
    // Periode d'herbe : temps avant renouvellement
    // Intensité d'herbe, quantité d'herbe apportée à chaque renouvellement.



// Démarrage de l'etude
    procedure(nbjours, periode_herbe, intensite_herbe, catastrophe);

    printf("\nTermine !\n\n");
    system("PAUSE");
    return 0;
}
Esempio n. 15
0
Status VoltDBDriver::insert(const RecordVector& records) {
  // Insert into Big Single Index Table.
  vector<voltdb::Parameter> param_types(3);
  param_types[0] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
  param_types[1] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
  param_types[2] = voltdb::Parameter(voltdb::WIRE_TYPE_BIGINT);
  voltdb::Procedure procedure("BIG_INDEX_TABLE_UINT64.insert", param_types);
  voltdb::ParameterSet* params = procedure.params();

  boost::shared_ptr<EmptyCallback> callback(new EmptyCallback);
  for (const auto& record : records) {
    // TODO(eddyxu): batch insert.
    string file_path, index_name;
    uint64_t key;
    std::tie(file_path, index_name, key) = record;
    params->addString(file_path).addString(index_name).addInt64(key);
    client_->client.invoke(procedure, callback);
  }
  while (!client_->client.drain()) {}
  return Status::OK;
}
Esempio n. 16
0
Cell eval(Cell exp, Cell env) {

    if (is_self_evaluating(exp)) {
        return exp;
    } else if (is_atom(exp)) {
        return lookup(exp, env);
    } else if (is_tagged(exp, atom("define"))) {
        return define(car(cdr(exp)), eval(car(cdr(cdr(exp))), env), env);
    } else if (is_tagged(exp, atom("set!"))) {
        return set(car(cdr(exp)), eval(car(cdr(cdr(exp))), env), env);
    } else if (is_tagged(exp, atom("if"))) {
        Cell cond = eval(car(cdr(exp)), env);
        if (is_atom(cond) && is_eq(cond, atom("#f"))) {
           exp = car(cdr(cdr(cdr(exp))));
        } else {
           exp = car(cdr(cdr(exp)));
        }
        return eval(exp, env);
    } else if (is_tagged(exp, atom("vau"))) {
        return procedure(exp, env);
    } else if (is_pair(exp)) {
        Cell proc = eval(car(exp), env);
        if (is_primitive(proc)) {
            return (proc->primitive)(eval_operands(cdr(exp), env));
        } else if (is_procedure(proc)) {
            Cell src = car(proc);
            Cell e = car(cdr(cdr(src)));
            Cell para = cons(e, cons(car(cdr(src)), null));
            Cell args = cons(env, cons(cdr(exp), null));
            Cell body = car(cdr(cdr(cdr(src))));
            return eval(body, extend_env(para, args, cdr(proc)));
        }
    }
    fprintf(stderr, "eval illegal state\n");
    return atom("#<void>");
}
Esempio n. 17
0
int main(int argc, char *argv[])
{

#ifdef ON_DEMAND
    int junk = 0;
#endif

#ifdef MODULE
    int new_sock;
#endif
    /* return status of MPI functions */
    MPI_Status status;
    /* number of pixels of the image */
    int dim = 0;
    /* dimensions of the image */
    int width, height;
    /* image count */
    int num_image = 0, num_worker;
    /* time variables */
    struct timeval tv1, tv2;

    /* fits of Gaussian */
    double fit[DIM_FIT];
    /* image representing Gaussian fit */
    unsigned char *image = NULL;

    /* indexes */
    int i = 0;

    /* Gauss matrix and vector have contiguous space in memory */
    double *data =
	(double *) malloc(sizeof(double) * DIM_FIT * (DIM_FIT + 1));
    gsl_matrix_view matrice =
	gsl_matrix_view_array(data, DIM_FIT, DIM_FIT);
    gsl_vector_view vettore =
	gsl_vector_view_array(data + (DIM_FIT * DIM_FIT), DIM_FIT);


	/*********************************************************************
	 INIT
	 *********************************************************************/

    srand(time(NULL));
    /* in order to recover from an error */
    gsl_set_error_handler_off();

    /* Initialize of MPI */
    MPI_Init(&argc, &argv);

    /* check the input parameters */
    if (argc != 3) {
	fprintf(stderr, "Invalid number of parameters\n");
	MPI_Abort(MPI_COMM_WORLD, MPI_ERR_ARG);
    }

    /* Every process takes the own rank */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Total number of processes */
    MPI_Comm_size(MPI_COMM_WORLD, &p);

    /* check for the number of processes */
    if (p <= PS) {
	fprintf(stderr, "Number of process not valid\n");
	MPI_Abort(MPI_COMM_WORLD, MPI_ERR_OP);
    }

    /* number of workers */
    num_worker = p - PS;

    /* first image is used to estimate gaussian parameters */
    if (my_rank == EMITTER) {

#ifdef DEBUG
	printf("Emitter with rank %d\n", my_rank);
#endif

#ifdef MODULE
	new_sock = Connect();

	if (Read(new_sock, &width, sizeof(int)) < 0)
	    error("Error reading the integers");
	if (Read(new_sock, &height, sizeof(int)) < 0)
	    error("Error reading the integers");

	dim = width * height;
	image = (unsigned char *) malloc(dim);
	/* read from the socket */
	if (Read(new_sock, image, dim) < 0)
	    error("Error reading from socket");
#else
	/* an image representing the gaussian is created and returned
	   as a unsigned char matrix */
	width = atoi(argv[1]);
	height = atoi(argv[2]);
	image = createImage(width, height);
#endif
	/* parameters of the gaussian are estimated */
	initialization(image, width, height, fit);
    }

    /* broadcast data of the image */
    MPI_Bcast(&width, 1, MPI_INT, EMITTER, MPI_COMM_WORLD);
    MPI_Bcast(&height, 1, MPI_INT, EMITTER, MPI_COMM_WORLD);
    MPI_Bcast(&fit, DIM_FIT, MPI_DOUBLE, EMITTER, MPI_COMM_WORLD);

    /* dimension of the image */
    dim = width * height;

	/*********************************************************************
	 EMITTER
	 *********************************************************************/

    if (my_rank == EMITTER) {

	for (i = 0; i < STREAMLENGTH; i++) {

#ifdef DEBUG
	    printf("Emitter sends image %d\n", i);
#endif

	    /* send to the workers the first images */
	    if (i < num_worker) {
		/*      first image is sent to worker */
		MPI_Send(image, dim, MPI_UNSIGNED_CHAR, i + PS, IMAGE,
			 MPI_COMM_WORLD);
	    } else {

#ifdef ON_DEMAND		/* ON_DEMAND */

		/* receive the request */
		MPI_Recv(&junk, 1, MPI_INT, MPI_ANY_SOURCE, REQUEST,
			 MPI_COMM_WORLD, &status);

		/* send the image */
		MPI_Send(image, dim, MPI_UNSIGNED_CHAR, status.MPI_SOURCE,
			 IMAGE, MPI_COMM_WORLD);

#else				/* NOT ON_DEMAND */
		MPI_Send(image, dim, MPI_UNSIGNED_CHAR,
			 i % num_worker + PS, IMAGE, MPI_COMM_WORLD);
#endif
	    }
#ifdef MODULE
	    if (i < STREAMLENGTH - 1) {
		/* read from the socket */
		if (Read(new_sock, image, dim) < 0)
		    error("Error reading from socket");
	    }
#endif

	}

	/* send the termination message */
	for (i = PS; i < p; i++)
	    MPI_Send(NULL, 0, MPI_INT, i, TERMINATION, MPI_COMM_WORLD);


		/*********************************************************************
		 COLLECTOR
		 *********************************************************************/

    } else if (my_rank == COLLECTOR) {
#ifdef DEBUG
	printf("Collector with rank %d\n", my_rank);
#endif

	/* take the time */
	gettimeofday(&tv1, NULL);
	i = 0;
	while (i < num_worker) {

	    MPI_Recv(fit, DIM_FIT, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG,
		     MPI_COMM_WORLD, &status);

	    if (status.MPI_TAG == TERMINATION) {
#ifdef DEBUG
		printf("Worker %d has ended\n", status.MPI_SOURCE);
#endif
		i++;
	    } else {
		num_image++;
#ifdef DEBUG
		/* PRINTOUT OF THE CURRENT RESULT */
		printf
		    ("Image %d from worker %d: %f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
		     num_image, status.MPI_SOURCE, fit[PAR_A], fit[PAR_X],
		     fit[PAR_Y], fit[PAR_SX], fit[PAR_SY], fit[PAR_a],
		     fit[PAR_b], fit[PAR_c]);
#endif
	    }

	}

	/* take the time */
	gettimeofday(&tv2, NULL);

	/* print parallelism degree, data size and the completion time */
	printf("%d\t%d\t%ld\n", p, dim,
	       (tv2.tv_sec - tv1.tv_sec) * 1000000 + tv2.tv_usec -
	       tv1.tv_usec);

		/*********************************************************************
		 WORKER
		 *********************************************************************/

    } else {
#ifdef DEBUG
	printf("Worker with rank %d\n", my_rank);
#endif

	/* calculate number of pixels and initialize buffers for the fit */
	dim = width * height;
	initBuffers(dim);
	image = (unsigned char *) malloc(dim);

	while (TRUE) {
#ifdef ON_DEMAND
	    /* send the request */
	    MPI_Send(&dim, 1, MPI_INT, EMITTER, REQUEST, MPI_COMM_WORLD);
#endif
	    /* blocking test of incoming message */
	    MPI_Probe(EMITTER, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
	    /* workers ends if receives termination message */
	    if (status.MPI_TAG == TERMINATION) {
#ifdef DEBUG
		printf("Worker %d ends after %d images\n", my_rank,
		       num_image);
#endif
		/* last result is sent to the collector with a different TAG */
		MPI_Send(fit, DIM_FIT, MPI_DOUBLE, COLLECTOR, TERMINATION,
			 MPI_COMM_WORLD);
		freeBuffers();
		break;
	    }

	    /* receive the image from the emitter */
	    MPI_Recv(image, dim, MPI_UNSIGNED_CHAR, EMITTER, IMAGE,
		     MPI_COMM_WORLD, &status);
	    /* calculation of the Gauss matrix and vector */
	    procedure(image, width, height, fit, matrice, vettore, 0);
	    /* solve the system and adjust the fit vector */
	    postProcedure(matrice, vettore, fit);
	    /* send the result to the collector */
	    MPI_Send(fit, DIM_FIT, MPI_DOUBLE, COLLECTOR, RESULTS,
		     MPI_COMM_WORLD);
	}
    }

    /* Finalize of MPI */
    MPI_Finalize();

    return 0;
}
Esempio n. 18
0
time_t timelocal(struct tm * local)
{
    synchronized procedure(timeMutex);
    return mktime(local); //mktime is more common (but less descriptive) name for timelocal
}
Esempio n. 19
0
static void RunCommand(const char* command) {
    LOG_DEBUG("Run %s", command);
    strcpy(str_cmdline, command);
    CHECK2_GE(procedure(&tree), 0, "error: %s", str_error);
}
Esempio n. 20
0
int main(int argc, char **argv) {
    /*
     * Instantiate a client and connect to the database.
     */
    voltdb::ClientConfig clientConfig("program", "password");
    voltdb::Client client = voltdb::Client::create();
    client.createConnection("localhost");

    /*
     * Describe the stored procedure to be invoked
     */
    std::vector<voltdb::Parameter> parameterTypes(3);
    parameterTypes[0] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
    parameterTypes[1] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
    parameterTypes[2] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING);
    voltdb::Procedure procedure("Insert", parameterTypes);

    boost::shared_ptr<CountingCallback> callback(new CountingCallback(5));

    /*
     * Load the database.
     */
    voltdb::ParameterSet* params = procedure.params();
    params->addString("English").addString("Hello").addString("World");
    client.invoke(procedure, callback);

    params->addString("French").addString("Bonjour").addString("Monde");
    client.invoke(procedure, callback);

    params->addString("Spanish").addString("Hola").addString("Mundo");
    client.invoke(procedure, callback);

    params->addString("Danish").addString("Hej").addString("Verden");
    client.invoke(procedure, callback);

    params->addString("Italian").addString("Ciao").addString("Mondo");
    client.invoke(procedure, callback);

    /*
     * Run the client event loop to poll the network and invoke callbacks.
     * The event loop will break on an error or when a callback returns true
     */
    client.run();

    /*
     * Describe procedure to retrieve message
     */
    parameterTypes.resize( 1, voltdb::Parameter(voltdb::WIRE_TYPE_STRING));
    voltdb::Procedure selectProc("Select", parameterTypes);

    /*
     * Retrieve the message
     */
    selectProc.params()->addString("Spanish");
    client.invoke(selectProc, boost::shared_ptr<PrintingCallback>(new PrintingCallback()));

    /*
     * Invoke event loop
     */
    client.run();

    return 0;
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
	
    /* pixels per worker */
    int ppw = 0;
	
	/* number of workers */
	int num_worker;
	
	/* pixels of the entire image */
	int dim;
	
    /* dimension of the entire image */
    int width,height;
	
    /* time variables */
    struct timeval tv1, tv2;
	
    /* Dimension of the partitioned image */
    int dimx = 0, dimy = 0;
	
    /* fit of the Gaussian */
    double fit[DIM_FIT];
	
    /* image representing Gaussian fit */
    unsigned char *image = NULL;
	
#ifdef PADDED
	/* buffer for the padded image */
	unsigned char *padded = NULL;
#endif	

#ifdef MODULE
	/* socket for the camera */
	int new_sock;
#endif
	
    /* local partition of the image*/
    unsigned char *partition;
	
	/* size of reduce buffer */
	int buffer_size = DIM_FIT * (DIM_FIT + 1);
	
    /* indexes */
    int i = 0;
	
    /* buffer for fit procedure */
    double *data = (double *) malloc( sizeof(double) * buffer_size );
    gsl_matrix_view matrice = gsl_matrix_view_array(data, DIM_FIT, DIM_FIT);
    gsl_vector_view vettore = gsl_vector_view_array(data + (DIM_FIT * DIM_FIT), DIM_FIT);
	
    /* output buffer of reduce */
    double *ret = (double *) malloc( sizeof(double) * buffer_size );
    gsl_matrix_view r_matrice = gsl_matrix_view_array(ret, DIM_FIT, DIM_FIT);
    gsl_vector_view r_vettore = gsl_vector_view_array(ret + (DIM_FIT * DIM_FIT), DIM_FIT);
	
	/*********************************************************************
	 INIT
	 *********************************************************************/	
	
	srand(time(NULL));
	/* in order to recover from an error */
	gsl_set_error_handler_off();
	
    /* Initialize of MPI */
    MPI_Init(&argc, &argv);
	
	/* Check the input parameters */
    if (argc != 3) {
		fprintf(stderr, "Invalid number of parameters: %d\n",argc);
		MPI_Abort(MPI_COMM_WORLD,MPI_ERR_ARG);
    }
    
    /* Every process takes their own rank */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
	
    /* Total number of processes */
    MPI_Comm_size(MPI_COMM_WORLD, &p);
	
	/* Number of workers */ 
	num_worker = p - PS;
	
    if (my_rank == EMITTER) {
#if DEBUG
		printf("Emitter with rank %d\n", my_rank);
#endif
		
#ifdef MODULE
		new_sock = Connect();
		
		if (Read(new_sock, &width, sizeof(int)) < 0)
			error("Error reading the integers");
		if (Read(new_sock, &height, sizeof(int)) < 0)
			error("Error reading the integers");
		
		dim = width * height;
		image = (unsigned char *) malloc (dim);
		/* read from the socket */
		if (Read(new_sock, image, dim) < 0)
			error("Error reading from socket");
#else		
		/* an image representing the gaussian is created and returned
		 as a unsigned char matrix */
		width = atoi(argv[1]);
		height = atoi(argv[2]);
		/* y dimension of the image is adjusted (if needed) */
		while (height % num_worker != 0) height++;
		/* image is created */
		image = createImage(width, height);
#endif		
		/* parameters of the gaussian are estimated */
		initialization(image, width, height,fit);
		
#if DEBUG
		printf("Emitter survived init\n");
#endif	
		
    } 
	
	/* broadcast data of the image */
	MPI_Bcast(&width,1,MPI_INT,EMITTER,MPI_COMM_WORLD);
	MPI_Bcast(&height,1,MPI_INT,EMITTER,MPI_COMM_WORLD);
	MPI_Bcast(&fit,DIM_FIT,MPI_DOUBLE,EMITTER,MPI_COMM_WORLD);
	
	/* dimension of the local partition are determined and relative buffers
	 are initialized */  
	
	dim = width * height;
	dimx = width;
	dimy = height / num_worker;
    ppw = dimx * dimy;
    partition = (unsigned char *) malloc(sizeof(unsigned char) * ppw);
    initBuffers(ppw);
	
    /* if I am the emitter I take the time */
    if (my_rank == EMITTER)
		gettimeofday(&tv1, NULL);
	
#ifdef PADDED
	if (my_rank == EMITTER){
		padded =(unsigned char*) malloc(sizeof(unsigned char) * ppw * p);
		for (i=0; i < dim; i++){
			padded[i + ppw] = image[i];
		}
		for(i=0;i<DIM_FIT * (DIM_FIT + 1);i++){
			ret[i] = 0;
		}		
		free(image);
		image = padded;
	}	
#endif	
	
    /*********************************************************************
	 LOOP on ELEMENTS
     *********************************************************************/		
	
    for (i = 0; i < STREAMLENGTH; i++) {
		
		/* the emitter executes the scatter */
		MPI_Scatter(image, ppw, MPI_UNSIGNED_CHAR, partition, ppw, MPI_UNSIGNED_CHAR, EMITTER, MPI_COMM_WORLD);
		/* execute the procedure over my partition */		
		if(my_rank >= PS){
			procedure(partition, dimx, dimy , fit, matrice, vettore, dimy*(my_rank-PS));
		}
	
		/* execute the reduce of matrix and vector */
		MPI_Reduce(data, ret, buffer_size , MPI_DOUBLE, MPI_SUM, EMITTER, MPI_COMM_WORLD);
		
		if (my_rank == EMITTER) {
			/* adjust fit results */			
			postProcedure(r_matrice,r_vettore,fit);	
		}
		
		/* broadcast of the result */
		MPI_Bcast(fit, DIM_FIT, MPI_DOUBLE, EMITTER, MPI_COMM_WORLD);
		
#ifdef DEBUG
		if (my_rank == EMITTER) {
			printf("Image %d: %f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", i, fit[PAR_A], fit[PAR_X],
				   fit[PAR_Y], fit[PAR_SX], fit[PAR_SY], fit[PAR_a], fit[PAR_b], fit[PAR_c]);
		}
#endif
		
#ifdef MODULE
		if (my_rank == EMITTER && i < STREAMLENGTH - 1) {		
			/* new image is stored in buffer image of the emitter*/
#ifdef PADDED
			if (Read(new_sock, image + ppw, dim) < 0)
				error("Error reading from socket");
#else			
			if (Read(new_sock, image, dim) < 0)
				error("Error reading from socket");
#endif				
		}
#endif			
    }
	
    if (my_rank == EMITTER) {
		gettimeofday(&tv2, NULL);
		/* print the parallelism degree, data size and the completion time */
		printf("%d\t%d\t%ld\n", p, dim,  (tv2.tv_sec - tv1.tv_sec) * 1000000 + tv2.tv_usec - tv1.tv_usec);
    }
    
	freeBuffers();
    /* Finalize of MPI */
    MPI_Finalize();
    
    return 0;
}
Esempio n. 22
0
int main(int argc, char **argv) {
  // FLAGS
  int c;
  std::string input;
  std::string centFile = "centroids.txt";
  std::string clustersFile = "clusters.txt";
  float identity = 0.5;
  bool flagIn = 0;
  bool flagCent = 0;
  bool flagClu = 0;
    
  while (1) {
    int this_option_optind = optind ? optind : 1;
        
    int option_index = 0;
    static struct option long_options[] = {
        {"in",  required_argument, 0, 'i'},
        {"dataset",     required_argument, 0,  'd' },
        {"clusters",  required_argument, 0,  'c' },   
        {"identity",    required_argument, 0,  'p' },
        {0,         0,                 0,  0 }
    };

    c = getopt_long(argc, argv, "i:o:c:p:",
                 long_options, &option_index);
        
    if (c == -1)
        break;

    switch (c) {
      case 'i':
        input.assign(optarg);
        flagIn = 1;
        break;
      case 'd':
       	centFile.assign(optarg);
       	flagCent = 1;
       	break;
      case 'c':
        clustersFile.assign(optarg);
        flagClu = 1;
        break;
      case 'p':
        identity = atof(optarg);
        break;
      case '?':
        break;
      }
  }

  if ((flagIn & flagCent & flagCent) == 0) {
    std::cout << "Please provide input sequence (--in), dataset" 
        << " (--dataset) and clusters (--clusters) ";
	exit(0);
  }

  // Create working directory
  char temp[] = "tmpXXXXXX";
  char *f = mkdtemp(temp);
  if (f == NULL) {
  	std::cout << "Failed";
  	exit(0);
  }

  // Searching for a sequence
  procedure(input, centFile, clustersFile, identity, temp);

  // Deleting working directory and files
  std::ostringstream oss;
  oss << "rm " << temp << "/*";
  system(oss.str().c_str());

  oss.str("");
  oss.clear();
  oss << "rmdir " << temp;
  system(oss.str().c_str());
  return 0;
}