Esempio n. 1
0
bool CudaCompiler::runCompiler( const std::string& cubinFile, 
                                const std::string& finalOpts)
{
  std::string logFile = m_cachePath + "/compile.log";
  
  std::string cmd = s_nvccCommand + " -o \"" + cubinFile + 
                    "\" -include \"" + m_cachePath + "/defines.inl\" " + 
                    + " -include cuda.h " +
                    finalOpts + " \"" + 
                    m_sourceFile +  
                    "\" 2>>\"" + logFile + "\"";

  initLogFile( logFile, cmd);
  
  if (system(cmd.c_str()) != 0 || !fileExists(cubinFile)) 
  {
    setLoggedError("CudaCompiler: Compilation failed!", logFile);
    return false;
  }

#if SHOW_NVCC_OUTPUT
  setLoggedError("", logFile);
  printf( "%s\n", getError().c_str());
  clearError();
#endif

  return true;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    VSingleInstanceGuard guard;
    bool canRun = guard.tryRun();

    QTextCodec *codec = QTextCodec::codecForName("UTF8");
    if (codec) {
        QTextCodec::setCodecForLocale(codec);
    }

    QApplication app(argc, argv);

    // The file path passed via command line arguments.
    QStringList filePaths = VUtils::filterFilePathsToOpen(app.arguments().mid(1));

    if (!canRun) {
        // Ask another instance to open files passed in.
        if (!filePaths.isEmpty()) {
            guard.openExternalFiles(filePaths);
        } else {
            guard.showInstance();
        }

        return 0;
    }

    VConfigManager vconfig;
    vconfig.initialize();
    g_config = &vconfig;

#if defined(QT_NO_DEBUG)
    for (int i = 1; i < argc; ++i) {
        if (!qstrcmp(argv[i], "-d")) {
            g_debugLog = true;
            break;
        }
    }

    initLogFile(vconfig.getLogFilePath());
#endif

    qInstallMessageHandler(VLogger);

    QString locale = VUtils::getLocale();
    // Set default locale.
    if (locale == "zh_CN") {
        QLocale::setDefault(QLocale(QLocale::Chinese, QLocale::China));
    }

    qDebug() << "command line arguments" << app.arguments();
    qDebug() << "files to open from arguments" << filePaths;

    // Check the openSSL.
    qDebug() << "openSSL" << QSslSocket::sslLibraryBuildVersionString()
             << QSslSocket::sslLibraryVersionNumber();

    // Load missing translation for Qt (QTextEdit/QPlainTextEdit/QTextBrowser).
    QTranslator qtTranslator1;
    if (qtTranslator1.load("widgets_" + locale, ":/translations")) {
        app.installTranslator(&qtTranslator1);
    }

    QTranslator qtTranslator2;
    if (qtTranslator2.load("qdialogbuttonbox_" + locale, ":/translations")) {
        app.installTranslator(&qtTranslator2);
    }

    QTranslator qtTranslator3;
    if (qtTranslator3.load("qwebengine_" + locale, ":/translations")) {
        app.installTranslator(&qtTranslator3);
    }

    // Load translation for Qt from resource.
    QTranslator qtTranslator;
    if (qtTranslator.load("qt_" + locale, ":/translations")) {
        app.installTranslator(&qtTranslator);
    }

    // Load translation for Qt from env.
    QTranslator qtTranslatorEnv;
    if (qtTranslatorEnv.load("qt_" + locale, "translations")) {
        app.installTranslator(&qtTranslatorEnv);
    }

    // Load translation for vnote.
    QTranslator translator;
    if (translator.load("vnote_" + locale, ":/translations")) {
        app.installTranslator(&translator);
    }

    VPalette palette(g_config->getThemeFile());
    g_palette = &palette;

    VMainWindow w(&guard);
    QString style = palette.fetchQtStyleSheet();
    if (!style.isEmpty()) {
        app.setStyleSheet(style);
    }

    w.show();

    w.openStartupPages();

    w.openFiles(filePaths);

    w.promptNewNotebookIfEmpty();

    return app.exec();
}
Esempio n. 3
0
bool SkinGroup::initConfiguration(yarp::os::Property &conf) {
  
  //int s = conf.size();
  //this->groupName = conf.get(0).asString().c_str();
  
  yarp::os::Value v = conf.find("groupname");
  
  if(v.isNull()) {
    printf("Not Group Name specified\n");
    return false;
  }
  else {
    this->groupName = v.asString().c_str();
  }
  
  
  initLogFile(conf);
  
  yarp::os::Value v2 = conf.find("parts");
  
  if(v2.isNull()) {
    return false;
  }
  else {
    // add all parts to this group
    
    if(!initSensors(conf)) {
      cerr << "ERROR: initSensors error. (SkinGroup)" << endl;
      return false;
    }
  }
  
  /*
    for (int j = 1; j < conf.size(); j++)
    {
    cout << conf.get(j).asString() << endl;
    int k = 0;
    for (k = 0; k < parts->size(); k++)
    {
    if (parts->at(k)->getPartName() == string(
    conf.get(j).asString().c_str()))
    {
    cout << "part : " << parts->at(k)->getPartName().c_str()
    << " is found and added to SkinGroup  "
    << this->groupName << endl;
    this->skinParts.push_back(parts->at(k));
    break;
    }
    }
    if (k == parts->size())
		{
		// Not found. Error
		cerr << "Sensor " << conf.get(j).asString().c_str()
		<< " for group " << this->groupName << " is not available."
					<< endl;
			return false;
		}
	}
	// not necessary. just to double check
	if (this->skinParts.size() != conf.size() - 1)
	{
		// Not found. Error
		cerr << "Not all sensors in sensorgroup " << this->groupName
				<< " are available. Check the config files" << endl;
		return false;
	}
  */
  cout << "OK. Sensors added for sensorgroup " << this->groupName << endl;
  
  // init other settings, e.g. offsets for each sensor in the whole data set
  
  taxelDimension = 0;
  for (size_t k = 0; k < skinParts.size(); k++)
    {
      offsets.push_back(taxelDimension);
      taxelDimension += skinParts[k]->getAllNumTaxels();
    }
  
  // other variables
  
  tempTactileData = new TactileData(taxelDimension);
  
  // load svm model file
  // TODO:
  yarp::os::ConstString _svmmodelfile = conf.find("svmmodel").asString();
  _svmmodelfile = conf.check("svmmodelfilepath", yarp::os::Value("traindata"), "").asString() + FILESEPARATOR + _svmmodelfile;
  
  this->svmmodelfile = _svmmodelfile.c_str();
  
  cout << "SKINGROUP : " << this->groupName << " has " << this->taxelDimension << " taxels" << endl;
  //this->classification = new TactileClassificationRawData(this->taxelDimension);
  this->classification = new TactileClassificationHist(this->taxelDimension);
  if(!this->classification->loadSVMModel(svmmodelfile.c_str()))
    {
      cout << "ERROR: cannot load SVMModel file " << svmmodelfile.c_str() << endl;
      return false;
    }
  
  yarp::os::Property custProp;
  custProp.put("normalisation", "none");
  custProp.put("hist_num_bins", 20);
  classification->customConfiguration(custProp);
  
  tState = new TactileState(TIME_DIMENSION, taxelDimension, 50);
  
  // init port for output broadcasting
  initOutport(conf);
  return true;
}
Esempio n. 4
0
bool CudaCompiler::runPreprocessor(std::string& cubinFile, std::string& finalOpts)
{
  // Preprocess.
  finalOpts = "";
  
  if (s_staticOptions.length()) {
    finalOpts += s_staticOptions + " ";
  }
  finalOpts += m_options;

  std::string logFile = m_cachePath + "/preprocess.log";
  
  std::string cmd = s_nvccCommand + " -E -o \"" + m_cachePath + "/preprocessed.cu\" " +
                    "-include \"" + m_cachePath + "/defines.inl\" " + 
                    finalOpts + " \"" + m_sourceFile + 
                    "\" 2>>\"" + logFile + "\"";

  initLogFile( logFile, cmd);
  
  if (0 != system(cmd.c_str()))
  {
    setLoggedError("CudaCompiler: Preprocessing failed!", logFile);
    return false;
  }

  // Specify binary format.
  if (s_staticBinaryFormat.length()) {
    finalOpts += s_staticBinaryFormat;
  } else {
    finalOpts += "-cubin";
  }
  finalOpts += " ";

  
  U32 hashA = FW_HASH_MAGIC;
  U32 hashB = FW_HASH_MAGIC;
  U32 hashC = FW_HASH_MAGIC;
  
  // Override SM architecture.
  S32 smArch = m_overriddenSMArch;
  if (!smArch) {
    smArch = CudaModule::getComputeCapability();
  }

  finalOpts = removeOption(finalOpts, "-arch", true);
  finalOpts = removeOption(finalOpts, "--gpu-architecture", true);
  
  char smArch_str[32];
  sprintf(smArch_str, "-arch sm_%d ", smArch);
  finalOpts += std::string(smArch_str);

  // Override pointer width.
  // CUDA 3.2 => requires -m32 for x86 build and -m64 for x64 build.
  if (CudaModule::getDriverVersion() >= 32)
  {
    finalOpts = removeOption(finalOpts, "-m32", false);
    finalOpts = removeOption(finalOpts, "-m64", false);
    finalOpts = removeOption(finalOpts, "--machine", true);

#if FW_64
    finalOpts += "-m64 ";
#else
    finalOpts += "-m32 ";
#endif
  }
    
  // Hash final compiler options and version.
  hashA += hash<std::string>(finalOpts);
  hashB += s_nvccVersionHash;
  FW_JENKINS_MIX(hashA, hashB, hashC);
  
  // File's timestamp hash to recompile when modified.
  U64 hashD = getFileTimeStamp( m_sourceFile );
  
  std::string fileName = hashToString(hashB) + 
                         hashToString(hashC) +
                         hashToString(hashD);
  
  cubinFile = m_cachePath + "/" + fileName + ".cubin";
  
  return true;
}
Esempio n. 5
0
int main(int argc, char * argv[]) {
  //check comand line paremeters
  if (argc < 10) {
	  printf("usage: client ip port requestfilename requestNum cancelOrStop(1 is cancel, 0 is stop) netinterface filterExpression serverbandstatus sleepTime\n");
	  return 1;
  }
  // check cancel parameter
  int isCancel = 0;
  char *prefix = argv[8];
  int sleepTime = atoi(argv[9]);
  if (strcmp(argv[5], "1") == 0) {
	isCancel = 1;
  }
  //init logFile
  char logFile[FILE_NAME_SIZE] = {0};
  if (initLogFile(logFile, sizeof logFile -1, isCancel, prefix) != 0) {
	fprintf(stderr, "init logfile failed\n");
	return 1;
  }
  printf("isCancel:%d\n", isCancel);
  printf("log file name is %s\n", logFile);
  struct ClientSockInfo sockInfo;
  if (initClientSockInfo(&sockInfo, argv[1], argv[2]) == 0) {
	printf("init client sockinfo successfully\n");
  } else {
	fprintf(stderr, "init client sockinfo failed\n");
	return 1;
  }
  char * requestFileName = argv[3];
  int requestNum = atoi(argv[4]);
  //init sniffPanel
  struct SniffPanel sniffPanel;
  sniffPanel.device = argv[6];
  sniffPanel.filterExpression = argv[7];
  sniffPanel.liveReadTimeOut = 2000;//default 2000 ms
  sniffPanel.payloadFilePath = NULL;
  sniffPanel.payloadFile = NULL;
  sniffPanel.cbAfterSniff = &cbAfterSniff;
  sniffPanel.cbWhenError  = &cbForSniffError;
  sniffPanel.cbLog        = &cbForSniffLog;
  sniffPanel.afterSniffArgs = (void *)logFile;
  sniffPanel.errorArgs      = NULL;
  sniffPanel.isStopped      = 1;
  if (initSniff(&sniffPanel) != 0) {
	fprintf(stderr, "init packet sniff error\n");
	return 1;
  } else {
	printf("finish initializing packet sniff\n");
  }
  pthread_t sniffThread;
  int i = 0;
  while (i < requestNum) {
	if (!sniffPanel.isStopped) {
	  printf("we need to stop the last sniff before starting new round\n");
	  if (stopSniff(&sniffPanel) != 0) {
		fprintf(stderr, "stop sniff failed\n");
		continue;
	  } else {
		printf("finish stopping the last sniff before starting new round\n");
	  }
	}
	i++;
    printf("round %d\n", i);
	//create connection to server
	//if (i == 1 || !isCancel) {
	//  if (createNewConn(&sockInfo) != 0) {
	//	fprintf(stderr, "create new connection failed \n");
	//	return 1;
	//  } else {
	//	printf("connect to server %s:%d successfully from port %d\n", sockInfo.serverIpStr, sockInfo.serverPort, sockInfo.clientPort);
	//  }
	//}
	if (createNewConn(&sockInfo) != 0) {
      i--;
	  fprintf(stderr, "create new connection failed \n");
      continue;
	} else {
	  printf("connect to server %s:%d successfully from port %d\n", sockInfo.serverIpStr, sockInfo.serverPort, sockInfo.clientPort);
	}

	//configure packet sniff and start thread
	sniffPanel.packetNum      = 0;
	sniffPanel.payloadSize    = 0;
	sniffPanel.isStopped      = 0;
	pthread_create(&sniffThread, NULL, sniffThreadFunc, (void *)&sniffPanel);

	printf("finish starting thread for sniff\n");
	//send request
	if (sendRequest(&sockInfo, requestFileName, strlen(requestFileName)) == 0) {
	  printf("send request successfully\n");
	} else {
	  fprintf(stderr, "send request failed\n");
	  shutdown(sockInfo.clientSockFd, SHUT_RDWR);
      i--;
      continue;
	}

	//receive response within random time
	int randomSecs = generateRandom(RANDOM_RANGE);
	randomSecs += 10;
	sockInfo.recvedBytes = 0;
	printf("start to recv within %d seconds\n", randomSecs);
	if (recvWithInRandom(&sockInfo, randomSecs) == 0) {
	  printf("recv %d KB in %d seconds\n", sockInfo.recvedBytes / 1024, randomSecs);
	} else {
	  fprintf(stderr, "recv failed in round %d with random %d\n", i, randomSecs);
	  shutdown(sockInfo.clientSockFd, SHUT_RDWR);
      i--;
      continue;
	}


	//send cancel or close signal
	const char *signal = isCancel? STOP_MSG : CLOSE_MSG;
	if (sendRequest(&sockInfo, signal, strlen(signal)) == 0) {
	  printf("finish sending signal : %s\n", signal);
	} else {
	  fprintf(stderr, "failed to send signal\n");
	  shutdown(sockInfo.clientSockFd, SHUT_RDWR);
      i--;
      continue;
	}

	//decide whether to close sock immediately after sending out cancel signal
	if (!isCancel) {
	  printf("shutdown for close test\n");
	  closeSock(sockInfo.clientSockFd);
	  printf("sleep for %d seconds in close test\n", sleepTime);
	  sleep(sleepTime);
	} else {
	  printf("continue receive for cancel test\n");
	  struct timeval timeout;
	  timeout.tv_sec = 5;
	  timeout.tv_usec = 0;
	  int recvAfterCancel = receiveFromSockUtilTimeout(sockInfo.clientSockFd, &timeout);
	  printf("recv %d KB after sending cancel signal", recvAfterCancel / 1024);
	  printf("shutdown connection for cancel test\n");
	  closeSock(sockInfo.clientSockFd);
	}

	//record log
	if (appendLog(logFile, &sockInfo, randomSecs) == 0) {
	  printf("finish appending new log\n");
	} else {
	  fprintf(stderr, "failed to append new log\n");
      i--;
      continue;
	}
	if (stopSniff(&sniffPanel) != 0) {
	  fprintf(stderr, "stop sniff failed\n");
      i--;
      continue;
	} else {
	  printf("finish stopping sniff with packets: %d, payloadSize: %d\n", sniffPanel.packetNum, sniffPanel.payloadSize / 1024);
	}
  }
}
Esempio n. 6
0
/* MainApp::OnInit
 * Application initialization, run when program is started
 *******************************************************************/
