-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep-main.cpp
59 lines (48 loc) · 1.79 KB
/
grep-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
#include <mpi.h>
#include <iostream>
#include "grep.h"
int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cout << "Expected 2 inputs, got " << argc - 1 << std::endl;
return 0;
}
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
double start_time = MPI_Wtime();
std::string all_lines;
std::string local_lines;
unsigned local_lines_start_from, total_number_of_lines;
std::vector<unsigned> local_matching_numbers;
grep::get_lines(rank, size, all_lines, total_number_of_lines, argv[2]);
double get_lines_time = MPI_Wtime();
if (rank == 0)
{
std::cout << "Get lines time: " << (get_lines_time - start_time) * 1000 << "ms" << std::endl;
}
grep::split_lines(rank, size, all_lines, total_number_of_lines, local_lines, local_lines_start_from);
double split_lines_time = MPI_Wtime();
if (rank == 0)
{
std::cout << "Split lines time: " << (split_lines_time - get_lines_time) * 1000 << "ms" << std::endl;
}
grep::search_string(rank, size, local_lines, argv[1], local_matching_numbers, local_lines_start_from);
local_lines.clear();
double search_string_time = MPI_Wtime();
if (rank == 0)
{
std::cout << "Search string time: " << (search_string_time - split_lines_time) * 1000 << "ms" << std::endl;
}
grep::print_result(rank, size, all_lines, local_matching_numbers);
double print_results_time = MPI_Wtime();
if (rank == 0)
{
std::cout << "Print results time: " << (print_results_time - search_string_time) * 1000 << "ms" << std::endl;
std::cout << "Total enlapsed time: " << (print_results_time - start_time) * 1000 << "ms" << std::endl;
}
MPI_Finalize();
return 0;
}