-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrep.h
87 lines (80 loc) · 3.61 KB
/
grep.h
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
#ifndef GREP_H
#define GREP_H
#include <vector>
#include <string>
namespace grep
{
const int LINELENGTH = 80;
const std::string OUTPUT_FILE = "outputs/output-mpi.txt";
/**
* Get the lines from the file and split them between processes.
*
* Args:
* rank (const unsigned): The rank of the process executing the function.
* size (const unsigned): The size of the communication channel.
* all_lines (std::string): Where process with rank 0 will store all the lines, concatenated
* one every (LINELENGTH + 1) characters (+1 is for null terminator), padded with null terminators.
* total_number_of_lines (unsigned): Where all the process will have the total number of lines in the file.
* file_name (const std::string): The filename.
*/
void get_lines(
const unsigned &rank,
const unsigned &size,
std::string &all_lines,
unsigned &total_number_of_lines,
const std::string &file_name);
/**
* Split the lines evenly between processes.
*
* Args:
* rank (const unsigned): The rank of the process executing the function.
* size (const unsigned): The size of the communication channel.
* all_lines (const std::string): Where process with rank 0 will store all the lines, concatenated
* one every (LINELENGTH + 1) characters (+1 is for null terminator), padded with null terminators.
* total_number_of_lines (const unsigned): Total number of lines in the file.
* local_lines (std::string): Where every process will have their local lines as a concatenated string.
* local_lines_start_from (unsigned): From which number the local lines starts.
*/
void split_lines(
const unsigned &rank,
const unsigned &size,
const std::string &all_lines,
const unsigned &total_number_of_lines,
std::string &local_lines,
unsigned &local_lines_start_from);
/**
* Search the local lines to find the specified string and save the number of the line
* where the string is found.
*
* Args:
* rank (const unsigned): The rank of the process executing the function.
* size (const unsigned): The size of the communication channel.
* local_lines (const std::string): The local lines of the process as a concatenated string.
* search_string (const std::string): The string to search.
* local_matching_numbers (std::vector<unsigned>): Where to save the numbers of the matching lines.
* local_lines_start_from (const unsigned): From which number the local lines starts.
*/
void search_string(
const unsigned &rank,
const unsigned &size,
const std::string &local_lines,
const std::string &search_string,
std::vector<unsigned> &local_matching_numbers,
const unsigned &local_lines_start_from);
/**
* From the local numbers of the matching lines print all the matching lines.
*
* Args:
* rank (const unsigned): The rank of the process executing the function.
* size (const unsigned): The size of the communication channel.
* all_lines (const std::vector<std::string>): Where process with rank 0 has all the lines, concatenated
* one every (LINELENGTH + 1) characters (+1 is for null terminator), padded with null terminators.
* local_matching_numbers (const std::vector<unsigned>): The numbers of the matching local lines.
*/
void print_result(
const unsigned &rank,
const unsigned &size,
const std::string &all_lines,
const std::vector<unsigned> &local_matching_numbers);
}
#endif // GREP_H