Пример #1
0
/**
 * Creates a plain text (or html) email and 
 * specifies the necessary MIME types if needed
 * due to attaching base64 files.
 * when this function is done, it will rewind
 * the file position and return an open file
**/
static dstrbuf *
createPlainEmail(dstrbuf *msg) 
{
	dstrbuf *border=NULL;
	dstrbuf *buf=DSB_NEW;
	CharSetType cs;

	if (Mopts.attach) {
		border = mimeMakeBoundary();
	} else {
		border = DSB_NEW;
	}

	if (Mopts.encoding) {
		cs = getCharSet((u_char *)msg->str);
	} else {
		cs = IS_ASCII;
	}
	printHeaders(border->str, buf, cs);
	if (makeMessage(msg, buf, border->str, cs) < 0) {
		dsbDestroy(buf);
		buf=NULL;
	}
	dsbDestroy(border);
	return buf;
}
Пример #2
0
void printHomeData(ULONG ID) {
	printHeaders();
	JSON::Object obj;
	obj.add(new JSON::String("ID"), new JSON::Integer(ID));
	obj.add(new JSON::String("homeData"), new JSON::String("test"));
	obj.render();
}
Пример #3
0
void RESTClient::send(const String &name, float value)
{
    printHTTP();
    print(name);
    print(F("&value="));
    print(value);
    printHeaders();
}
Пример #4
0
void HTTPServer::notFound()
{
    if (havePacket()) {
        printHeaders(typePlain, status404);
        println(status404);
        sendReply();
    }
}
Пример #5
0
void RESTClient::send(const __FlashStringHelper *name, float value)
{
    printHTTP();
    print(name);
    print(F("&value="));
    print(value);
    printHeaders();
}
Пример #6
0
void printHelpTable(void) {
  int i = 0;
  int longestFlag = 0;
  char flagBuf[100];
  char lastHeaderType = '\0';

  printAdditionalHelp();

  for (i = 0; i < numFlags; i++) {
    int flagLen;
    if (flagList[i].flagDash[0] == '\0') {
      flagLen = 2 + strlen(flagList[i].flagDashDash);
    } else {
      if (flagList[i].flagDashDash[0] == '\0') {
        flagLen = 1 + strlen(flagList[i].flagDash) +
                  strlen(flagList[i].subArg);
      } else {
        flagLen = 1 + strlen(flagList[i].flagDash) +
                  strlen(flagList[i].subArg) +
                  2 + 2 + strlen(flagList[i].flagDashDash);
      }
    }

    if (longestFlag < flagLen) {
      longestFlag = flagLen;
    }
  }

  for (i = 0; i < numFlags; i++) {
    printHeaders(flagList[i].headerType, &lastHeaderType);
    if (flagList[i].flagDash[0] == '\0') {
      snprintf(flagBuf, sizeof(flagBuf), "--%s", flagList[i].flagDashDash);
    } else {
      if (flagList[i].flagDashDash[0] == '\0') {
        snprintf(flagBuf, sizeof(flagBuf), "-%s%s",
                 flagList[i].flagDash, flagList[i].subArg);
      } else {
        snprintf(flagBuf, sizeof(flagBuf), "-%s%s, --%s",
                 flagList[i].flagDash, flagList[i].subArg,
                 flagList[i].flagDashDash);
      }
    }

    fprintf(stdout, "  %-*s  : ", longestFlag, flagBuf);
    {
      const char* p;
      const char* pNext;
      for (p = flagList[i].description;
           (pNext = strchr(p, '\n')) != NULL;
           p = pNext + 1) {
        fprintf(stdout, "%.*s\n%*s", (int) (pNext - p), p,
                longestFlag + 6, "");
      }
      fprintf(stdout, "%s\n", p);
    }
  }
  fprintf(stdout, "\n");
}
Пример #7
0
/**
 * Creates a signed message with gpg and takes into 
 * account the correct MIME message types to add to 
 * the message.
**/
static dstrbuf *
createGpgEmail(dstrbuf *msg, GpgCallType gpg_type)
{
	dstrbuf *tmpbuf=DSB_NEW;
	dstrbuf *gpgdata=NULL, *buf=DSB_NEW;
	dstrbuf *border1=NULL, *border2=NULL;

	assert(msg != NULL);

	/* Create two borders if we're attaching files */
	border1 = mimeMakeBoundary();
	if (Mopts.attach) {
		border2 = mimeMakeBoundary();
	} else {
		border2 = DSB_NEW;
	}

	if (makeGpgMessage(msg, tmpbuf, border2->str) < 0) {
		dsbDestroy(buf);
		buf=NULL;
		goto end;
	}

	gpgdata = callGpg(tmpbuf, gpg_type);
	if (!gpgdata) {
		dsbDestroy(buf);
		buf=NULL;
		goto end;
	}
	printHeaders(border1->str, buf, IS_ASCII);

	dsbPrintf(buf, "\r\n--%s\r\n", border1->str);
	if (gpg_type & GPG_ENC) {
		dsbPrintf(buf, "Content-Type: application/pgp-encrypted\r\n\r\n");
		dsbPrintf(buf, "Version: 1\r\n");
		dsbPrintf(buf, "\r\n--%s\r\n", border1->str);
		dsbPrintf(buf, "Content-type: application/octet-stream; "
			       "name=encrypted.asc\r\n\r\n");
	} else if (gpg_type & GPG_SIG) {
		dsbPrintf(buf, "%s\r\n", tmpbuf->str);
		dsbPrintf(buf, "\r\n--%s\r\n", border1->str);
		dsbPrintf(buf, "Content-Type: application/pgp-signature\r\n");
		dsbPrintf(buf, "Content-Description: This is a digitally signed message\r\n\r\n");
	} 
	dsbPrintf(buf, "%s", gpgdata->str);
	dsbPrintf(buf, "\r\n--%s--\r\n", border1->str);

end:
	dsbDestroy(tmpbuf);
	dsbDestroy(gpgdata);
	dsbDestroy(border1);
	dsbDestroy(border2);
	return buf;
}
Пример #8
0
void avengersAssemble(AST_NODE* astTree, TAC* tacList)
{
    DEST_ASM = fopen("assembly.s", "w");
    printHeaders();
    parseGlobalVariables(astTree);
    parseStrings();
    fprintf(DEST_ASM, "\t.text\n");
    parseTAC(tacList);
    printFooter();
    fclose(DEST_ASM);
}
Пример #9
0
void printHelpTable(void) {
  typedef struct _flagType {
    const char* flag;
    const char* description;
    const char headerType;
  } flagType;

  static flagType flagList[] = {
    {"-h, --help", "print this message", 'g'},
    {"-nl <n>", "run program using n locales", 'g'},
    {"", "(equivalent to setting the numLocales config const)", 'g'},
    {"-q, --quiet", "run program in quiet mode", 'g'},
    {"-v, --verbose", "run program in verbose mode", 'g'},
    {"-b, --blockreport", "report location of blocked threads on SIGINT", 'g'},
    {"-t, --taskreport",
     "report list of pending and executing tasks on SIGINT", 'g'},
    {"--gdb", "run program in gdb", 'g'},

    {"-s, --<cfgVar>=<val>", "set the value of a config var", 'c'},    
    {"-f<filename>", "read in a file of config var assignments", 'c'},

    {NULL, NULL, ' '}
  };

  int i = 0;
  int longestFlag = 0;
  char lastHeaderType = '\0';

  printAdditionalHelp();

  while (flagList[i].flag) {
    int thisFlag = strlen(flagList[i].flag);
    if (longestFlag < thisFlag) {
      longestFlag = thisFlag;
    }
    i++;
  }

  i = 0;
  while (flagList[i].flag) {
    printHeaders(flagList[i].headerType, &lastHeaderType);
    if (flagList[i].flag[0] == '\0') {
      fprintf(stdout, "  %-*s    %s\n", longestFlag, flagList[i].flag,
              flagList[i].description);
    } else {
      fprintf(stdout, "  %-*s  : %s\n", longestFlag, flagList[i].flag, 
              flagList[i].description);
    }
    i++;
  }
  fprintf(stdout, "\n");
}
Пример #10
0
        int runNormal() {
            bool showHeaders = ! hasParam( "noheaders" );
            int rowCount = getParam( "rowcount" , 0 );
            int rowNum = 0;

            auth();

            BSONObj prev = stats();
            if ( prev.isEmpty() )
                return -1;

            int maxLockedDbWidth = 0;

            while ( rowCount == 0 || rowNum < rowCount ) {
                sleepsecs((int)ceil(_statUtil.getSeconds()));
                BSONObj now;
                try {
                    now = stats();
                }
                catch ( std::exception& e ) {
                    cout << "can't get data: " << e.what() << endl;
                    continue;
                }

                if ( now.isEmpty() )
                    return -2;

                try {

                    BSONObj out = _statUtil.doRow( prev , now );

                    // adjust width up as longer 'locked db' values appear
                    setMaxLockedDbWidth( &out, &maxLockedDbWidth ); 
                    if ( showHeaders && rowNum % 10 == 0 ) {
                        printHeaders( out );
                    }

                    printData( out , out );

                }
                catch ( AssertionException& e ) {
                    cout << "\nerror: " << e.what() << "\n"
                         << now
                         << endl;
                }

                prev = now;
                rowNum++;
            }
            return 0;
        }
