Esempio n. 1
0
void TripPrep::MPI_Setup (void)
{
#ifdef MPI_EXE
	if (MPI_Size () == 1) return;

	int range [2];

	if (Master ()) {
		int num_parts, rank;
		Db_File temp_file;
		String key, dir;
		Integers count;
		Int_Itr itr;
		Int_RItr ritr;

		dir = Get_Control_String (PROJECT_DIRECTORY);
		if (!dir.empty ()) {
			Fix_Directory (dir);
		}
		key = Get_Control_String (System_File_ID (TRIP));
	
		temp_file.Filename (dir + key);
		num_parts = temp_file.Num_Parts ();
		if (num_parts < 2) return;

		Write (1, "Number of MPI Processors = ") << MPI_Size ();
		Write (1, "Number of Trip Partitions = ") << num_parts;
		Write (1);

		count.assign (MPI_Size (), 0);

		for (itr = count.begin (); itr != count.end (); itr++) {
			(*itr)++;
			if (--num_parts == 0) break;
		}
		while (num_parts > 0) {
			for (ritr = count.rbegin (); ritr != count.rend (); ritr++) {
				(*ritr)++;
				if (--num_parts == 0) break;
			}
		}
		num_parts = 0;

		for (rank=0, itr = count.begin (); itr != count.end (); itr++, rank++) {
			range [0] = num_parts;
			num_parts += *itr;
			range [1] = num_parts - 1;

			if (rank == 0) {
				First_Partition (range [0]);
				Last_Partition (range [1]);
			} else {
				Send_MPI_Array (range, 2, rank);
			}
		}

	} else {	//---- slave ----

		Get_MPI_Array (range, 2, 0);

		First_Partition (range [0]);
		Last_Partition (range [1]);
	}
#endif
}
Esempio n. 2
0
void PlanCompare::MPI_Close (void)
{
#ifdef MPI_EXE
	int i, lvalue [6], rank;

	if (Master ()) {
		if (new_plan_flag) {
			Show_Message (1);

			for (i=1; i < MPI_Size (); i++) {

				rank = Show_MPI_Message ();

				//---- retrieve the new plan statistics

				Get_MPI_Array (lvalue, 6, rank);

				new_plan_file->Add_Files (lvalue [0]);
				new_plan_file->Add_Records (lvalue [1]);
				new_plan_file->Add_Households (lvalue [2]);
				new_plan_file->Add_Persons (lvalue [3]);
				new_plan_file->Add_Tours (lvalue [4]);
				new_plan_file->Add_Trips (lvalue [5]);
			}
			new_plan_file->Close ();
		}

		//---- write the new selection file ----

		if (select_parts) {
			Show_Message (1);

			select_map.swap (selected);
			Write_Selections ();

			for (i=1; i < MPI_Size (); i++) {
				Show_MPI_Message ();
			}
		}
		Show_Message (1);

	} else {	//---- slave ----

		if (new_plan_flag) {
			if (Partition_Range ()) {
				Send_MPI_Message (String ("Slave %d Wrote %ss %d..%d") % MPI_Rank () % new_plan_file->File_Type () % First_Partition () % Last_Partition ());
			} else {
				Send_MPI_Message (String ("Slave %d Wrote %s %d") % MPI_Rank () % new_plan_file->File_Type () % First_Partition ());
			}

			//---- send new plan statistics ----

			lvalue [0] = new_plan_file->Num_Files ();
			lvalue [1] = new_plan_file->Num_Records ();
			lvalue [2] = new_plan_file->Num_Households ();
			lvalue [3] = new_plan_file->Num_Persons ();
			lvalue [4] = new_plan_file->Num_Tours ();
			lvalue [5] = new_plan_file->Num_Trips ();
			new_plan_file->Close ();

			Send_MPI_Array (lvalue, 6);
		}

		//---- write the new selection file ----

		if (select_parts) {
			select_map.swap (selected);
			Write_Selections ();

			Selection_File *file = System_Selection_File (true);

			if (Partition_Range ()) {
				Send_MPI_Message (String ("Slave %d Wrote %ss %d..%d") % MPI_Rank () % file->File_Type () % First_Partition () % Last_Partition ());
			} else {
				Send_MPI_Message (String ("Slave %d Wrote %s %d") % MPI_Rank () % file->File_Type () % First_Partition ());
			}
		}
		Exit_Stat (DONE);
	}
#endif
}