Support odd text
This commit is contained in:
parent
f6cfc87ce1
commit
bee0b9ef57
24
main.c
24
main.c
@ -20,6 +20,9 @@ int sum_array(int *, int);
|
||||
|
||||
int main() {
|
||||
int rank, size, private_text_len, text_len, pattern_len;
|
||||
int *text_piece;
|
||||
int *displacements;
|
||||
int remain;
|
||||
char *pattern, *text;
|
||||
|
||||
MPI_Init(NULL, NULL);
|
||||
@ -34,14 +37,27 @@ int main() {
|
||||
printf("pattern: %s\n", pattern);
|
||||
text_len = strlen(text);
|
||||
pattern_len = strlen(pattern);
|
||||
private_text_len = text_len / size; // TODO: size non divisibile
|
||||
private_text_len = text_len / size;
|
||||
remain = text_len % size;
|
||||
|
||||
text_piece = (int *) malloc(sizeof(int) * size);
|
||||
displacements = (int *) malloc(sizeof(int) * size);
|
||||
|
||||
displacements[0] = 0;
|
||||
for (int i = 0; i < size - 1; ++i) {
|
||||
text_piece[i] = private_text_len;
|
||||
displacements[i + 1] = displacements[i] + private_text_len;
|
||||
}
|
||||
|
||||
MPI_Bcast(&private_text_len, 1, MPI_INT, MASTER, MPI_COMM_WORLD);
|
||||
text_piece[size - 1] = private_text_len + remain;
|
||||
}
|
||||
|
||||
MPI_Scatter(text_piece, 1, MPI_INT, &private_text_len, 1, MPI_INT, MASTER, MPI_COMM_WORLD);
|
||||
|
||||
char *private_text = (char *) malloc(sizeof(char) * (private_text_len + 1));
|
||||
|
||||
MPI_Scatter(text, private_text_len, MPI_CHAR, private_text, private_text_len, MPI_CHAR, MASTER, MPI_COMM_WORLD);
|
||||
MPI_Scatterv(text, text_piece, displacements, MPI_CHAR, private_text, private_text_len, MPI_CHAR, MASTER,
|
||||
MPI_COMM_WORLD);
|
||||
private_text[private_text_len] = '\0';
|
||||
|
||||
printf("%d -> input: %s\n", rank, private_text);
|
||||
@ -116,7 +132,7 @@ int main() {
|
||||
|
||||
char *read_text() {
|
||||
// TODO
|
||||
return "abc";
|
||||
return "ciaoooooo mamma come stai???";
|
||||
}
|
||||
|
||||
char *read_pattern() {
|
||||
|
Loading…
Reference in New Issue
Block a user