Example #1
0
vespalib::string
FlushEngine::flushNextTarget(const vespalib::string & name)
{
    std::pair<FlushContext::List,bool> lst = getSortedTargetList();
    if (lst.second) {
        // Everything returned from a priority strategy should be flushed
        flushAll(lst.first);
        _executor.sync();
        prune();
        std::lock_guard<std::mutex> strategyGuard(_strategyLock);
        _priorityStrategy.reset();
        _strategyCond.notify_all();
        return "";
    }
    if (lst.first.empty()) {
        LOG(debug, "No target to flush.");
        return "";
    }
    FlushContext::SP ctx = initNextFlush(lst.first);
    if ( ! ctx) {
        LOG(debug, "All targets refused to flush.");
        return "";
    }
    if ( name == ctx->getName()) {
        LOG(info, "The same target %s out of %ld has been asked to flush again. "
                  "This might indicate flush logic flaw so I will wait 100 ms before doing it.",
                  name.c_str(), lst.first.size());
        std::this_thread::sleep_for(100ms);
    }
    _executor.execute(std::make_unique<FlushTask>(initFlush(*ctx), *this, ctx));
    return ctx->getName();
}
Example #2
0
void* sender_caputils(struct thread_data* td, void *ptr){
	send_proc_t* proc = (send_proc_t*)ptr;    /* Extract the parameters that we got from our master, i.e. parent process.. */
	const int nics = proc->nics;              /* The number of active CIs */

	logmsg(stderr, SENDER, "Initializing. There are %d captures.\n", nics);

	/* initialize timestamp */
	{
		struct timespec tmp;
		clock_gettime(CLOCK_REALTIME, &tmp);
		for ( int i = 0; i < MAX_FILTERS; i++ ){
			MAsd[i].last_sent = tmp;
		}
	}

	/* unlock main thread */
	thread_init_finished(td, 0);

	/* sender loop */
	while( terminateThreads == 0 ){
		flush_senders();
		fill_senders(proc);
	}

	logmsg(verbose, SENDER, "Flushing sendbuffers.\n");
	flushAll(1);

	logmsg(stderr, SENDER, "Finished.\n");
	return(NULL) ;
}
Example #3
0
void HardwareSerial::begin(unsigned long baud)
{
	baudRate = baud;

	/* Set the UART to interrupt whenever the TX FIFO is almost empty or
	 * when any character is received. */
	//MAP_UARTFIFOLevelSet(UART_BASE, UART_FIFO_TX7_8, UART_FIFO_RX7_8);

	/* Initialize the UART. */
//	UARTClockSourceSet(UART_BASE, UART_CLOCK_SYSTEM);
	MAP_PRCMPeripheralReset(g_ulUARTPeriph[uartModule]);

	MAP_PRCMPeripheralClkEnable(g_ulUARTPeriph[uartModule], PRCM_RUN_MODE_CLK);

	MAP_PinTypeUART(g_ulUARTConfig[uartModule][0], PIN_MODE_3);
	MAP_PinTypeUART(g_ulUARTConfig[uartModule][1], PIN_MODE_3);

	MAP_UARTConfigSetExpClk(UART_BASE, 80000000, baudRate,
				(UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
				UART_CONFIG_WLEN_8));

	flushAll();
	MAP_IntEnable(g_ulUARTInt[uartModule]);

	/* Enable the UART operation. */
	MAP_UARTEnable(UART_BASE);

	MAP_UARTIntEnable(UART_BASE, UART_INT_RT | UART_INT_TX);
}
Example #4
0
static void fill_senders(const send_proc_t* proc){
	static const size_t header_size = sizeof(struct cap_header) + sizeof(struct sendhead);

	const int oldest = oldest_packet(proc->nics, proc->semaphore);

	/* couldn't find a packet, gave up waiting. we are probably terminating. */
	if ( oldest == -1 ){
		return;
	}

	/* timeout, flush all buffers */
	if( oldest == -2 ){
		flushAll(0);
		return;
	}

	struct CI* CI = &_CI[oldest];
	struct write_header* whead = CI_packet(CI, CI->readpos);
	struct cap_header* head    = whead->cp;
	struct destination* dst    = &MAsd[whead->destination];

	/* calculate size of sendbuffer and compare with MTU */
	const size_t payload_size = dst->buffer.end - dst->buffer.begin;
	const int larger_mtu = payload_size + head->caplen + header_size > MPinfo->MTU;

	/* if the current packet doesn't fit flush first */
	if ( larger_mtu ){
		assert(payload_size > 0 && dst->sendcount > 0 && "packet didn't fit into frame but frame is empty");
		send_packet(dst);
	}

	/* copy packet into buffer */
	copy_to_sendbuffer(dst, whead, CI);
}
Example #5
0
template <typename ElemType> nano_time_t
DotPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];

    DataType type;
    type = ( typeid(ElemType) == typeid(float))? TYPE_FLOAT:( typeid(ElemType) == typeid(double))? TYPE_DOUBLE:
										( typeid(ElemType) == typeid(FloatComplex))? TYPE_COMPLEX_FLOAT: TYPE_COMPLEX_DOUBLE;

    event = NULL;
    clFinish( queue);
    time = getCurrentTime();

#define TIMING
#ifdef TIMING
    int iter = 100;
    for ( int i=1; i <= iter; i++)
    {
#endif

        status = (cl_int)clMath::clblas::dot( type, params_.N, mobjDP_, params_.offa, mobjX_, params_.offBX, params_.incx,
                             mobjY_, params_.offCY, params_.incy, scratchBuff, 1, &queue, 0, NULL, &event);
        if (status != CL_SUCCESS) {
            cerr << "The CLBLAS DOT function failed, status = " <<
                    status << endl;

            return NANOTIME_ERR;
        }
#ifdef TIMING
    } // iter loop
    clFinish( queue);
    time = getCurrentTime() - time;
    time /= iter;
#else

    status = flushAll(1, &queue);
    if (status != CL_SUCCESS) {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    time = getCurrentTime();
    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS) {
        time = getCurrentTime() - time;
    }
    else {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }
#endif
    return time;
}
Example #6
0
template <typename ElemType> nano_time_t
Syr2kPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];

    status = clEnqueueWriteBuffer(queue, mobjC_, CL_TRUE, 0,
                                  params_.rowsC * params_.columnsC *
                                  sizeof(ElemType), backC_, 0, NULL, &event);
    if (status != CL_SUCCESS) {
        cerr << "Matrix C buffer object enqueuing error, status = " <<
                 status << endl;

        return NANOTIME_ERR;
    }

    status = clWaitForEvents(1, &event);
    if (status != CL_SUCCESS) {
        cout << "Wait on event failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

    event = NULL;
    status = (cl_int)clMath::clblas::syr2k(params_.order,
        params_.uplo, params_.transA, params_.N, params_.K, alpha_,
        mobjA_, params_.offA, params_.lda, mobjB_, params_.offBX, params_.ldb,
        beta_, mobjC_, params_.offCY, params_.ldc, 1, &queue, 0, NULL, &event);
    if (status != CL_SUCCESS) {
        cerr << "The CLBLAS SYR2K function failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }
    status = flushAll(1, &queue);
    if (status != CL_SUCCESS) {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    time = getCurrentTime();
    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS) {
        time = getCurrentTime() - time;
    }
    else {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }

    return time;
}
Example #7
0
void HardwareSerial::end()
{
	unsigned long ulInt = MAP_IntMasterDisable();

	flushAll();

	/* If interrupts were enabled when we turned them off, 
	 * turn them back on again. */
	if(!ulInt) {
		MAP_IntMasterEnable();
	}

	MAP_UARTIntDisable(UART_BASE, UART_INT_RT | UART_INT_TX);
	MAP_UARTIntUnregister(UART_BASE);
}
Example #8
0
void
HardwareSerial::begin(unsigned long baud)
{
    //
    // Initialize the UART.
    //
    ROM_SysCtlPeripheralEnable(g_ulUARTInt[uartModule]);

    //TODO:Add functionality for PinConfigure with variable uartModule
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);

    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    //
    // Only allow a single instance to be opened.
    //
    ASSERT(g_ulUARTBase[uartModule] == 0);
    //
    // Check to make sure the UART peripheral is present.
    //
    if(!ROM_SysCtlPeripheralPresent(g_ulUARTPeriph[uartModule]))
    {
        return;
    }
    ROM_SysCtlPeripheralEnable(g_ulUARTPeriph[uartModule]);
    ROM_UARTConfigSetExpClk(g_ulUARTBase[uartModule], ROM_SysCtlClockGet(), baud,
                            (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_WLEN_8));
    //
    // Set the UART to interrupt whenever the TX FIFO is almost empty or
    // when any character is received.
    //
    ROM_UARTFIFOLevelSet(g_ulUARTBase[uartModule], UART_FIFO_TX1_8, UART_FIFO_RX1_8);
    flushAll();
    ROM_UARTIntDisable(g_ulUARTBase[uartModule], 0xFFFFFFFF);
    ROM_UARTIntEnable(g_ulUARTBase[uartModule], UART_INT_RX | UART_INT_RT);
    ROM_IntMasterEnable();
    ROM_IntEnable(g_ulUARTInt[uartModule]);


    //
    // Enable the UART operation.
    //
    ROM_UARTEnable(g_ulUARTBase[uartModule]);

}
void HardwareSerial::end()
{
    unsigned long ulInt = ROM_IntMasterDisable();

	flushAll();

    //
    // If interrupts were enabled when we turned them off, turn them
    // back on again.
    //
    if(!ulInt)
    {
        ROM_IntMasterEnable();
    }

    ROM_IntDisable(g_ulUARTInt[uartModule]);
    ROM_UARTIntDisable(UART_BASE, UART_INT_RX | UART_INT_RT);
}
Example #10
0
// (call 'any ..) -> flg
any doCall(any ex) {
   pid_t pid;
   any x, y;
   int res, i, ac = length(x = cdr(ex));
   char *av[ac+1];

   if (ac == 0)
      return Nil;
   av[0] = alloc(NULL, pathSize(y = evSym(x))),  pathString(y, av[0]);
   for (i = 1; isCell(x = cdr(x)); ++i)
      av[i] = alloc(NULL, bufSize(y = evSym(x))),  bufString(y, av[i]);
   av[ac] = NULL;
   flushAll();
   if ((pid = fork()) == 0) {
      setpgid(0,0);
      execvp(av[0], av);
      execError(av[0]);
   }
   i = 0;  do
      free(av[i]);
   while (++i < ac);
   if (pid < 0)
      err(ex, NULL, "fork");
   setpgid(pid,0);
   if (Termio)
      tcsetpgrp(0,pid);
   for (;;) {
      while (waitpid(pid, &res, WUNTRACED) < 0) {
         if (errno != EINTR)
            err(ex, NULL, "wait pid");
         if (*Signal)
            sighandler(ex);
      }
      if (Termio)
         tcsetpgrp(0,getpgrp());
      if (!WIFSTOPPED(res))
         return res == 0? T : Nil;
      load(NULL, '+', Nil);
      if (Termio)
         tcsetpgrp(0,pid);
      kill(pid, SIGCONT);
   }
}
void
HardwareSerial::begin(unsigned long baud)
{
	baudRate = baud;
    //
    // Initialize the UART.
    //
    ROM_SysCtlPeripheralEnable(g_ulUARTPeriph[uartModule]);

    //TODO:Add functionality for PinConfigure with variable uartModule
    ROM_GPIOPinConfigure(g_ulUARTConfig[uartModule][0]);
    ROM_GPIOPinConfigure(g_ulUARTConfig[uartModule][1]);

    ROM_GPIOPinTypeUART(g_ulUARTPort[uartModule], g_ulUARTPins[uartModule]);

    ROM_UARTConfigSetExpClk(UART_BASE, F_CPU, baudRate,
                            (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_WLEN_8));
    //
    // Set the UART to interrupt whenever the TX FIFO is almost empty or
    // when any character is received.
    //
    ROM_UARTFIFOLevelSet(UART_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
    flushAll();
    ROM_UARTIntDisable(UART_BASE, 0xFFFFFFFF);
    ROM_UARTIntEnable(UART_BASE, UART_INT_RX | UART_INT_RT);
    ROM_IntEnable(g_ulUARTInt[uartModule]);

    //
    // Enable the UART operation.
    //
    ROM_UARTEnable(UART_BASE);

    // Allocate TX & RX buffers
    if (txBuffer != (unsigned char *)0xFFFFFFFF)  // Catch attempts to re-init this Serial instance by freeing old buffer first
        free(txBuffer);
    if (rxBuffer != (unsigned char *)0xFFFFFFFF)  // Catch attempts to re-init this Serial instance by freeing old buffer first
        free(rxBuffer);
    txBuffer = (unsigned char *) malloc(txBufferSize);
    rxBuffer = (unsigned char *) malloc(rxBufferSize);

    SysCtlDelay(100);
}
void GDIHashtable::BatchDestructionManager::update() {

    if (get_free_system_resources != NULL) {

        CriticalSection::Lock l(m_managerLock);

        if (m_nCounter < 0) {
            UINT nFreeResources = (*get_free_system_resources)(GFSR_GDIRESOURCES);
            /*
             * If m_bBatchingEnabled is FALSE there is no need
             * to flush since we have been destroying all
             * GDI resources as soon as they were released.
             */
            if (m_bBatchingEnabled) {
                if (nFreeResources < m_nFirstThreshold) {
                    flushAll();
                    nFreeResources = (*get_free_system_resources)(GFSR_GDIRESOURCES);
                }
            }
            if (nFreeResources < m_nSecondThreshold) {
                m_bBatchingEnabled = FALSE;
                m_nCounter = m_nDestroyPeriod;
            } else {
                m_bBatchingEnabled = TRUE;
                /*
                 * The frequency of checks must depend on the currect amount
                 * of free space in GDI heaps. Otherwise we can run into the
                 * Resource Meter warning dialog when GDI resources are low.
                 * This is a heuristic rule that provides this dependency.
                 * These numbers have been chosen because:
                 * Resource Meter posts a warning dialog when less than 10%
                 * of GDI resources are free.
                 * 5 pens/brushes take 1%. So 3 is the upper bound.
                 * When changing this rule you should check that performance
                 * isn't affected (with Caffeine Mark and JMark).
                 */
                m_nCounter = (nFreeResources - 10) * 3;
            }
        }
    }
}
Example #13
0
/*
 * 将数据接收地址设置rxAddr, 并将接收到的数据放入rxBuf中
 * 若成功返回1
 * 若失败返回0
 */
uchar nrfRecv(uchar* rxAddr, uchar* rxBuf)
{
    uchar rxSta, ret;

    enterRxMode(rxAddr);
    //延时等待400us
    _delay_us(400);
    rxSta = spiRw (STATUS);
    spiRwReg(WRITE_REG + STATUS, 0xff);

    if (rxSta & STA_MARK_RX)
    {
        spiWriteBuf (RD_RX_PLOAD, rxBuf, TX_PLOAD_WIDTH);
        ret = 1;
    }
    else
        ret = 0;

    flushAll();
    return ret;
}
Example #14
0
/*
 * 将数据发送地址设置为txAddr,并将txBuf中的数据发送出去
 * 若成功返回1
 * 若失败返回0
 */
uchar nrfSend(uchar* txAddr, volatile uchar* txBuf)
{
    uchar txSta, ret;
    uint iCnt = 0;
    enterTxMode(txAddr, txBuf);

    //接收到数据发送完成中断
    //或者是超过一定的查询次数
    while ((PIND * (1<<IRQ)) || (iCnt ++ > 2000));

    txSta = spiRw(STATUS);
    spiRwReg(WRITE_REG + STATUS, 0xff);

    if (txSta & STA_MARK_TX)
    {
        flushAll();
        ret = 1;
    }
    ret = 0;
    return ret;
}
Example #15
0
void InputFilter::setEnabled (lua_State *L, bool v)
{
    ensureAlive();
    if (enabled == v) return;
    enabled = v;
    if (enabled) {
        // If enabling, release all masked buttons below.
        BindingSet masked;
        for (auto i=buttonCallbacks.begin(), i_=buttonCallbacks.end() ; i != i_ ; ++i) {
            masked.insert(i->first);
        }
        IFMap::iterator i = ifmap.find(this->order);
        i++;
        for ( ; i != ifmap.end(); ++i) {
            i->second->flushSet(L, masked);
        }
    } else {
        // If disabling, release all local buttons.
        flushAll(L);
    }

    enabled = v;
    update_grabbed();
}
Example #16
0
template <typename ElemType> nano_time_t
TrsvPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];
    size_t lenX = 1 + ((params_.N-1) * abs(params_.incx)) + params_.offBX;

    status = clEnqueueWriteBuffer(queue, mobjX_, CL_TRUE, 0,
                                  lenX * sizeof(ElemType), backX_, 0, NULL, &event);
    if (status != CL_SUCCESS) {
        cerr << "Vector X buffer object enqueuing error, status = " <<
                 status << endl;

        return NANOTIME_ERR;
    }

    status = clWaitForEvents(1, &event);
    if (status != CL_SUCCESS) {
        cout << "Wait on event failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

    event = NULL;

    DataType type;
    type = ( typeid(ElemType) == typeid(float))? TYPE_FLOAT:( typeid(ElemType) == typeid(double))? TYPE_DOUBLE: ( typeid(ElemType) == typeid(FloatComplex))? TYPE_COMPLEX_FLOAT: TYPE_COMPLEX_DOUBLE;

	time = getCurrentTime();
#define TIMING
#ifdef TIMING
	clFinish( queue);

	int iter = 20;
	for ( int i = 1; i <= iter; i++)
	{
#endif
    status = (cl_int)clMath::clblas::trsv(type, params_.order, params_.uplo,
        params_.transA, params_.diag, params_.N, mobjA_, params_.offa, params_.lda,
        mobjX_, params_.offBX, params_.incx, 1, &queue, 0, NULL, &event);

    if (status != CL_SUCCESS) {
        cerr << "The CLBLAS TRSV function failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

#ifdef TIMING
	} // iter loop
	clFinish( queue);
    time = getCurrentTime() - time;
	time /= iter;
#else

    status = flushAll(1, &queue);
    if (status != CL_SUCCESS) {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS) {
        time = getCurrentTime() - time;
    }
    else {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }
#endif
    return time;
}
Example #17
0
template <typename ElemType> nano_time_t
HprPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];

    status = clEnqueueWriteBuffer(queue, mobjAP_, CL_TRUE, 0,
                                  ((( params_.N*( params_.N + 1 ) )/2 ) + params_.offa) *
                                  sizeof(ElemType), backAP_, 0, NULL, &event);
    if (status != CL_SUCCESS) {
        cerr << "Matrix A buffer object enqueuing error, status = " <<
                 status << endl;

        return NANOTIME_ERR;
    }

    status = clWaitForEvents(1, &event);
    if (status != CL_SUCCESS) {
        cout << "Wait on event failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

    event = NULL;

#define TIMING
#ifdef TIMING
    clFinish( queue);
    time = getCurrentTime();

    int iter = 20;
    for ( int i = 1; i <= iter; i++)
    {
#endif
    status = (cl_int)clMath::clblas::hpr(params_.order, params_.uplo, params_.N, CREAL(alpha_), mobjX_, params_.offBX, params_.incx,
				mobjAP_, params_.offa, 1, &queue, 0, NULL, &event);

    if (status != CL_SUCCESS) {
        cerr << "The CLBLAS HPR function failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

#ifdef TIMING
    } // iter loop
    clFinish( queue);
    time = getCurrentTime() - time;
    time /= iter;
#else
    status = flushAll(1, &queue);
    if (status != CL_SUCCESS) {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    time = getCurrentTime();
    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS) {
        time = getCurrentTime() - time;
    }
    else {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }
#endif

    return time;
}
Example #18
0
void VerticesExtractor::call_RAY_SLAVE_MODE_ADD_EDGES(){

	MACRO_COLLECT_PROFILING_INFORMATION();

	if(this->m_outbox==NULL){
		m_rank=m_parameters->getRank();
		this->m_mode=m_mode;
		this->m_outbox=m_outbox;
		this->m_outboxAllocator=m_outboxAllocator;
	}

	if(m_finished){
		return;
	}

	if(!m_checkedCheckpoint){
		m_checkedCheckpoint=true;
		if(m_parameters->hasCheckpoint("GenomeGraph")){
			cout<<"Rank "<<m_parameters->getRank()<<": checkpoint GenomeGraph exists, not extracting vertices."<<endl;
			Message aMessage(NULL,0,MASTER_RANK,RAY_MPI_TAG_VERTICES_DISTRIBUTED,m_parameters->getRank());
			m_outbox->push_back(aMessage);
			m_finished=true;
			return;
		}
	}

	#ifdef ASSERT
	assert(m_pendingMessages>=0);
	#endif
	if(m_pendingMessages!=0){
		return;
	}

	if(m_mode_send_vertices_sequence_id%10000==0 &&m_mode_send_vertices_sequence_id_position==0
		&&m_mode_send_vertices_sequence_id<(int)m_myReads->size()){

		string reverse="";
		if(m_reverseComplementVertex==true){
			reverse="(reverse complement) ";
		}
		printf("Rank %i is adding edges %s[%i/%i]\n",m_parameters->getRank(),reverse.c_str(),(int)m_mode_send_vertices_sequence_id+1,(int)m_myReads->size());
		fflush(stdout);

		m_derivative.addX(m_mode_send_vertices_sequence_id);
		m_derivative.printStatus(SLAVE_MODES[RAY_SLAVE_MODE_ADD_EDGES],RAY_SLAVE_MODE_ADD_EDGES);
		m_derivative.printEstimatedTime(m_myReads->size());
	}

	if(m_mode_send_vertices_sequence_id==(int)m_myReads->size()){

		MACRO_COLLECT_PROFILING_INFORMATION();

		// flush data
		flushAll(m_outboxAllocator,m_outbox,m_parameters->getRank());

		if(m_pendingMessages==0){
			#ifdef ASSERT
			assert(m_bufferedDataForIngoingEdges.isEmpty());
			assert(m_bufferedDataForOutgoingEdges.isEmpty());
			#endif

			Message aMessage(NULL,0, MASTER_RANK, RAY_MPI_TAG_VERTICES_DISTRIBUTED,m_parameters->getRank());
			m_outbox->push_back(aMessage);
			m_finished=true;
			printf("Rank %i is adding edges [%i/%i] (completed)\n",m_parameters->getRank(),(int)m_mode_send_vertices_sequence_id,(int)m_myReads->size());
			fflush(stdout);
			m_bufferedDataForIngoingEdges.showStatistics(m_parameters->getRank());
			m_bufferedDataForOutgoingEdges.showStatistics(m_parameters->getRank());

			m_derivative.writeFile(&cout);
		}
	}else{

		MACRO_COLLECT_PROFILING_INFORMATION();

/*
 * Decode the DNA sequence 
 * and store it in a local buffer.
 */
		if(m_mode_send_vertices_sequence_id_position==0){
			(*m_myReads)[(m_mode_send_vertices_sequence_id)]->getSeq(m_readSequence,m_parameters->getColorSpaceMode(),false);
		
			//cout<<"DEBUG Read="<<*m_mode_send_vertices_sequence_id<<" color="<<m_parameters->getColorSpaceMode()<<" Seq= "<<m_readSequence<<endl;
		}

		int len=strlen(m_readSequence);

		if(len<m_parameters->getWordSize()){
			m_hasPreviousVertex=false;
			(m_mode_send_vertices_sequence_id)++;
			(m_mode_send_vertices_sequence_id_position)=0;
			return;
		}

		MACRO_COLLECT_PROFILING_INFORMATION();

		char memory[1000];

		int maximumPosition=len-m_parameters->getWordSize()+1;
		
		#ifdef ASSERT
		assert(m_readSequence!=NULL);
		#endif

		int p=(m_mode_send_vertices_sequence_id_position);
		memcpy(memory,m_readSequence+p,m_parameters->getWordSize());
		memory[m_parameters->getWordSize()]='\0';

		MACRO_COLLECT_PROFILING_INFORMATION();

		if(isValidDNA(memory)){

			MACRO_COLLECT_PROFILING_INFORMATION();

			Kmer currentForwardKmer=wordId(memory);

			/* TODO: possibly don't flush k-mer that are not lower. not sure it that would work though. -Seb */

/*
 *                   previousForwardKmer   ->   currentForwardKmer
 *                   previousReverseKmer   <-   currentReverseKmer
 */


/*
 * Push the kmer
 */


			MACRO_COLLECT_PROFILING_INFORMATION();

			if(m_hasPreviousVertex){

				MACRO_COLLECT_PROFILING_INFORMATION();

				// outgoing edge
				// PreviousVertex(*) -> CurrentVertex
				Rank outgoingRank=m_parameters->_vertexRank(&m_previousVertex);
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,m_previousVertex.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,currentForwardKmer.getU64(i));
				}


				if(m_bufferedDataForOutgoingEdges.flush(outgoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_OUT_EDGES_DATA,m_outboxAllocator,m_outbox,m_parameters->getRank(),false)){
					m_pendingMessages++;
				}

				// ingoing edge
				// PreviousVertex -> CurrentVertex(*)
				Rank ingoingRank=m_parameters->_vertexRank(&currentForwardKmer);
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,m_previousVertex.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,currentForwardKmer.getU64(i));
				}


				if(m_bufferedDataForIngoingEdges.flush(ingoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_IN_EDGES_DATA,m_outboxAllocator,m_outbox,m_parameters->getRank(),false)){
					m_pendingMessages++;
				}

				MACRO_COLLECT_PROFILING_INFORMATION();
			}

			// reverse complement
			//
			Kmer currentReverseKmer=currentForwardKmer.
				complementVertex(m_parameters->getWordSize(),m_parameters->getColorSpaceMode());


			if(m_hasPreviousVertex){
				MACRO_COLLECT_PROFILING_INFORMATION();

				// outgoing edge
				// 
				Rank outgoingRank=m_parameters->_vertexRank(&currentReverseKmer);

				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,currentReverseKmer.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,m_previousVertexRC.getU64(i));
				}

				MACRO_COLLECT_PROFILING_INFORMATION();


				if(m_bufferedDataForOutgoingEdges.flush(outgoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_OUT_EDGES_DATA,m_outboxAllocator,m_outbox,m_parameters->getRank(),false)){

					m_pendingMessages++;
				}

				MACRO_COLLECT_PROFILING_INFORMATION();

				// ingoing edge
				Rank ingoingRank=m_parameters->_vertexRank(&m_previousVertexRC);

				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,currentReverseKmer.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,m_previousVertexRC.getU64(i));
				}

				MACRO_COLLECT_PROFILING_INFORMATION();


				if(m_bufferedDataForIngoingEdges.flush(ingoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_IN_EDGES_DATA,m_outboxAllocator,m_outbox,m_parameters->getRank(),false)){
					m_pendingMessages++;
				}
				MACRO_COLLECT_PROFILING_INFORMATION();
			}

			// there is a previous vertex.
			m_hasPreviousVertex=true;
			m_previousVertex=currentForwardKmer;
			m_previousVertexRC=currentReverseKmer;
		}else{
			m_hasPreviousVertex=false;
		}

		MACRO_COLLECT_PROFILING_INFORMATION();

		(m_mode_send_vertices_sequence_id_position++);

		if((m_mode_send_vertices_sequence_id_position)==maximumPosition){
			m_hasPreviousVertex=false;
			(m_mode_send_vertices_sequence_id)++;
			(m_mode_send_vertices_sequence_id_position)=0;
		}
	}
	MACRO_COLLECT_PROFILING_INFORMATION();
}
Example #19
0
/**
 * \brief	This checks if some event was triggered to get the new input command
 * \param	device		input of which we are trying to read the event
 * \param	command		command for which we want to assign the event
 * \return 	returns true, if an event was triggered, or false if not.
 */
