示例#1
0
int TaskBroker::readFromFile( const char *fname ) 
{
	if ( fname == 0 )
		return 0;

	QFile *file = new QFile( fname );

	if( file == 0 ) {
		warning( "out of memory creating file object");
		return 0;
	}

	if( !file->open( IO_ReadOnly ) ) {
		// file open error
		emit fileError( fname );
		delete file;
		return 0;
	}

	_taskList->setAutoDelete( TRUE );
	_taskList->clear();

	char *line = new char[T_LINESIZE+1];

	if( line == 0 ) {
		delete file;
		warning("out of memory creating string.");
		return 0;
	}

	while( !file->atEnd() ) {
		Task *newTask;

		if ( file->readLine( line, T_LINESIZE ) == 0 )
			break;

		newTask = readTask( line );

		if( newTask != 0 )
			_taskList->append( newTask );
	}

	file->close();
	_taskList->first();

	delete file;
	delete[] line;

	return _taskList->count();
}
示例#2
0
int main(int argc, char* argv[])
{
	//==================================================//
    // Check to make sure enough arguments are input:   //
    //==================================================//    
    if (argumentCheck(argc, argv) != 0) {
        return -1;
    }

	//==================================================//
    // Open USB HID:		                            //
    //==================================================//
    if (hidOpen() != 0) {
        return -1;
    }

	//==================================================//
    // Create Log File:                                 //
    //==================================================//
    if (logSetup(argv) != 0) {
        return -1;
    }

	//==================================================//
    // System ready...                                  //
    //==================================================//
    printf("\nREADY! Now logging...\n\n");

    //==================================================//
    // Run until error or user-terminated:              //
    //==================================================//
    int run = 1;
	while (run) {
		readTask();
		run = KB.kbhit() ? 0 : 1;
	}

	//==================================================//
    // Closing house-keeping tasks:                     //
    //==================================================//
	hid_close(hHID);
	fclose(fOutput);
	hid_exit();

	return EXIT_SUCCESS;
}
示例#3
0
int main(int argc, char ** argv)
{
	int i, j, counter, order;
	double * current = NULL, * old = NULL, * test = NULL, sum_test;
	
	// Setup:
	// TaskDescriptor has all the info read from the input
	TaskDescriptor * task = readTask(stdin);
	current = malloc(sizeof(double) * task->VECTOR.order);
	old = malloc(sizeof(double) * task->VECTOR.order);
	test = malloc (sizeof(double) * (task->VECTOR.order + 1) );

	// test vector saves the original values of the matrix row and the value required from the vector for testing
	// after the algorithm has ended.
	// Since we only test one row, this is a good approach to save memory
	memcpy(test, task->MATRIX.value[task->ROW_TEST], sizeof(double) * task->MATRIX.order);
	test[task->VECTOR.order] = task->VECTOR.value[task->ROW_TEST];

	/* Start of the algorithm */

	// Initiate the matrix by dividing each value by the diagonal value and setting the diagonal value as 0
	for (i = 0; i < task->MATRIX.order; ++i)
	{
		int diagonal_value = task->MATRIX.value[i][i];
		for (j = 0; j < task->MATRIX.order; j++)
				task->MATRIX.value[i][j] /= diagonal_value;
		task->VECTOR.value[i] /=  diagonal_value;
		task->MATRIX.value[i][i] = 0;
	}
	memcpy (current, task->VECTOR.value, sizeof(double) * task->VECTOR.order);
	order = task->VECTOR.order;

	
	for (counter = 0; counter < task->ITE_MAX; )
	{
		double max_dif, max_value, error, value;
		swap_vectors(&old, &current);

		for (i = 0; i < order; ++i)
		{
			double sum = 0.0;
			for (j = 0; j < order; ++j)
			{
				// We know value[i][i] is 0, it won't change the value
				// Faster to do 1 mult and 1 addition once than an if for every value
				sum += (task->MATRIX.value[i][j] * old[j]);
			}
			current[i] = task->VECTOR.value[i] - sum;
		}

		// We have ended the iteration, we increase the counter here
		// so that if we break out of the for loop the counter will be correct
		++counter;

		// Calculate the error
		// Its calculated as
		// error_i = Max(Dif[0], Dif[1], ... , Dif[n-1]) / Max(Abs(x[0]_i, x[1]_i, ..., x[n-1]_i))
		// where Dif[i] = Abs(x[i]_k - x[i]_(k-1))
		max_dif = fabs(current[0] - old[0]);
		max_value = fabs(current[0]);
		for (i = 1; i < order; ++i)
		{
			value = fabs(current[i] - old[i]);
			if (value > max_dif) max_dif = value;
			value = fabs(current[i]);
			if (value > max_value) max_value = value;
		}

		error = max_dif/max_value;
		if (error < task->ERROR)
			break;


	}

	/* End of the algorithm */

	/* Tests and output */
	sum_test = 0.0;
	for (i = 0; i < order; ++i)
	{
		sum_test += current[i] * test[i];
	}

	printf("---------------------------------------------------------\n" 
		"Iterations: %d\n" 
		"RowTest: %d => [%f] =? %f\n"
		"---------------------------------------------------------\n",
		counter, task->ROW_TEST, sum_test, test[order]);



	freeTask(&task);
	if (current) free(current);
	if (old) free (old);
	if (test) free(test);

	return 0;
}
示例#4
0
/// This is where the link is actually performed.
bool Driver::link(const TargetInfo &targetInfo) {
  // Honor -mllvm
  if (!targetInfo.llvmOptions().empty()) {
    unsigned numArgs = targetInfo.llvmOptions().size();
    const char **args = new const char*[numArgs + 2];
    args[0] = "lld (LLVM option parsing)";
    for (unsigned i = 0; i != numArgs; ++i)
      args[i + 1] = targetInfo.llvmOptions()[i];
    args[numArgs + 1] = 0;
    llvm::cl::ParseCommandLineOptions(numArgs + 1, args);
  }

  // Read inputs
  ScopedTask readTask(getDefaultDomain(), "Read Args");
  std::vector<std::vector<std::unique_ptr<File>>> files(
      targetInfo.inputFiles().size());
  size_t index = 0;
  std::atomic<bool> fail(false);
  TaskGroup tg;
  for (const auto &input : targetInfo.inputFiles()) {
    if (targetInfo.logInputFiles())
      llvm::outs() << input.getPath() << "\n";

    tg.spawn([ &, index]{
      if (error_code ec = targetInfo.readFile(input.getPath(), files[index])) {
        llvm::errs() << "Failed to read file: " << input.getPath() << ": "
                     << ec.message() << "\n";
        fail = true;
        return;
      }
    });
    ++index;
  }
  tg.sync();
  readTask.end();

  if (fail)
    return true;

  InputFiles inputs;
  for (auto &f : files)
    inputs.appendFiles(f);

  // Give target a chance to add files.
  targetInfo.addImplicitFiles(inputs);

  // assign an ordinal to each file so sort() can preserve command line order
  inputs.assignFileOrdinals();

  // Do core linking.
  ScopedTask resolveTask(getDefaultDomain(), "Resolve");
  Resolver resolver(targetInfo, inputs);
  if (resolver.resolve()) {
    if (!targetInfo.allowRemainingUndefines())
      return true;
  }
  MutableFile &merged = resolver.resultFile();
  resolveTask.end();

  // Run passes on linked atoms.
  ScopedTask passTask(getDefaultDomain(), "Passes");
  PassManager pm;
  targetInfo.addPasses(pm);
  pm.runOnFile(merged);
  passTask.end();

  // Give linked atoms to Writer to generate output file.
  ScopedTask writeTask(getDefaultDomain(), "Write");
  if (error_code ec = targetInfo.writeFile(merged)) {
    llvm::errs() << "Failed to write file '" << targetInfo.outputPath()
                 << "': " << ec.message() << "\n";
    return true;
  }

  return false;
}
示例#5
0
/// This is where the link is actually performed.
bool Driver::link(const LinkingContext &context, raw_ostream &diagnostics) {
  // Honor -mllvm
  if (!context.llvmOptions().empty()) {
    unsigned numArgs = context.llvmOptions().size();
    const char **args = new const char *[numArgs + 2];
    args[0] = "lld (LLVM option parsing)";
    for (unsigned i = 0; i != numArgs; ++i)
      args[i + 1] = context.llvmOptions()[i];
    args[numArgs + 1] = 0;
    llvm::cl::ParseCommandLineOptions(numArgs + 1, args);
  }
  InputGraph &inputGraph = context.inputGraph();
  if (!inputGraph.numFiles())
    return false;

  // Read inputs
  ScopedTask readTask(getDefaultDomain(), "Read Args");
  std::vector<std::vector<std::unique_ptr<File> > > files(
      inputGraph.numFiles());
  size_t index = 0;
  std::atomic<bool> fail(false);
  TaskGroup tg;
  std::vector<std::unique_ptr<LinkerInput> > linkerInputs;
  for (auto &ie : inputGraph.inputElements()) {
    if (ie->kind() == InputElement::Kind::File) {
      FileNode *fileNode = (llvm::dyn_cast<FileNode>)(ie.get());
      auto linkerInput = fileNode->createLinkerInput(context);
      if (!linkerInput) {
        llvm::outs() << fileNode->errStr(error_code(linkerInput)) << "\n";
        return false;
      }
      linkerInputs.push_back(std::move(*linkerInput));
    }
    else {
      llvm_unreachable("Not handling other types of InputElements");
    }
  }
  for (const auto &input : linkerInputs) {
    if (context.logInputFiles())
      llvm::outs() << input->getUserPath() << "\n";

    tg.spawn([ &, index]{
      if (error_code ec = context.parseFile(*input, files[index])) {
        diagnostics << "Failed to read file: " << input->getUserPath() << ": "
                    << ec.message() << "\n";
        fail = true;
        return;
      }
    });
    ++index;
  }
  tg.sync();
  readTask.end();

  if (fail)
    return false;

  InputFiles inputs;

  for (auto &f : inputGraph.internalFiles())
    inputs.appendFile(*f.get());

  for (auto &f : files)
    inputs.appendFiles(f);

  // Give target a chance to add files.
  context.addImplicitFiles(inputs);

  // assign an ordinal to each file so sort() can preserve command line order
  inputs.assignFileOrdinals();

  // Do core linking.
  ScopedTask resolveTask(getDefaultDomain(), "Resolve");
  Resolver resolver(context, inputs);
  if (resolver.resolve()) {
    if (!context.allowRemainingUndefines())
      return false;
  }
  MutableFile &merged = resolver.resultFile();
  resolveTask.end();

  // Run passes on linked atoms.
  ScopedTask passTask(getDefaultDomain(), "Passes");
  PassManager pm;
  context.addPasses(pm);
  pm.runOnFile(merged);
  passTask.end();

  // Give linked atoms to Writer to generate output file.
  ScopedTask writeTask(getDefaultDomain(), "Write");
  if (error_code ec = context.writeFile(merged)) {
    diagnostics << "Failed to write file '" << context.outputPath()
                << "': " << ec.message() << "\n";
    return false;
  }

  return true;
}