Пример #1
0
bool p7142sd3c::timersStartStop(bool start) {
    boost::recursive_mutex::scoped_lock guard(_p7142Mutex);

    if (_simulate) {
        setXmitStartTime(microsec_clock::universal_time());
        return true;
    }

    // Set enabled/disabled state for all timers
    for (int i = 0; i < N_SD3C_TIMERS; i++) {
        _timerConfigs[i].setEnabled(start);
    }

    // (Re)initialize timers to establish enabled/disabled state
    if (! initTimers(start)) {
      ELOG << "***** ERROR timersStartStop(), cannot init timers *****";
      return false;
    }
        
    // Turn on Write Strobes
    P7142_REG_WRITE(_BAR2Base + MT_WR, WRITE_ON);
    usleep(p7142::P7142_IOCTLSLEEPUS);

    // Get current time
    ptime now(microsec_clock::universal_time());
    //
    // Actually start or stop the timers now
    //
    if (start) {
        DLOG << "About to start timers: " << now;
        if (_externalStartTrigger) {
            // We assume here that the external trigger is a 1 PPS signal, 
            // e.g., from GPS.
            //
            // Sleep until ~0.5 seconds after the top of a second. This gives
            // us a comfortable fraction of a second to set up timer start and 
            // know at precisely which second the timers will start. It also 
            // allows for our system clock to be off by up to 0.2 seconds.
            
            // sleep until the next 0.5 second mark
            int wake_uSec = 500000; // wake at 0.5 seconds after the top of a second
            int usecNow = now.time_of_day().total_microseconds() % 1000000;
            int sleep_uSec = (1000000 + wake_uSec - usecNow) % 1000000;
            // Timers will start at the top of the next second after we wake
            setXmitStartTime(now + microseconds(1000000 + sleep_uSec - wake_uSec));
            // Now sleep
            usleep(sleep_uSec);
            ptime beforeStart(microsec_clock::universal_time());
            DLOG << "Time just before start: " << beforeStart;
            // Set the wait-for-trigger bit so timers start at the next
            // trigger.
            P7142_REG_WRITE(_BAR2Base + MT_ADDR, ALL_SD3C_TIMER_BITS | GPS_EN);
            usleep(p7142::P7142_IOCTLSLEEPUS);
            ptime afterStart(microsec_clock::universal_time());
        } else {
            // Internal trigger: timers start immediately.
            setXmitStartTime(now);
            P7142_REG_WRITE(_BAR2Base + MT_ADDR, ALL_SD3C_TIMER_BITS | ADDR_TRIG);
            usleep(p7142::P7142_IOCTLSLEEPUS);
        }
        DLOG << "Timers/radar start time " << _radarStartTime;
    } else {
    	P7142_REG_WRITE(_BAR2Base + MT_ADDR, ALL_SD3C_TIMER_BITS);
        usleep(p7142::P7142_IOCTLSLEEPUS);
        DLOG << "Timers stopped at " << now;
    }
    
    // Turn off Write Strobes
    P7142_REG_WRITE(_BAR2Base + MT_WR, WRITE_OFF);
    usleep(p7142::P7142_IOCTLSLEEPUS);

    return true;

}
Пример #2
0
int main(int argc, char *argv[]){
	int myid, numprocs, next, namelen;

	int i;
	int rc;
	struct timespec start, end;
	double comtime;
	char processor_name[MPI_MAX_PROCESSOR_NAME];
	MPI_Status status;

	int m,n,k;
	int *V, *out;				// host copies
	int *D;						
	FILE *fp;
	if(argc != 2)
	{
		printf("Usage: knn <inputfile>\n");
		exit(1);
	}
	if((fp = fopen(argv[1], "r")) == NULL)
	{
		printf("Error open input file!\n");
		exit(1);
	}
	fscanf(fp, "%d %d %d", &m, &n, &k);

	V = (int *) malloc(m*n*sizeof(int));
	out = (int *) malloc(m*k*sizeof(int));

	for(i=0; i<m*n; i++)
	{
		fscanf(fp, "%d", &V[i]);
	}

	fclose(fp);

	MPI_Init(&argc,&argv);
	MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
	MPI_Comm_rank(MPI_COMM_WORLD,&myid);
	MPI_Get_processor_name(processor_name,&namelen);
	if(numprocs != 2) goto end;

	if(myid == 0) beforeStart(processor_name);
	MPI_Barrier(MPI_COMM_WORLD);
	if(myid == 1) beforeStart(processor_name);
	MPI_Barrier(MPI_COMM_WORLD);
	clock_gettime(CLOCK_REALTIME,&start);
	MPI_Barrier(MPI_COMM_WORLD);

	launch(myid, m, n, k, V, out);

	MPI_Barrier(MPI_COMM_WORLD);
	if(myid == 1)
	{
		rc = MPI_Send(out+(m/2)*k, (m/2)*k, MPI_INT, 0, 1, MPI_COMM_WORLD);
	}
	if(myid == 0)
	{
		rc = MPI_Recv(out+(m/2)*k, (m/2)*k, MPI_INT, 1, 1, MPI_COMM_WORLD, &status);
	}

	MPI_Barrier(MPI_COMM_WORLD);
	clock_gettime(CLOCK_REALTIME,&end);
	if(myid == 0){
		comtime = (double)(end.tv_sec-start.tv_sec)+(double)(end.tv_nsec-start.tv_nsec)/(double)1000000000L;
		showResult(m, k, out);
		printf("%f\n", comtime);
	}
	MPI_Barrier(MPI_COMM_WORLD);
	free(V);
	free(out);
	MPI_Barrier(MPI_COMM_WORLD);
end:
	MPI_Finalize();

//	free(V);
//	free(out);

	return (0);
}