void CInput::readNewEvent()
{
	stInputCommand &lokalInput = InputCommand[remapper.mapDevice][remapper.mapPosition];

	// This function is used to configure new input keys.
	// For iPhone, we have emulation via touchpad and we don't want to have custom keys.
	// We should fix the menu for iPhone so that this function doesn't get called.
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
	printf("WARNING: called readNewEvent on iphone\n");
	return;
#endif

	memset(&lokalInput, 0, sizeof(stInputCommand));
	if(!m_EventList.empty())
		m_EventList.clear();

	while( SDL_PollEvent( &Event ) )
	{
		switch ( Event.type )
		{
			case SDL_QUIT:
				gLogging.textOut("SDL: Got quit event in readNewEvent!");
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
				// on iPhone, we just want to quit in this case
				exit(0);
#endif
                break;

			case SDL_KEYDOWN:
				lokalInput.joyeventtype = ETYPE_KEYBOARD;
				lokalInput.keysym = Event.key.keysym.sym;
				remapper.mappingInput = false;
				break;

			case SDL_JOYBUTTONDOWN:
#if defined(CAANOO) || defined(WIZ) || defined(GP2X)
				WIZ_EmuKeyboard( Event.jbutton.button, 1 );
				return false;
#else
				lokalInput.joyeventtype = ETYPE_JOYBUTTON;
				lokalInput.joybutton = Event.jbutton.button;
				lokalInput.which = Event.jbutton.which;
				remapper.mappingInput = false;
#endif
				break;

			case SDL_JOYAXISMOTION:

				// Deadzone check. Double, because being a
				// new event to be read it should make better to configure
				if( (Event.jaxis.value > 2*m_joydeadzone ) ||
				    (Event.jaxis.value < -2*m_joydeadzone ) )
				{
					lokalInput.joyeventtype = ETYPE_JOYAXIS;
					lokalInput.joyaxis = Event.jaxis.axis;
					lokalInput.which = Event.jaxis.which;
					lokalInput.joyvalue = (Event.jaxis.value>0) ? 32767 : -32767;
					remapper.mappingInput = false;
				}

				break;

			case SDL_JOYHATMOTION:
				lokalInput.joyeventtype = ETYPE_JOYHAT;
				lokalInput.joyhatval = Event.jhat.value;
				lokalInput.which = Event.jhat.which;
				remapper.mappingInput = false;
				break;
		}

        flushAll();
    }
}
Example #20
0
template <typename ElemType> nano_time_t
HpmvPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];
	int lenY = 1 + (params_.N-1) * abs(params_.incy);

    status = clEnqueueWriteBuffer(queue, mobjY_, CL_TRUE, 0,
                                  (lenY + params_.offCY )* sizeof(ElemType), backY_, 0, NULL, &event);
    if (status != CL_SUCCESS) {
        cerr << "Vector Y buffer object enqueuing error, status = " <<
                 status << endl;

        return NANOTIME_ERR;
    }

    status = clWaitForEvents(1, &event);
    if (status != CL_SUCCESS) {
        cout << "Wait on event failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

    event = NULL;

	time = getCurrentTime();
#define TIMING
#ifdef TIMING

	int iter = 20;
	for ( int i = 1; i <= iter; i++)
	{
#endif
		status = (cl_int)clMath::clblas::hpmv(params_.order, params_.uplo, params_.N, alpha, mobjAP_, params_.offA,
						mobjX_, params_.offBX, params_.incx, beta, mobjY_, params_.offCY, params_.incy,
						1, &queue, 0, NULL, &event);

    if (status != CL_SUCCESS) {
        cerr << "The CLBLAS HPMV function failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

#ifdef TIMING
	} // iter loop
	clFinish( queue);
    time = getCurrentTime() - time;
	time /= iter;
#else

	status = flushAll(1, &queue);
    if (status != CL_SUCCESS) {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    time = getCurrentTime();
    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS) {
        time = getCurrentTime() - time;
    }
    else {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }

	//printf("Time elapsed : %lu\n", time);
#endif

    return time;
}
Example #21
0
void
getDirCreateTimes(struct sub_data *dirCreate, char **dname, char **fname,
		  int numdirs, int numFiles)
{
  int fd, i, j;
  int startTime, endTime;

#ifdef DEBUG
  printf("DirCreateTime\n");
#endif

  for (j = 0; j < reps; j++) {
    /* flush caches */
    flushAll();

    /* create the files */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++) {
      if ((fd = open(fname[i], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) == -1) {
	perror("dirCreate, create");
	exit(1);
      }
      close(fd);
    }
    gettimeofday(&endTime, (struct timezone *) NULL);
    dirCreate->time1[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("numFiles: %d, time: %f\n", numFiles, dirCreate->time1[j]);
#endif
    
    /* remove the files */
    for (i = 0; i < numFiles; i++) {
      if (unlink(fname[i]) < 0) {
	perror("dirCreateTime, unlink");
	exit(1);
      }
    }
    sync();

    /* flush caches */
    flushAll();
    
    /* create the directories */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++) {
      if (mkdir(fname[i], S_IRWXU) == -1) {
	perror("dirCreate, mkdir");
	exit(1);
      }
    }
    gettimeofday(&endTime, (struct timezone *) NULL);
    dirCreate->time2[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("numDirs: %d, time: %f\n", numFiles, dirCreate->time2[j]);
#endif
    
    /* remove the files */
    for (i = 0; i < numFiles; i++) {
      if (rmdir(fname[i]) < 0) {
	perror("dirCreateTime, rmdir");
	exit(1);
      }
    }
    sync();
  }
}
Example #22
0
void
getInodeAccessTimes(struct sub_data *inodeAccess, char **dname, char **fname,
		    int numdirs, int numFiles)
{
  int *perm;
  int fd, i, j;
  int startTime, endTime;
  struct alfs_stat buf;

#ifdef DEBUG
  printf("InodeAccessTime\n");
#endif

  perm = (int *) myMalloc (sizeof(int) * numFiles);

  /* create the files */
  for (i = 0; i < numFiles; i++) {
    if ((fd = open(fname[i], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) == -1) {
      perror("inodeAccess, create");
      exit(1);
    }
    close(fd);
  }
    
  for (j = 0; j < reps; j++) {
    /* create permuation */
    createPerm(&perm, numFiles, 1, numFiles);

    /* flush buffers */
    flushAll();
    
    /* stat the path to get the path into the cache */
    for (i = 0; i < numdirs; i++)
      if (stat(dname[i], &buf) < 0) {
	perror("inodeAccess, stat path");
	exit(1);
      }

    /* stat in creation order */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++) {
      if (stat(fname[i], &buf) < 0) {
	perror("inodeAccess, stat seq");
	exit(1);
      }
    }
    gettimeofday(&endTime, (struct timezone *) NULL);
    inodeAccess->time1[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("SEQ: numFiles: %d, time: %f\n", numFiles, inodeAccess->time1[j]);
#endif

    /* flush buffers */
    flushAll();

    /* stat the path to get the path into the cache */
    for (i = 0; i < numdirs; i++)
      if (stat(dname[i], &buf) < 0) {
	perror("inodeAccess, stat path 2");
	exit(1);
      }

    /* stat in random order */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++) {
      if (stat(fname[perm[i]], &buf) < 0) {
	perror("inodeAccess, stat rand");
	exit(1);
      }
    }
    gettimeofday(&endTime, (struct timezone *) NULL);
    inodeAccess->time2[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("RAND: numFiles: %d, time: %f\n", numFiles, inodeAccess->time2[j]);
#endif
  }

  /* clean-up */
  for (i = 0; i < numFiles; i++)
    if (unlink(fname[i]) < 0) {
      perror("inodeAccessTime, unlink");
      exit(1);
    }
  free(perm);
}
Example #23
0
pid_t forkLisp(any ex) {
   pid_t n;
   int i, hear[2], tell[2];
   static int mic[2];

   flushAll();
   if (!Spkr) {
      if (pipe(mic) < 0)
         pipeError(ex, "open");
      closeOnExec(ex, mic[0]), closeOnExec(ex, mic[1]);
      Spkr = mic[0];
   }
   if (pipe(hear) < 0  ||  pipe(tell) < 0)
      pipeError(ex, "open");
   closeOnExec(ex, hear[0]), closeOnExec(ex, hear[1]);
   closeOnExec(ex, tell[0]), closeOnExec(ex, tell[1]);
   for (i = 0; i < Children; ++i)
      if (!Child[i].pid)
         break;
   if ((n = fork()) < 0)
      err(ex, NULL, "fork");
   if (n == 0) {
      void *p;

      Slot = i;
      Spkr = 0;
      Mic = mic[1];
      close(hear[1]), close(tell[0]), close(mic[0]);
      if (Hear)
         close(Hear),  closeInFile(Hear),  closeOutFile(Hear);
      initInFile(Hear = hear[0], NULL);
      if (Tell)
         close(Tell);
      Tell = tell[1];
      for (i = 0; i < Children; ++i)
         if (Child[i].pid)
            close(Child[i].hear), close(Child[i].tell),  free(Child[i].buf);
      Children = 0,  free(Child),  Child = NULL;
      for (p = Env.inFrames; p; p = ((inFrame*)p)->link)
         ((inFrame*)p)->pid = 0;
      for (p = Env.outFrames; p; p = ((outFrame*)p)->link)
         ((outFrame*)p)->pid = 0;
      for (p = CatchPtr; p; p = ((catchFrame*)p)->link)
         ((catchFrame*)p)->fin = Zero;
      free(Termio),  Termio = NULL;
      if (Repl)
         ++Repl;
      val(PPid) = val(Pid);
      val(Pid) = boxCnt(getpid());
      run(val(Fork));
      val(Fork) = Nil;
      return 0;
   }
   if (i == Children)
      allocChildren();
   close(hear[0]), close(tell[1]);
   Child[i].pid = n;
   Child[i].hear = tell[0];
   nonblocking(Child[i].tell = hear[1]);
   Child[i].ofs = Child[i].cnt = 0;
   Child[i].buf = NULL;
   return n;
}
Example #24
0
void
getInodeCreateTimes(struct sub3_data *inodeCreate, char **dname, char **fname,
		    int numdirs, int numFiles)
{
  char **flink;
  int fd;
  int i, j, index;
  int startTime, endTime;
  struct alfs_stat buf;

#ifdef DEBUG
  printf("InodeCreateTime\n");
#endif

  /* name files */
  flink = (char **) myMalloc (sizeof(char *) * numFiles);
  index = 0;
  i = numdirs - numFiles / MAXNUMFILESINDIR;
  if (numFiles % MAXNUMFILESINDIR != 0)
    i--;
  for (; i < numdirs && index < numFiles; i++) {
    for (j = 0; (j < MAXNUMFILESINDIR) && (index < numFiles); j++) {
      flink[index] = (char *) myMalloc(strlen(dname[i]) + 25);
      sprintf(flink[index], "%s/link%d.%d", dname[i], index, getpid());
      index++;
    }
  }

  /* loop _reps_ time to increase accuracy */
  for (j = 0; j < reps; j++) {
    /* flush caches */
    flushAll();

    /* stat the directories */
    for (i = 0; i < numdirs; i++)
      if (stat(dname[i], &buf) == -1) {
	perror("inodeCreate, dir stat");
	exit(1);
      }

    /* create the files */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++) {
      if ((fd = open(fname[i], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) == -1) {
	perror("inodeCreate, create");
	exit(1);
      }
      close(fd);
    }
    gettimeofday(&endTime, (struct timezone *) NULL);
    inodeCreate->time1[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("numFiles: %d, time: %f\n", numFiles, inodeCreate->time1[j]);
#endif

    /* flush caches */
    flushAll();

    /* stat the files */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++)
      if (stat(fname[i], &buf) == -1) {
	perror("inodeCreate, file stat");
	exit(1);
      }
    gettimeofday(&endTime, (struct timezone *) NULL);
    inodeCreate->time2[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("numFiles, %d, time: %f\n", numFiles, inodeCreate->time2[j]);
#endif

    /* flush caches */
    flushAll();

#ifndef NOHARDLINKS
    /* create the hard-links */
    gettimeofday(&startTime, (struct timezone *) NULL);
    for (i = 0; i < numFiles; i++) {
      if (stat(fname[i], &buf) == -1) {
	perror("inodeCreate, file stat 2");
	exit(1);
      }
      if (link(fname[i], flink[i]) == -1) {
	perror("inodeCreate, link");
	exit(1);
      }
    }
    gettimeofday(&endTime, (struct timezone *) NULL);
    inodeCreate->time3[j] = diffTime(startTime, endTime);
#ifdef DEBUG
    printf("numLinks: %d, time: %f\n", numFiles, inodeCreate->time3[j]);
#endif
#endif /* NOHARDLINKS */

    /* remove everything */
    for (i = 0; i < numFiles; i++) {
#ifndef NOHARDLINKS
      if (unlink(flink[i]) < 0) {
	perror("inodeCreateTime, unlink link");
	exit(1);
      }
#endif
      if (unlink(fname[i]) < 0) {
	perror("inodeCreateTime, unlink");
	exit(1);
      }
    }
    sync();
  }

  for (i = 0; i < numFiles; i++)
    free(flink[i]);
  free(flink);
}
Example #25
0
template <typename ElemType> nano_time_t
RotPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];

    //DataType type;
    //type = ( typeid(ElemType) == typeid(float))? TYPE_FLOAT: TYPE_DOUBLE;

    status = clEnqueueWriteBuffer(queue, mobjX_, CL_TRUE, 0, (lengthx + params_.offa) * sizeof(ElemType), X_, 0, NULL, &event);
    if (status != CL_SUCCESS)
    {
        cerr << "Vector X buffer object enqueuing error, status = " << status << endl;
        return NANOTIME_ERR;
    }

    status = clEnqueueWriteBuffer(queue, mobjY_, CL_TRUE, 0, (lengthy + params_.offb) * sizeof(ElemType), Y_, 0, NULL, &event);
    if (status != CL_SUCCESS)
    {
        cerr << "Vector Y buffer object enqueuing error, status = " << status << endl;
        return NANOTIME_ERR;
    }

    status = clWaitForEvents(1, &event);
    if (status != CL_SUCCESS)
    {
        cout << "Wait on event failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    event = NULL;
    time = getCurrentTime();

#define TIMING
#ifdef TIMING
    clFinish( queue);
    int iter = 50;
    for ( int i=1; i <= iter; i++)
    {
#endif
        status = (cl_int)clMath::clblas::rot(params_.N, mobjX_, params_.offa, params_.incx, mobjY_, params_.offb, params_.incy,
                                             alpha, beta, 1, &queue, 0, NULL, &event);
        if (status != CL_SUCCESS)
        {
            cerr << "The CLBLAS ROT function failed, status = " << status << endl;
            return NANOTIME_ERR;
        }
#ifdef TIMING
    } // iter loop
    clFinish( queue);
    time = getCurrentTime() - time;
    time /= iter;
#else

    status = flushAll(1, &queue);
    if (status != CL_SUCCESS)
    {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    time = getCurrentTime();
    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS)
    {
        time = getCurrentTime() - time;
    }
    else
    {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }
#endif
    return time;
}
Example #26
0
void VerticesExtractor::process(int*m_mode_send_vertices_sequence_id,
				ArrayOfReads*m_myReads,
				bool*m_reverseComplementVertex,
				int rank,
				StaticVector*m_outbox,
				bool*m_mode_send_vertices,
				int wordSize,
				int size,
				RingAllocator*m_outboxAllocator,
				int*m_mode
				){
	if(this->m_outbox==NULL){
		m_rank=rank;
		this->m_mode=m_mode;
		this->m_outbox=m_outbox;
		this->m_outboxAllocator=m_outboxAllocator;
	}
	#ifdef ASSERT
	assert(m_pendingMessages>=0);
	#endif
	if(m_pendingMessages!=0){
		return;
	}

	if(m_finished){
		return;
	}

	if(*m_mode_send_vertices_sequence_id%100000==0 &&m_mode_send_vertices_sequence_id_position==0
	&&*m_mode_send_vertices_sequence_id<(int)m_myReads->size()){
		string reverse="";
		if(*m_reverseComplementVertex==true){
			reverse="(reverse complement) ";
		}
		printf("Rank %i is computing vertices & edges %s[%i/%i]\n",rank,reverse.c_str(),(int)*m_mode_send_vertices_sequence_id+1,(int)m_myReads->size());
		fflush(stdout);
	}

	if(*m_mode_send_vertices_sequence_id>(int)m_myReads->size()-1){
		// flush data
		flushAll(m_outboxAllocator,m_outbox,rank);
		if(m_pendingMessages==0){
			#ifdef ASSERT
			assert(m_bufferedData.isEmpty());
			assert(m_bufferedDataForIngoingEdges.isEmpty());
			assert(m_bufferedDataForOutgoingEdges.isEmpty());
			#endif

			Message aMessage(NULL,0, MASTER_RANK, RAY_MPI_TAG_VERTICES_DISTRIBUTED,rank);
			m_outbox->push_back(aMessage);
			m_finished=true;
			printf("Rank %i is computing vertices & edges [%i/%i] (completed)\n",rank,(int)*m_mode_send_vertices_sequence_id,(int)m_myReads->size());
			fflush(stdout);
			m_bufferedData.showStatistics(m_parameters->getRank());
			m_bufferedDataForIngoingEdges.showStatistics(m_parameters->getRank());
			m_bufferedDataForOutgoingEdges.showStatistics(m_parameters->getRank());
		}
	}else{
		if(m_mode_send_vertices_sequence_id_position==0){
			(*m_myReads)[(*m_mode_send_vertices_sequence_id)]->getSeq(m_readSequence,m_parameters->getColorSpaceMode(),false);
		
			//cout<<"DEBUG Read="<<*m_mode_send_vertices_sequence_id<<" color="<<m_parameters->getColorSpaceMode()<<" Seq= "<<m_readSequence<<endl;
		}
		int len=strlen(m_readSequence);

		if(len<wordSize){
			m_hasPreviousVertex=false;
			(*m_mode_send_vertices_sequence_id)++;
			(m_mode_send_vertices_sequence_id_position)=0;
			return;
		}

		char memory[1000];
		int lll=len-wordSize+1;
		
		#ifdef ASSERT
		assert(m_readSequence!=NULL);
		#endif

		int p=(m_mode_send_vertices_sequence_id_position);
		memcpy(memory,m_readSequence+p,wordSize);
		memory[wordSize]='\0';
		if(isValidDNA(memory)){
			Kmer a=wordId(memory);

			int rankToFlush=0;

			rankToFlush=m_parameters->_vertexRank(&a);
			for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
				m_bufferedData.addAt(rankToFlush,a.getU64(i));
			}

			if(m_bufferedData.flush(rankToFlush,KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_VERTICES_DATA,m_outboxAllocator,m_outbox,rank,false)){
				m_pendingMessages++;
			}

			if(m_hasPreviousVertex){
				// outgoing edge
				int outgoingRank=m_parameters->_vertexRank(&m_previousVertex);
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,m_previousVertex.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,a.getU64(i));
				}

				if(m_bufferedDataForOutgoingEdges.needsFlushing(outgoingRank,2*KMER_U64_ARRAY_SIZE)){
					if(m_bufferedData.flush(outgoingRank,KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_VERTICES_DATA,m_outboxAllocator,m_outbox,rank,true)){
						m_pendingMessages++;
					}
				}

				if(m_bufferedDataForOutgoingEdges.flush(outgoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_OUT_EDGES_DATA,m_outboxAllocator,m_outbox,rank,false)){
					m_pendingMessages++;
				}

				// ingoing edge
				int ingoingRank=m_parameters->_vertexRank(&a);
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,m_previousVertex.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,a.getU64(i));
				}

				if(m_bufferedDataForIngoingEdges.needsFlushing(ingoingRank,2*KMER_U64_ARRAY_SIZE)){
					if(m_bufferedData.flush(ingoingRank,KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_VERTICES_DATA,m_outboxAllocator,m_outbox,rank,true)){
						m_pendingMessages++;
					}
				}

				if(m_bufferedDataForIngoingEdges.flush(ingoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_IN_EDGES_DATA,m_outboxAllocator,m_outbox,rank,false)){
					m_pendingMessages++;
				}
			}

			// reverse complement
			Kmer b=complementVertex(&a,wordSize,m_parameters->getColorSpaceMode());

			rankToFlush=m_parameters->_vertexRank(&b);
			for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
				m_bufferedData.addAt(rankToFlush,b.getU64(i));
			}

			if(m_bufferedData.flush(rankToFlush,KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_VERTICES_DATA,m_outboxAllocator,m_outbox,rank,false)){
				m_pendingMessages++;
			}

			if(m_hasPreviousVertex){
				// outgoing edge
				int outgoingRank=m_parameters->_vertexRank(&b);
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,b.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForOutgoingEdges.addAt(outgoingRank,m_previousVertexRC.getU64(i));
				}

				if(m_bufferedDataForOutgoingEdges.needsFlushing(outgoingRank,2*KMER_U64_ARRAY_SIZE)){
					if(m_bufferedData.flush(outgoingRank,1*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_VERTICES_DATA,m_outboxAllocator,m_outbox,rank,true)){
						m_pendingMessages++;
					}
				}

				if(m_bufferedDataForOutgoingEdges.flush(outgoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_OUT_EDGES_DATA,m_outboxAllocator,m_outbox,rank,false)){
					m_pendingMessages++;
				}

				// ingoing edge
				int ingoingRank=m_parameters->_vertexRank(&m_previousVertexRC);
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,b.getU64(i));
				}
				for(int i=0;i<KMER_U64_ARRAY_SIZE;i++){
					m_bufferedDataForIngoingEdges.addAt(ingoingRank,m_previousVertexRC.getU64(i));
				}

				if(m_bufferedDataForIngoingEdges.needsFlushing(ingoingRank,2*KMER_U64_ARRAY_SIZE)){
					if(m_bufferedData.flush(ingoingRank,1*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_VERTICES_DATA,m_outboxAllocator,m_outbox,rank,true)){
						m_pendingMessages++;
					}
				}

				if(m_bufferedDataForIngoingEdges.flush(ingoingRank,2*KMER_U64_ARRAY_SIZE,RAY_MPI_TAG_IN_EDGES_DATA,m_outboxAllocator,m_outbox,rank,false)){
					m_pendingMessages++;
				}
			}

			// there is a previous vertex.
			m_hasPreviousVertex=true;
			m_previousVertex=a;
			m_previousVertexRC=b;
		}else{
			m_hasPreviousVertex=false;
		}

		(m_mode_send_vertices_sequence_id_position++);
		if((m_mode_send_vertices_sequence_id_position)==lll){
			m_hasPreviousVertex=false;
			(*m_mode_send_vertices_sequence_id)++;
			(m_mode_send_vertices_sequence_id_position)=0;
		}
	}
}
Example #27
0
Component::~Component()
{
    
    ofLogVerbose(__func__) << getName();
    OMX_ERRORTYPE error;

    if(handle)
    {
        for (size_t i = 0; i < inputBuffers.size(); i++)
        {
            error = OMX_FreeBuffer(handle, inputPort, inputBuffers[i]);
            OMX_TRACE(error);
        }
       
    }
    
    while (!inputBuffersAvailable.empty())
    {
        inputBuffersAvailable.pop();
    }
    inputBuffers.clear();
    
    //if(componentName != "OMX.broadcom.video_decode")
    //{
        
    if (doFreeHandle) 
    {
        
        error = OMX_FreeHandle(handle);
        OMX_TRACE(error); 
        ofLogVerbose(__func__) << componentName << " FREED";
    }else
    {
        stringstream info;
        
        OMX_STATETYPE currentState;
        OMX_GetState(handle, &currentState);
        
        
        OMX_PARAM_U32TYPE extra_buffers;
        OMX_INIT_STRUCTURE(extra_buffers);
        
        error = getParameter(OMX_IndexParamBrcmExtraBuffers, &extra_buffers);
        OMX_TRACE(error);
        info << "currentState: " << GetOMXStateString(currentState) << endl;
        info << "PRE extra_buffers.nU32: " << (int)extra_buffers.nU32 << endl;
       
        extra_buffers.nU32 = 0;
        error = setParameter(OMX_IndexParamBrcmExtraBuffers, &extra_buffers);
        OMX_TRACE(error);
        
        error = getParameter(OMX_IndexParamBrcmExtraBuffers, &extra_buffers);
        info << "POST extra_buffers.nU32: " << (int)extra_buffers.nU32 << endl;
        
        flushAll();
        
        disableAllPorts();
        ofLogVerbose(__func__) << info.str();
        //error = OMX_FreeHandle(handle);
        //OMX_TRACE(error); 
        //ofLogVerbose(__func__) << info.str() << " " << componentName << " FREED";

    }

    //}
    
    handle = NULL;
    
    
    //error =  waitForCommand(OMX_CommandPortDisable, inputPort);
    //OMX_TRACE(error);
    
  
 
	pthread_mutex_destroy(&m_omx_input_mutex);
	pthread_mutex_destroy(&m_omx_output_mutex);
	pthread_mutex_destroy(&event_mutex);
	pthread_mutex_destroy(&eos_mutex);
	pthread_cond_destroy(&m_input_buffer_cond);
	pthread_cond_destroy(&m_output_buffer_cond);
	pthread_cond_destroy(&m_omx_event_cond);

	pthread_mutex_destroy(&m_lock);
	sem_destroy(&m_omx_fill_buffer_done);

}
Example #28
0
bool Component::Deinitialize(string caller)
{
    ofLogVerbose(__func__) << componentName << " by caller: " << caller;
    OMX_ERRORTYPE error = OMX_ErrorNone;

    
    
	if(handle)
	{
		
        flushAll();
		

        error = freeOutputBuffers();
        OMX_TRACE(error);
		freeInputBuffers();
        OMX_TRACE(error);
        
        if((componentName != "OMX.broadcom.egl_render") && (componentName != "OMX.broadcom.video_decode"))
        {
            if(getState() == OMX_StateExecuting)
            {
                setState(OMX_StatePause);
            }
            if(getState() != OMX_StateIdle)
            {
                setState(OMX_StateIdle);
            }
            if(getState() != OMX_StateLoaded)
            {
                setState(OMX_StateLoaded);
            }
        }
		
        if(componentName != "OMX.broadcom.video_decode")
        {
            error = OMX_FreeHandle(handle);
            OMX_TRACE(error); 
        }
		


		handle = NULL;
	}else
    {
        ofLogError(__func__) << "NO HANDLE! caller: " << caller;
    }

	inputPort    = 0;
	outputPort   = 0;
	//componentName = "";

    if(CustomFillBufferDoneHandler)
    {
        CustomFillBufferDoneHandler = NULL;
    }
	if(CustomEmptyBufferDoneHandler)
    {
       CustomEmptyBufferDoneHandler = NULL; 
    }
	

    ofLogVerbose(__func__) << componentName << " END";

	return true;
}
Example #29
0
template <typename ElemType> nano_time_t
ScalPerformanceTest<ElemType>::clblasPerfSingle(void)
{
    nano_time_t time;
    cl_event event;
    cl_int status;
    cl_command_queue queue = base_->commandQueues()[0];
    bool is_css_zds = (params_.K == 1)? true: false;        // K indicates csscal/zdscal

    status = clEnqueueWriteBuffer(queue, mobjX_, CL_TRUE, 0,
                                  (lengthX + params_.offBX) * sizeof(ElemType), backX_, 0, NULL, &event);
    if (status != CL_SUCCESS) {
        cerr << "Matrix A buffer object enqueuing error, status = " <<
                 status << endl;

        return NANOTIME_ERR;
    }

    status = clWaitForEvents(1, &event);
    if (status != CL_SUCCESS) {
        cout << "Wait on event failed, status = " <<
                status << endl;

        return NANOTIME_ERR;
    }

    event = NULL;
    time = getCurrentTime();

#define TIMING
#ifdef TIMING
    clFinish( queue);
    int iter = 50;
    for ( int i=1; i <= iter; i++)
    {
#endif

        status = (cl_int)clMath::clblas::scal(is_css_zds, params_.N, alpha_, mobjX_, params_.offBX, params_.incx,
                            1, &queue, 0, NULL, &event);
        if (status != CL_SUCCESS) {
            cerr << "The CLBLAS SCAL function failed, status = " <<
                    status << endl;

            return NANOTIME_ERR;
        }
#ifdef TIMING
    } // iter loop
    clFinish( queue);
    time = getCurrentTime() - time;
    time /= iter;
#else

    status = flushAll(1, &queue);
    if (status != CL_SUCCESS) {
        cerr << "clFlush() failed, status = " << status << endl;
        return NANOTIME_ERR;
    }

    time = getCurrentTime();
    status = waitForSuccessfulFinish(1, &queue, &event);
    if (status == CL_SUCCESS) {
        time = getCurrentTime() - time;
    }
    else {
        cerr << "Waiting for completion of commands to the queue failed, "
                "status = " << status << endl;
        time = NANOTIME_ERR;
    }
#endif
    return time;
}