-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
131 lines (104 loc) · 3.31 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* File: main.cpp
* Author: Tomáš Čerevka, Adam Činčura
*
* Created on October 31, 2011, 3:21 PM
*/
#include <cstdlib>
#include <string>
#include <mpi.h>
#include "Input.h"
#include "Solver.h"
#include "WorkMessage.h"
using namespace std;
/*
* Vstupni bod programu.
*/
int main(int argc, char** argv) {
try {
MPI_Init(&argc, &argv);
// Mereni casu.
double start, stop;
MPI_Barrier(MPI_COMM_WORLD);
start = MPI_Wtime();
int myRank;
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
int processesCount;
MPI_Comm_size(MPI_COMM_WORLD, &processesCount);
// Priprav se deska.
Board board;
Input input(&board);
input.parseArguments(argc, argv);
Solver solver(&board, input.getTargetTower(), input.getMaxDepth());
vector<Move> solution;
if(myRank==0){
cout << "Towers of Hanoi" << endl;
input.printTask();
}
solver.init();
solver.solve(solution);
// Vypise reseni.
// if (myRank == 0) {
// for (vector<Move>::const_iterator it = solution.begin(); it != solution.end(); ++it) {
// cout << *it << endl;
// }
//
// cout << "Solution has " << solution.size() << " steps." << endl;
// }
//// //=== Testovani serializace ===
//
// // Vytvori se sekvence tahu.
// vector<Move> moves;
// Move move1(0, 2, 2);
// Move move2(3, 2, 1);
// Move move3(3, 0, 7);
// Move move4(1, 3, 5);
// moves.push_back(move1);
// moves.push_back(move2);
// moves.push_back(move3);
// moves.push_back(move4);
//
// Move move5(2, 3, 1);
//
// SpaceItem spaceItem(board, moves, move5);
// WorkMessage message;
// message.addItem(spaceItem);
// message.addItem(spaceItem);
// message.addItem(spaceItem);
//
// char buffer[BUFFER_SIZE];
// int position = 0;
// message.serialize(buffer, position);
//
// cout << endl << "I will send (" << position << "B): " << endl;
// cout << message << endl;
//
// int dest = 1;
// int tag = 0;
// MPI_Send(buffer, position, MPI_PACKED, dest, tag, MPI_COMM_WORLD);
//
// char buffer[BUFFER_SIZE];
// WorkMessage message;
// MPI_Status status;
//
// MPI_Recv(buffer, BUFFER_SIZE, MPI_PACKED, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
//
// int position = 0;
// message.deserialize(buffer, position);
//
// cout << "I received (" << position << "B): " << endl;
// cout << message << endl;
//
MPI_Barrier(MPI_COMM_WORLD);
stop = MPI_Wtime();
if (myRank == 0) {
cout << "Execution time: " << (stop - start) << endl;
}
MPI_Finalize();
return 0;
} catch (const char* exception) {
cout << exception << endl;
MPI_Finalize();
return 1;
}
}