Skip to content
Snippets Groups Projects
PthreadSimulation.cpp 1.04 KiB
Newer Older
#include <PthreadSimulation.hpp>
#include <iostream>

namespace nbody {
	using namespace std;

	PthreadSimulation::PthreadSimulation(int& argc, char**& argv) {
		//TODO: change
		this->parallelRank = 0;
		if (argc == 2) {
			this->correctState = this->readInputData(string(argv[1]));
		} else {
			this->correctState = false;
		}
		this->tree.build(this->bodies);
	}

	PthreadSimulation::~PthreadSimulation() {
	}

	void PthreadSimulation::cleanup() {
		//TODO: maybe kill threads
	}

	int PthreadSimulation::getNumberOfProcesses() {
		return this->threads.size();
	}

	int PthreadSimulation::getProcessId() {
		vector<pthread_t>::iterator it = this->threads.begin();
		int id = 0;

		while (*it != pthread_self() && it != this->threads.end()) {
			id++;
			it++;
		}
		if (it != this->threads.end()) {
			return id;
		} else {
			return -1;
		}
	}

	void PthreadSimulation::runStep() {
		//Box domain = this->tree.getRootBB();

		//cout << this->tree.getRootBB().volume() << endl;
		this->tree.rebuild();
		this->tree.computeForces();
		this->tree.advance();