Пример #11
0
 int main ()
 {
 	//call functions
    int numPlyrs;
    int plyrInfo[MAXPLYRS][NUMCOLS] ;
    
    numPlyrs = readStats(plyrInfo) ;	
    
 	//check for successful read   
    if(numPlyrs != 0)
    {
       printHeaders() ;
       printPlayerPts(plyrInfo, numPlyrs) ;
       printTeamPts(plyrInfo, numPlyrs) ;
    }
 	
    return 0 ;
 }
Пример #12
0
int main(int argc, char **argv)
{
    FILE   *fp, *fp2, *pipe;
    char   testName[32] = "MPI_Allreduce", file1[64], file2[64], pipeStr[8];
    int    dblSize, proc, nprocs, nodeCPUs, nodes;
    unsigned int i, j, size, localSize, NLOOP = NLOOP_MAX;
    unsigned int smin = MIN_COL_SIZE, smed = MED_COL_SIZE, smax = MAX_COL_SIZE;
    double tScale = USEC, bwScale = MB_8;
    double tStart, timeMin, timeMinGlobal, overhead, threshold_lo, threshold_hi;
    double msgBytes, sizeBytes, UsedMem, localMax;
    double tElapsed[NREPS], tElapsedGlobal[NREPS];
    double *A, *B;

    pipe = popen( "cat /proc/cpuinfo | grep processor | wc -l", "r" );
    fgets( pipeStr, 8, pipe ); pclose(pipe);
    nodeCPUs = atoi(pipeStr);

    // Initialize parallel environment
    MPI_Init( &argc, &argv );
    MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
    MPI_Comm_rank( MPI_COMM_WORLD, &proc );

    // Reset maximum message size to fit within node memory
    if( nprocs > nodeCPUs ){
        nodes = nprocs / nodeCPUs;
        if( smax > nodes ) smax = smax / nodes;
        if( smed > nodes ) smed = smed / nodes;
    }

    // Check for user defined limits
    checkEnvCOL( proc, &NLOOP, &smin, &smed, &smax );

    // Initialize local variables
    dblSize = sizeof(double);
    UsedMem = (double)smax*(double)dblSize*(double)( nprocs + 1 );

    // Allocate and initialize arrays
    srand( SEED );
    A = doubleVector( smax );
    B = doubleVector( smax*nprocs );

    // Open output file and write header
    if( proc == 0 ){
        // Check timer overhead in seconds
        timerTest( &overhead, &threshold_lo, &threshold_hi );
        // Open output files and write headers
        sprintf( file1, "allreduce_time-np_%.4d.dat", nprocs );
        sprintf( file2, "allreduce_bw-np_%.4d.dat",   nprocs );
        fp  = fopen( file1, "a" );
        fp2 = fopen( file2, "a" );
        printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );
    }

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup with a medium size message
    MPI_Allreduce( A, B, smed, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
    // Test is current NLOOP is enough to capture fastest test cases
    MPI_Barrier( MPI_COMM_WORLD );
    tStart = benchTimer();
    for(j = 0; j < NLOOP; j++){
        MPI_Allreduce( A, B, smin, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
    }
    timeMin = benchTimer() - tStart;
    MPI_Reduce( &timeMin, &timeMinGlobal, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
    if( proc == 0 ) resetInnerLoop( timeMinGlobal, threshold_lo, &NLOOP );
    MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD );

    //================================================================
    // Execute test for each requested size                  
    //================================================================
    localMax = 0.0;
    for( size = smin; size <= smax; size = size*2 ){

        // Warmup with a medium size message
        MPI_Allreduce( A, B, smed, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );

        // Repeat NREPS to collect statistics
        for(i = 0; i < NREPS; i++){
            MPI_Barrier( MPI_COMM_WORLD );
            tStart = benchTimer();
            for(j = 0; j < NLOOP; j++){
                MPI_Allreduce( A, B, size, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
            }
            tElapsed[i] = benchTimer() - tStart;
        }
        MPI_Reduce( tElapsed, tElapsedGlobal, NREPS, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );   
        // Only task 0 needs to do the analysis of the collected data
        if( proc == 0 ){
            // sizeBytes is size to write to file
            // msgBytes is actual data exchanged on the wire
            msgBytes  = (double)size*(double)nprocs*(double)dblSize;
            sizeBytes = (double)size*(double)dblSize;
            post_process( fp, fp2, threshold_hi, tElapsedGlobal, tScale, 
                          bwScale, size*dblSize, sizeBytes, msgBytes, &NLOOP, 
                          &localMax, &localSize );
        }
        MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD ); 
    }
    //================================================================
    // Print completion message, free memory and exit                  
    //================================================================
    if( proc == 0 ){
        fclose(fp);
        fclose(fp2);
        fprintf( stdout,"\n %s test completed.\n\n", testName );
    }
    free( A );
    free( B );

    MPI_Finalize();
    return 0;
}
Пример #13
0
int main(int argc, char **argv)
{
    FILE    *fp, *fp2;
    char    testName[32] = "MPI_Get_Fence", file1[64], file2[64];
    int     dblSize, proc, nprocs, npairs, partner;
    unsigned int i, j, k, size, localSize, NLOOP = NLOOP_MAX;
    unsigned int smin = MIN_P2P_SIZE, smed = MED_P2P_SIZE, smax = MAX_P2P_SIZE;
    double  tScale = USEC, bwScale = MB_8;
    double  tStart, timeMin, timeMinGlobal, overhead, threshold_lo, threshold_hi;
    double  msgBytes, sizeBytes, localMax, UsedMem;
    double  tElapsed[NREPS], tElapsedGlobal[NREPS];
    double  *A, *B;
    MPI_Win   win;

    // Initialize parallel environment
    MPI_Init(&argc, &argv);
    MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
    MPI_Comm_rank( MPI_COMM_WORLD, &proc );

    // Test input parameters
    if( nprocs%2 != 0 && proc == 0 )
        fatalError( "P2P test requires an even number of processors" );

    // Check for user defined limits
    checkEnvP2P( proc, &NLOOP, &smin, &smed, &smax );

    // Initialize local variables
    localMax = 0.0;
    npairs   = nprocs/2;
    if( proc < npairs  ) partner = proc + npairs;
    if( proc >= npairs ) partner = proc - npairs;
    UsedMem = (double)smax*(double)sizeof(double)*2.0;

    // Allocate and initialize arrays
    srand( SEED );
    A = doubleVector( smax );
    B = doubleVector( smax );

    // Open output file and write header
    if( proc == 0 ){
        // Check timer overhead in seconds
        timerTest( &overhead, &threshold_lo, &threshold_hi );
        // Open output files and write headers
        sprintf( file1, "getfence_time-np_%.4d.dat", nprocs );
        sprintf( file2, "getfence_bw-np_%.4d.dat",   nprocs );
        fp  = fopen( file1, "a" );
        fp2 = fopen( file2, "a" );
        printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );
    }

    // Get type size
    MPI_Type_size( MPI_DOUBLE, &dblSize );
    // Set up a window for RMA
    MPI_Win_create( A, smax*dblSize, dblSize, MPI_INFO_NULL, MPI_COMM_WORLD, &win );

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup with a medium size message
    if( proc < npairs ){
        MPI_Win_fence( 0, win );
        MPI_Get( B, smed, MPI_DOUBLE, partner, 0, smed, MPI_DOUBLE, win );
        MPI_Win_fence( 0, win );
    }else{
        MPI_Win_fence( 0, win );
        MPI_Win_fence( 0, win );
    }
    // Test if current NLOOP is enough to capture fastest test cases
    MPI_Barrier( MPI_COMM_WORLD );
    tStart = benchTimer();
    if( proc < npairs ){
        for(j = 0; j < NLOOP; j++){
            MPI_Win_fence( 0, win );
        	MPI_Get( B, smin, MPI_DOUBLE, partner, 0, smin, MPI_DOUBLE, win );
            MPI_Win_fence( 0, win );
        }
    }else{
        for(j = 0; j < NLOOP; j++){
            MPI_Win_fence( 0, win );
            MPI_Win_fence( 0, win );
        }
    }
    timeMin = benchTimer() - tStart;
    MPI_Reduce( &timeMin, &timeMinGlobal, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
    if( proc == 0 ) resetInnerLoop( timeMinGlobal, threshold_lo, &NLOOP );
    MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD );


    //================================================================
    // Execute test for each requested size                  
    //================================================================
    for( size = smin; size <= smax; size = size*2 ){

        // Warmup with a medium size message
        if( proc < npairs ){
            MPI_Win_fence( 0, win );
            MPI_Get( B, smed, MPI_DOUBLE, partner, 0, smed, MPI_DOUBLE, win );
            MPI_Win_fence( 0, win );
        }else{
            MPI_Win_fence( 0, win );
            MPI_Win_fence( 0, win );
        }

        // Repeat NREPS to collect statistics
        for(i = 0; i < NREPS; i++){
            MPI_Barrier( MPI_COMM_WORLD );
            tStart = benchTimer();
            if( proc < npairs ){
                for(j = 0; j < NLOOP; j++){
                    MPI_Win_fence( 0, win );
        	        MPI_Get( B, size, MPI_DOUBLE, partner, 0, size, MPI_DOUBLE, win );
                    MPI_Win_fence( 0, win );
                }
            }else{
                for(j = 0; j < NLOOP; j++){
                    MPI_Win_fence( 0, win );
                    MPI_Win_fence( 0, win );
                }
            }
        	tElapsed[i] = benchTimer() - tStart;
        }
        MPI_Reduce( tElapsed, tElapsedGlobal, NREPS, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
        // Only task 0 needs to do the analysis of the collected data
        if( proc == 0 ){
            // sizeBytes is size to write to file
            // msgBytes is actual data exchanged on the wire
            msgBytes  = (double)size*(double)npairs*(double)dblSize;
            sizeBytes = (double)size*(double)dblSize;
            post_process( fp, fp2, threshold_hi, tElapsedGlobal, tScale, 
                          bwScale, size*dblSize, sizeBytes, msgBytes, &NLOOP, 
                          &localMax, &localSize );
        }
        MPI_Bcast( &NLOOP, 1, MPI_INT, 0, MPI_COMM_WORLD );

    }
    MPI_Win_free( &win );
    MPI_Barrier( MPI_COMM_WORLD );
    free( A );
    free( B );

    //================================================================
    // Print completion message, free memory and exit                  
    //================================================================
    if( proc == 0 ){
        printSummary( fp2, testName, localMax, localSize );
        fclose( fp2 ); 
        fclose( fp );
    }

    MPI_Finalize();
    return 0;
}
Пример #14
0
        int runMany() {
            StateMap threads;

            {
                string orig = getParam( "host" );
                bool showPorts = false;
                if ( orig == "" )
                    orig = "localhost";

                if ( orig.find( ":" ) != string::npos || hasParam( "port" ) )
                    showPorts = true;

                StringSplitter ss( orig.c_str() , "," );
                while ( ss.more() ) {
                    string host = ss.next();
                    if ( showPorts && host.find( ":" ) == string::npos) {
                        // port supplied, but not for this host.  use default.
                        if ( hasParam( "port" ) )
                            host += ":" + _params["port"].as<string>();
                        else
                            host += ":27017";
                    }
                    _add( threads , host );
                }
            }

            sleepsecs(1);

            int row = 0;
            bool discover = hasParam( "discover" );
            int maxLockedDbWidth = 0;

            while ( 1 ) {
                sleepsecs( (int)ceil(_statUtil.getSeconds()) );

                // collect data
                vector<Row> rows;
                for ( map<string,shared_ptr<ServerState> >::iterator i=threads.begin(); i!=threads.end(); ++i ) {
                    scoped_lock lk( i->second->lock );

                    if ( i->second->error.size() ) {
                        rows.push_back( Row( i->first , i->second->error ) );
                    }
                    else if ( i->second->prev.isEmpty() || i->second->now.isEmpty() ) {
                        rows.push_back( Row( i->first ) );
                    }
                    else {
                        BSONObj out = _statUtil.doRow( i->second->prev , i->second->now );
                        rows.push_back( Row( i->first , out ) );
                    }

                    if ( discover && ! i->second->now.isEmpty() ) {
                        if ( _discover( threads , i->first , i->second ) )
                            break;
                    }
                }

                // compute some stats
                unsigned longestHost = 0;
                BSONObj biggest;
                for ( unsigned i=0; i<rows.size(); i++ ) {
                    if ( rows[i].host.size() > longestHost )
                        longestHost = rows[i].host.size();
                    if ( rows[i].data.nFields() > biggest.nFields() )
                        biggest = rows[i].data;

                    // adjust width up as longer 'locked db' values appear
                    setMaxLockedDbWidth( &rows[i].data, &maxLockedDbWidth ); 
                }

                {
                    // check for any headers not in biggest

                    // TODO: we put any new headers at end,
                    //       ideally we would interleave

                    set<string> seen;

                    BSONObjBuilder b;

                    {
                        // iterate biggest
                        BSONObjIterator i( biggest );
                        while ( i.more() ) {
                            BSONElement e = i.next();
                            seen.insert( e.fieldName() );
                            b.append( e );
                        }
                    }

                    // now do the rest
                    for ( unsigned j=0; j<rows.size(); j++ ) {
                        BSONObjIterator i( rows[j].data );
                        while ( i.more() ) {
                            BSONElement e = i.next();
                            if ( seen.count( e.fieldName() ) )
                                continue;
                            seen.insert( e.fieldName() );
                            b.append( e );
                        }

                    }

                    biggest = b.obj();

                }

                // display data

                cout << endl;

                //    header
                if ( row++ % 5 == 0 && ! biggest.isEmpty() ) {
                    cout << setw( longestHost ) << "" << "\t";
                    printHeaders( biggest );
                }

                //    rows
                for ( unsigned i=0; i<rows.size(); i++ ) {
                    cout << setw( longestHost ) << rows[i].host << "\t";
                    if ( rows[i].err.size() )
                        cout << rows[i].err << endl;
                    else if ( rows[i].data.isEmpty() )
                        cout << "no data" << endl;
                    else
                        printData( rows[i].data , biggest );
                }

            }

            return 0;
        }
Пример #15
0
void printID(ULONG ID) {
	printHeaders();
	JSON::Object obj;
	obj.add(new JSON::String("ID"), new JSON::Integer(ID));
	obj.render();
}
Пример #16
0
void printDone() {
	printHeaders();
	done.render();
}
Пример #17
0
int main(int argc, char **argv)
{
    FILE    *fp, *fp2;
    char    testName[32] = "PHI_TRANSFER_KEEP_NOAL_IN";
    int     micNum, tid;
    unsigned int i, j, size, localSize, NLOOP = NLOOP_PHI_MAX, NLOOP_PHI;
    unsigned int smin = MIN_PHI_SIZE, smed = MED_PHI_SIZE, smax = MAX_PHI_SIZE;
    double  *f0, *f0_noal, *f1, *f1_noal;
    double timeMin, tStart, tElapsed[NREPS];
    double tScale = USEC, bwScale = MB;
    double overhead, threshold_lo, threshold_hi;
    double tMin, tMax, tAvg, stdDev, bwMax, bwMin, bwAvg, bwDev;
    double UsedMem, localMax, msgBytes;
    double tMsg[NREPS], bwMsg[NREPS];

    // Identify number of MIC devices
    micNum = _Offload_number_of_devices();
    if( micNum == 0 ) fatalError( "No Xeon Phi devices found. Test Aborted." );

    // Check for user defined limits
    checkEnvPHI( &NLOOP, &smin, &smed, &smax );
    if( micNum == 1 ) UsedMem = (double)smax*sizeof(double);
    if( micNum == 2 ) UsedMem = (double)smax*2.0*sizeof(double);

    // Allocate and initialize test array
    srand( SEED );
    f0 = doubleVector( smax+1 );
    // This array is unaligned by exactly 8 bytes
    f0_noal = &f0[1];

    // Check timer overhead in seconds
    timerTest( &overhead, &threshold_lo, &threshold_hi );

    // Open output files and write headers
    fp  = fopen( "mic0_keep_noal_time_in.dat", "a" );
    fp2 = fopen( "mic0_keep_noal_bw_in.dat", "a" );
    printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup processor with a large size exchange
    // Since we will be reusing we want to make sure this exchange uses smax
    #pragma offload_transfer target(mic:0) in( f0_noal : length(smax) ALLOC KEEP )
    // Test is current NLOOP is enough to capture fastest test cases
    tStart = benchTimer();
    for(j = 0; j < NLOOP; j++){
        #pragma offload_transfer target(mic:0) in( f0_noal : length(smin) REUSE KEEP )
    }
    timeMin = benchTimer() - tStart;
    resetInnerLoop( timeMin, threshold_lo, &NLOOP );
    // Let's save this info in case we have more than one Phi device
    NLOOP_PHI = NLOOP;

    //================================================================
    // Execute test for each requested size                  
    //================================================================
    localSize = smin;
    localMax  = 0.0;
    for( size = smin; size <= smax; size = size*2 ){

        // Copy array to Phi (read/write test)
        for( i = 0; i < NREPS; i++){
            tStart = benchTimer();
            for(j = 0; j < NLOOP; j++){
                #pragma offload_transfer target(mic:0) in( f0_noal : length(size) REUSE KEEP )
            }
            tElapsed[i] = benchTimer() - tStart;
        }
        msgBytes = (double)( size*sizeof(double));
        post_process( fp, fp2, threshold_hi, tElapsed, tScale, bwScale, size,
                      msgBytes, msgBytes, &NLOOP, &localMax, &localSize );
    }
    // Print completion message                 
    printSummary( fp2, testName, localMax, localSize );
    fclose( fp2 ); 
    fclose( fp );

    if( micNum == 2 ){

    // Allocate and initialize test array for second Phi coprocessor (mic:1)
    f1 = doubleVector(smax+1);
    f1_noal = &f1[1];

    // Open output files and write headers
    fp  = fopen( "mic1_keep_noal_time_in.dat", "a" );
    fp2 = fopen( "mic1_keep_noal_bw_in.dat", "a" );
    printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );

    //================================================================
    // Single loop with minimum size to verify that inner loop length  
    // is long enough for the timings to be accurate                     
    //================================================================
    // Warmup processor with a large size exchange
    // Since we will be reusing we want to make sure this exchanges uses smax
    #pragma offload_transfer target(mic:1) in( f1_noal : length(smax) ALLOC KEEP )
    // Reset innermost loop to safe value and local quantities to defaults
    NLOOP = NLOOP_PHI;
    localSize = smin;
    localMax  = 0.0;

   //================================================================
    // Execute test for each requested size                  
    //================================================================
    for( size = smin; size <= smax; size = size*2 ){

        // Copy array to Phi (read/write test)
        for( i = 0; i < NREPS; i++){
            tStart = benchTimer();
            for(j = 0; j < NLOOP; j++){
                #pragma offload_transfer target(mic:1) in( f1_noal : length(size) REUSE KEEP )
            }
            tElapsed[i] = benchTimer() - tStart;
        }
        msgBytes = (double)( size*sizeof(double));
        post_process( fp, fp2, threshold_hi, tElapsed, tScale, bwScale, size,
                      msgBytes, msgBytes, &NLOOP, &localMax, &localSize );
    }
    // Print completion message                 
    printSummary( fp2, testName, localMax, localSize );
    fclose( fp2 ); 
    fclose( fp );

    //------- TESTING SIMULTANEOUS DATA TRANSFER TO BOTH PHI DEVICES ------

    // Open output files and write headers
    fp  = fopen( "mic0+1_keep_noal_time_in.dat", "a" );
    fp2 = fopen( "mic0+1_keep_noal_bw_in.dat", "a" );
    printHeaders( fp, fp2, testName, UsedMem, overhead, threshold_lo );

    // Warmup processor with a medium size exchange
    #pragma offload_transfer target(mic:0) in( f0_noal : length(smed) REUSE KEEP )
    #pragma offload_transfer target(mic:1) in( f1_noal : length(smed) REUSE KEEP )
    // Reset innermost loop to safe value and local quantities to defaults
    NLOOP = NLOOP_PHI;
    localSize = smin;
    localMax  = 0.0;

    //================================================================
    // Execute test for each requested size                  
    //================================================================
    for( size = smin; size <= smax; size = size*2 ){

        for( i = 0; i < NREPS; i++){
            tStart = benchTimer();
            #pragma omp parallel private(j,tid) num_threads(2)
            {
                tid = omp_get_thread_num();
                if( tid == 0 ){
                    for(j = 0; j < NLOOP; j++){
                        #pragma offload_transfer target(mic:0) in( f0_noal : length(size) REUSE KEEP )
                    }
                }
                if( tid == 1 ){
                    for(j = 0; j < NLOOP; j++){
                        #pragma offload_transfer target(mic:1) in( f1_noal : length(size) REUSE KEEP )
                    }
                }
            }
            tElapsed[i] = 0.5*( benchTimer() - tStart );
        }
        msgBytes = (double)( size*sizeof(double));
        post_process( fp, fp2, threshold_hi, tElapsed, tScale, bwScale, size,
                      msgBytes, msgBytes, &NLOOP, &localMax, &localSize );
    }
    // Print completion message                 
    printSummary( fp2, testName, localMax, localSize );
    fclose( fp2 ); 
    fclose( fp );

    }

    free( f0 );
    if( micNum == 2 ) free( f1 );
    return 0;
}
Пример #18
0
void setup(){
    
    // A visual Queue that the System is in
    // Setup Mode.
        // Pin 14 -> LED ON
    
    digitalWrite(SetupLED, HIGH);
    
// ----- PRELIMINARY PROCEDURES ------

//    -> init serial Connection to LCD
    
    initLCD();
    LCDprintln("***** Starting Up *****");
    delay(100);
    LCDprintln("  [OK]    ");

    
// ----- SPLASH SCREEN PROCEDURES ------
    
//    -> splash Screen
//      -> ask for connections 
//      -> Store USB?
    
#ifdef MEGA
    toggleSplashScreen();
    delay(1000);

    askForConnectionTypes();
    askToStoreData();
#endif
    
// ----- DEBUG STARTUP PROCEDURES ------
    
#ifdef DEBUG
    toggleSplashScreen();
    delay(1000);
    
    LCDprintln("***** DEBUG MODE *****");
    
    startDebugSequence();
#endif  

// ----- PINS // INT // ISR PROCEDURES ------    
    
    //    -> init buttons
    //    -> init LED pins
    //    -> init Digital pins
    //    -> init Sensors
    
    //    -> attach interrupts
    
#ifdef MEGA
    initbuttons();
#else
    LCDprintln("In DEBUG mode no input required");
#endif
    
#ifdef MEGA
    initLEDPins();
    initDigitalPins();
    initSensors();
#else
    LCDprintln("No need for inputs random numbers\n
             sent to the PC/XBee.");
#endif
    
    attachInterrupts();

    

// ----- COMMS STARTUP PROCEDURES ------
    
//    -> init Keyboard  
//    -> init serial Connection to XBee
//    -> init serial Connection to PC
    
#ifdef XBeeConnected
    initXbee();
    LCDdisplayConnectedIcon(Connection);
#endif

#ifdef USBConnected
    initUSB();
    LCDdisplayConnectedIcon(Connection);
#endif
    
#ifdef StoreUSB
    initVDIP();
    LCDdisplayConnectedIcon(Connection);
    printHeaders();
#endif

// ----- MEM. & MENUS STARTUP PROCEDURES ------
    
//    -> init EEPROM
//      -> +1 to session ID
//      -> Verify Version ID
//    -> init Menu System
//    -> Startup
    
    initEEPROM();
    initMenus();
    
    // A visual Queue that the System is now past
    // the Setup Mode.
    // Pin 14 -> LED OFF
    
    digitalWrite(SetupLED, LOW);
}