Ejemplo n.º 1
0
void CPUMiner::Init()
{
	if (globalconfs.coin.cputhreads == 0)
	{
#ifdef CPU_MINING_ONLY
		cout << "Config warning: cpu_mining_threads 0" << endl;
#endif
		return;
	}
	const string DEFAULT_ALGORITHM = "hp7";
	
	//mtrlt init functions
	const uint MAX_PRIME_VALUE = 1000000;
	Primes::Generate(MAX_PRIME_VALUE);
	const uint MIN_CHAIN_LENGTH = 6;
	Sieve::Generate(MAX_SIEVE_AMOUNT,MIN_CHAIN_LENGTH);
	
	//hp7 init functions
	GeneratePrimeTable();
	
	map<string,void*(*)(void*)> funcs;
	if(globalconfs.coin.protocol == "primecoin")
	{
		funcs["hp7"] = Reap_CPU_XPM_hp7;
		funcs["mtrlt"] = Reap_CPU_XPM_mtrlt;
	}
	cout << "Available CPU mining algorithms: ";
	for(map<string,void*(*)(void*)>::iterator it=funcs.begin(); it!=funcs.end(); ++it)
	{
		if (it!=funcs.begin())
			cout << ", ";
		cout << it->first;
	}
	cout << endl;

	void*(*cpualgo)(void*) = funcs[globalconfs.coin.cpu_algorithm];

	if (cpualgo == NULL)
	{
		if (globalconfs.coin.cpu_algorithm != "")
			cout << "CPU algorithm " << globalconfs.coin.cpu_algorithm << " not found." << endl;
		cout << "Using default: " << DEFAULT_ALGORITHM << endl;
		cpualgo = funcs[DEFAULT_ALGORITHM];
	}
	else
		cout << "Using CPU algorithm: " << globalconfs.coin.cpu_algorithm << endl;

	for(uint i=0; i<globalconfs.coin.cputhreads; ++i)
	{
		Reap_CPU_param state;
		pthread_mutex_t initializer = PTHREAD_MUTEX_INITIALIZER;

		state.share_mutex = initializer;
		state.shares_available = false;

		state.hashes = 0;

		state.thread_id = i|0x80000000;

		CPUstates.push_back(state);
	}
	
	cout << "Creating " << CPUstates.size() << " CPU thread" << (CPUstates.size()==1?"":"s") << "." << endl;
	for(uint i=0; i<CPUstates.size(); ++i)
	{
		cout << i+1 << "...";
		pthread_attr_t attr;
	    pthread_attr_init(&attr);
		int schedpolicy;
		pthread_attr_getschedpolicy(&attr, &schedpolicy);
		int schedmin = sched_get_priority_min(schedpolicy);
		int schedmax = sched_get_priority_max(schedpolicy);
		if (i==0 && schedmin == schedmax)
		{
			cout << "Warning: can't set thread priority" << endl;
		}
		sched_param schedp;
		schedp.sched_priority = schedmin;
		pthread_attr_setschedparam(&attr, &schedp);

		pthread_create(&CPUstates[i].thread, &attr, cpualgo, (void*)&CPUstates[i]);
		pthread_attr_destroy(&attr);
	}
	cout << "done" << endl;
}
Ejemplo n.º 2
0
/*********************************
* main - this is where it begins
*********************************/
int main(int argc, char **argv)
{
  std::cout << "********************************************" << std::endl;
  std::cout << "*** Xolominer - Primecoin Pool Miner v" << VERSION_MAJOR << "." << VERSION_MINOR << " " << VERSION_EXT << std::endl;
  std::cout << "*** by xolokram/TB - www.beeeeer.org - glhf" << std::endl;
  std::cout << "***" << std::endl;
  std::cout << "*** thx to Sunny King & mikaelh" << std::endl;
  std::cout << "*** press CTRL+C to exit" << std::endl;
  std::cout << "********************************************" << std::endl;

  t_start = boost::posix_time::second_clock::universal_time();
  running = true;

#if defined(__MINGW32__) || defined(__MINGW64__)
  SetConsoleCtrlHandler(ctrl_handler, TRUE);
#elif defined(__GNUG__)
  set_signal_handler(SIGINT, ctrl_handler);
#endif //TODO: __APPLE__

  if (argc < 2)
  {
    std::cerr << "usage: " << argv[0] <<
    " -poolfee=<fee-in-%> -poolip=<ip> -poolport=<port> -pooluser=<user> -poolpassword=<password>" <<
    std::endl;
    return EXIT_FAILURE;
  }

  const int atexit_res = std::atexit(exit_handler);
  if (atexit_res != 0)
    std::cerr << "atexit registration failed, shutdown will be dirty!" << std::endl;

  // init everything:
  ParseParameters(argc, argv);

  socket_to_server = NULL;
  pool_share_minimum = (unsigned int)GetArg("-poolshare", 7);
  thread_num_max = GetArg("-genproclimit", 1); // what about boost's hardware_concurrency() ?
  fee_to_pay = GetArg("-poolfee", 3);
  miner_id = GetArg("-minerid", 0);

  if (thread_num_max == 0 || thread_num_max > MAX_THREADS)
  {
    std::cerr << "usage: " << "current maximum supported number of threads = " << MAX_THREADS << std::endl;
    return EXIT_FAILURE;
  }

  if (fee_to_pay == 0 || fee_to_pay > 100)
  {
    std::cerr << "usage: " << "please use a pool fee between [1 , 100]" << std::endl;
    return EXIT_FAILURE;
  }

  if (miner_id > 65535)
  {
    std::cerr << "usage: " << "please use a miner id between [0 , 65535]" << std::endl;
    return EXIT_FAILURE;
  }

  fPrintToConsole = true; // always on
  fDebug          = GetBoolArg("-debug");

  pindexBest = new CBlockIndex();

  GeneratePrimeTable();

  // ok, start mining:
  CBlockProviderGW* bprovider = new CBlockProviderGW();
  CMasterThread *mt = new CMasterThread(bprovider);
  mt->run();

  // end:
  return EXIT_SUCCESS;
}