bool MainApp::OnInit()
{
	// Set locale to C so that the tokenizer will work properly
	// even in locales where the decimal separator is a comma.
	setlocale(LC_ALL, "C");

	// Init global variables
	Global::error = "";
	ArchiveManager::getInstance();
	init_ok = false;

	// Init variables
	action_invalid = new SAction("invalid", "Invalid Action", "", "Something's gone wrong here");

	// Setup system options
	wxSystemOptions::SetOption("mac.listctrl.always_use_generic", 1);

	// Set application name (for wx directory stuff)
#ifdef __WINDOWS__
	wxApp::SetAppName("SLADE3");
#else
	wxApp::SetAppName("slade3");
#endif

	// Handle exceptions using wxDebug stuff, but only in release mode
#ifdef NDEBUG
	wxHandleFatalExceptions(true);
#endif

	// Init application directories
	if (!initDirectories())
		return false;

	// Load image handlers
	wxInitAllImageHandlers();

	// Init logfile
	initLogFile();

	// Init keybinds
	KeyBind::initBinds();

	// Load configuration file
	wxLogMessage("Loading configuration");
	readConfigFile();
	Global::log_verbosity = log_verbosity;

	// Check that SLADE.pk3 can be found
	wxLogMessage("Loading resources");
	theArchiveManager->init();
	if (!theArchiveManager->resArchiveOK())
	{
		wxMessageBox("Unable to find slade.pk3, make sure it exists in the same directory as the SLADE executable", "Error", wxICON_ERROR);
		return false;
	}

	// Init lua
	Lua::init();

	// Calculate scaling factor (from system ppi)
	wxMemoryDC dc;
	Global::ppi_scale = (double)(dc.GetPPI().x) / 96.0;

	// Show splash screen
	theSplashWindow->init();
	theSplashWindow->show("Starting up...");

	// Init SImage formats
	SIFormat::initFormats();

	// Load program icons
	wxLogMessage("Loading icons");
	loadIcons();

	// Load program fonts
	Drawing::initFonts();

	// Load entry types
	wxLogMessage("Loading entry types");
	EntryDataFormat::initBuiltinFormats();
	EntryType::loadEntryTypes();

	// Load text languages
	wxLogMessage("Loading text languages");
	TextLanguage::loadLanguages();

	// Init text stylesets
	wxLogMessage("Loading text style sets");
	StyleSet::loadResourceStyles();
	StyleSet::loadCustomStyles();

	// Init colour configuration
	wxLogMessage("Loading colour configuration");
	ColourConfiguration::init();

	// Init nodebuilders
	NodeBuilders::init();

	// Init game executables
	Executables::init();

	// Init actions
	initActions();
	theMainWindow;

	// Init base resource
	wxLogMessage("Loading base resource");
	theArchiveManager->initBaseResource();
	wxLogMessage("Base resource loaded");

	// Show the main window
	theMainWindow->Show(true);
	SetTopWindow(theMainWindow);
	theSplashWindow->SetParent(theMainWindow);
	theSplashWindow->CentreOnParent();

	// Open any archives on the command line
	// argv[0] is normally the executable itself (i.e. Slade.exe)
	// and opening it as an archive should not be attempted...
	for (int a = 1; a < argc; a++)
	{
		string arg = argv[a];
		theArchiveManager->openArchive(arg);
	}

	// Hide splash screen
	theSplashWindow->hide();

	init_ok = true;
	wxLogMessage("SLADE Initialisation OK");

	// Init game configuration
	theGameConfiguration->init();

	// Show Setup Wizard if needed
	if (!setup_wizard_run)
	{
		SetupWizardDialog dlg(theMainWindow);
		dlg.ShowModal();
		setup_wizard_run = true;
	}

	// Check for updates
#ifdef __WXMSW__
	wxHTTP::Initialize();
	if (update_check)
		checkForUpdates(false);
#endif

	// Bind events
	Bind(wxEVT_MENU, &MainApp::onMenu, this);
	Bind(wxEVT_COMMAND_VERSIONCHECK_COMPLETED, &MainApp::onVersionCheckCompleted, this);

	return true;
}
Esempio n. 7
0
File: main.c Progetto: dud3/ELEVATOR
int main(int argc, char **argv) {

  int size, rank, rc, root = 0, nameLength = 20;

  MPI_Status status;
  MPI_File configFile = malloc(sizeof configFile);
  MPI_Info info;
  char *configFileName = "./configFile.txt";

  createLogFile();

  MPI_Init(&argc, &argv);
  
  initLogFile();

  MPI_Info_create(&info);

  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  printf("%d/%d started.\n", rank+1, size);

  char buf[nameLength + 1];

  rc = MPI_File_open(MPI_COMM_WORLD, configFileName,
                     MPI_MODE_RDONLY, info, &configFile);

  printf("%d/%d achieved the file_open result: %d.\n", rank+1, size, rc);

  // set the individual pointer to our position in the config file
  // master is the master of elevators
  rc = MPI_File_seek(configFile, rank * nameLength, MPI_SEEK_SET);
 
  rc = MPI_File_read(configFile, buf, nameLength, MPI_CHAR, &status);
  buf[nameLength] = '\0';
  int len = nameLength - 1;
  while ((len >= 0) && (buf[len] == ' ')) {
    buf[len] = '\0';
    len--;
  }

  rc = MPI_File_close(&configFile);

  char *ourname = buf;

  char str[50 + nameLength];
  printf(strcat (strcat (strcpy (str, "%d/%d has the name '"), ourname), "'.\n"), rank+1, size);

  //read in the file to be counted, line by line.
  FILE * fp;
  fp = fopen(argv[1], "r");

  if (fp == NULL) {
      printf("%d/%d did not find a document to count! Switching to assignment part 1.\n", rank+1, size);
    assgn = 1;
  } else {
    printf("%d/%d found a document to count. Switching to assignment part 2.\n", rank+1, size);
    assgn = 2;

      /*
      
      // general idea:

    char * line = NULL;
    size_t lineLen = 0;
    ssize_t read;
  
    dlist* list = NULL;
    dlist_create(10, &list);
    printf("size of list is %d\n", list->size);

    for (int c = 0; c < 15; c++) {
        char buf[6]; // long enough for test + num, e.g. test1
        sprintf(buf, "test%d", c);
      dlist_append(&list, buf);
    }

    char* thestring;

    printf("capacity is %d\n", list->capacity);
    for (int c = 0; c < 15; c++) {
      dlist_get(&list, c, &thestring);
      printf("string is: %s\n", thestring);
    }



    while ((read = getline(&line, &lineLen, fp)) != -1) {
      printf("Retrieved line of length %zu :\n", read);
      printf("%s", line);
    }
  
    if (line)
      free(line);

      */

    char * line = NULL;
    size_t lineLen = 0;
    ssize_t read;
  
    dlist_create(10, &list);

      // go through the lines in the file...

    int i = 0;

    while ((read = getline(&line, &lineLen, fp)) != -1) {
        i++;
        
        // ... and map them to the individual worker threads
        if (i % (size-1) == rank-1) {
        dlist_append(&list, line);
        }
    }
  
    if (line)
      free(line);
  }
  
  // we check whether or not we are the root process.
  if (rank == root) {
    master(rank);
  }
  else {
    worker(rank, ourname);
  }
 
  closeLogFile();
  
  printf("%d/%d ended.\n", rank+1, size);

  MPI_Finalize();
}