Esempio n. 1
0
void PrimeFinder::gatherPrimes(int method, unsigned long long size, unsigned long long blockSize) {
	NumberList *numbers = new NumberList(size);
	unsigned long long firstNumber = 3, lastNumber = size;
	
	clock_t startTime, endTime;

	if(method == 2) {
		startTime = clock();
		numbers->blockMultiples(blockSize);
	}
	else {
		startTime = clock();
		unsigned long long k2 = 0, inc = 0, sqrtLast = trunc(sqrt(lastNumber));
		for(unsigned long long k = firstNumber; k <= sqrtLast; k += inc ) {
			k2 = k*k;
			if(method == 0) numbers->markMultiplesDivision(k);
			else if (method == 1) numbers->markMultiplesByMultiples(k);
			inc = (numbers->findNextUnmarked(k))-k;
		}

	}

	endTime = clock();
	timeTaken =  (double)(endTime-startTime)/(double)CLOCKS_PER_SEC;
	delete numbers;
}
Esempio n. 2
0
void PrimeFinder::gatherPrimesOpenMP(int method, unsigned long long size, unsigned long long blockSize) {
	NumberList *numbers = new NumberList(size);
	unsigned long long firstNumber = 3, lastNumber = size;
	
	double startTime, endTime;

	if(method == 2) {
		startTime = omp_get_wtime();
		#pragma omp parallel num_threads(8)
		{
			numbers->blockMultiplesOpenMP(blockSize);
		}
	}
	else {
		startTime = omp_get_wtime();
		unsigned long long k2 = 0, inc = 0, sqrtLast = (unsigned long long)trunc(sqrt(lastNumber));

		#pragma omp parallel
		{
			for(unsigned long long k = firstNumber; k <= sqrtLast; k += inc ) {
				k2 = k*k;
				if(method == 0) numbers->markMultiplesDivisionOpenMP(k);
				else if (method == 1) numbers->markMultiplesByMultiplesOpenMP(k);
				inc = (numbers->findNextUnmarked(k))-k;
			}
		}

	}

	endTime = omp_get_wtime();
	timeTaken =  (double)(endTime-startTime);
	delete numbers;

}
Esempio n. 3
0
TEST(number_list, add_clear_2) {
  NumberList nl;

  // should be the NULL pointer at this time
  EXPECT_EQ((void*)0, nl.getNumbers());
  // should be no items at this time
  EXPECT_EQ(0, nl.getNumberCount());

  // add a bunch of numbers
  int i, count = 100;
  for(i = 0; i < count; i++)
    {
      EXPECT_EQ(true, nl.addNumber(6));
    }
  // should not be the NULL pointer at this time
  EXPECT_NE((void*)0, nl.getNumbers());
  // should be count items at this time
  EXPECT_EQ(count, nl.getNumberCount());

  // clear the numbers
  EXPECT_EQ(true, nl.clear());

  // should be the NULL pointer at this time
  EXPECT_EQ((void*)0, nl.getNumbers());
  // should be no items at this time
  EXPECT_EQ(0, nl.getNumberCount());
}
int main()
{
   // Define a NumberList object.
   NumberList list;

   // Append some values to the list.
   list.appendNode(2.5);
   list.appendNode(7.9);
   list.appendNode(12.6);
   return 0;
}
Esempio n. 5
0
int main()
{
   const int MAX = 10;  // Maximum number of values

   // Define a NumberList object.
   NumberList list;

   // Build the list with a series of numbers.
   for (int x = 0; x < MAX; x++)
      list.insertNode(x);

   // Display the number of nodes in the list.
   cout << "The number of nodes is "
        << list.numNodes() << endl;
   return 0;
}
Esempio n. 6
0
int main()
{
   // Define a NumberList object.
   NumberList list;

   // Build the list with some values.
   list.appendNode(2.5);
   list.appendNode(7.9);
   list.appendNode(12.6);

   // Insert a node in the middle of the list.
   list.insertNode(10.5);

   // Dispay the list
   list.displayList();
   return 0;
}
Esempio n. 7
0
vector<unsigned long long> PrimeFinder::gatherPrimesMPI(unsigned long long size, unsigned long long blockSize, int proc, int nProc) {
	NumberList *numbers = new NumberList(size);
	vector<unsigned long long> retVec;
	
	double_t startTime, endTime;

	startTime = MPI_Wtime();
	numbers->blockMultiplesMPI(blockSize, proc, nProc);

	endTime = MPI_Wtime();
	timeTaken =  (double)(endTime-startTime);
	numbers->unmarkedNumbers(retVec);
	delete numbers;

	return retVec;

}
int main()
{
    const double MAX = 10.0;  // Upper limit of values

    // Create a NumberList object.
    NumberList list;

    // Add a series of numbers to the list.
    for (double x = 1.5; x < MAX; x += 1.1)
        list.appendNode(x);

    // Display the values in the list.
    cout << "Here are the values in the list:\n";
    list.displayList();

    // Display the values in reverse order.
    cout << "Here are the values in reverse order:\n";
    list.displayBackwards();
    return 0;
}
Esempio n. 9
0
bool PyVisInterface::PathIntegralSingleStep(QuaxolChunk& output) {
    // Timer slowness("python time");
    if(!g_PyVis || !g_PyVis->scriptStep)
        return false;

    PyErr_Print();

    PyObject* result = PyObject_CallObject(g_PyVis->scriptStep, /* args */ NULL);
    ScopePyDecRef clearResult(result);
    if(!result || !PyList_Check(result) || PyList_Size(result) <= 0) {
        //printf("Python script step didn't return a valid list\n");
        return false;
    }
    PyObject* list = PyList_GetItem(result, 0);
    PyErr_Print();

    NumberList nums;
    bool success = g_PyVis->CollectNumberList(list, nums);
    // printf("Got %d nums!\n", (int)nums.size());
    QuaxolSpec pos(0,0,0,0);
    for(int i = 0;
            i < (int)nums.size() && i < (int)QuaxolChunk::c_mxSz; 
            i++) {
        double val = nums[i];
        // printf(" val %f ", val); 
        static double max = 10.0f;
        static double min = 0.0f;
        int numFilled = (int)((val - min) / (max - min) * (double)QuaxolChunk::c_mxSz);
        pos.x = i;
        for(int j = 0;
                j < numFilled && j < (int)QuaxolChunk::c_mxSz;
                j++) {
            pos.z = j;
            output.SetAt(pos, true);
        }
    }
    PyErr_Print();

    return success;
}
Esempio n. 10
0
int main() {
	//ListNode *head;

	/*head = new ListNode;
	head->value = 12.5;
	head->next = NULL;

	ListNode *secondPtr = new ListNode;
	secondPtr->value = 13.5;
	secondPtr->next = NULL;
	head->next = secondPtr;

	ListNode *head = new ListNode(13.5);
	head = new ListNode(12.5, head);
	head = new ListNode(11.5, head);

	std::cout << "First: " << head->value << std::endl;
	std::cout << "Second: " << head->next->value << std::endl;
	std::cout << "Third: " << head->next->next->value << std::endl;

	//print entire list
	ListNode *ptr = head;
	while (ptr != NULL) {
		std::cout << ptr->value << " ";
		ptr = ptr->next;
	}
	std::cout << std::endl;*/

	NumberList list;
	list.add(2);
	list.add(3);
	list.add(1);
	list.add(4);
	list.display();
	std::cout << std::endl;
	list.remove(2);
	list.display();
	std::cout << std::endl;

	std::cout << std::endl;
	Sorted list2;
	list2.add(3);
	list2.add(2);
	list2.add(1);
	list2.add(4);
	list2.display();
	std::cout << std::endl;
	list2.remove(3);
	list2.display();
	std::cout << std::endl;

	return 0;

}
Esempio n. 11
0
TEST(number_list, add_clear_1) {
  NumberList nl;

  // should be the NULL pointer at this time
  EXPECT_EQ((void*)0, nl.getNumbers());
  // should be no items at this time
  EXPECT_EQ(0, nl.getNumberCount());

  // add a number
  EXPECT_EQ(true, nl.addNumber(6));
  // should not be the NULL pointer at this time
  EXPECT_NE((void*)0, nl.getNumbers());
  // should be one item at this time
  EXPECT_EQ(1, nl.getNumberCount());

  // clear the numbers
  EXPECT_EQ(true, nl.clear());

  // should be the NULL pointer at this time
  EXPECT_EQ((void*)0, nl.getNumbers());
  // should be no items at this time
  EXPECT_EQ(0, nl.getNumberCount());
}