Last active
August 29, 2015 14:10
-
-
Save IuryAlves/ca3fd560e122a3a5dd0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # include <stdio.h> | |
| # include <stdlib.h> | |
| # include <ctype.h> | |
| # include <string.h> | |
| # include <stdbool.h> | |
| # include <mpi.h> | |
| # define MAX 100001 | |
| int VectorSort[MAX]; | |
| int size = 0; | |
| void swap(int *A ,int *B); | |
| void gerarNumerosAleatorios(int *v, int tamanho); | |
| void GnomeSort(); | |
| int main (void){ | |
| int size; | |
| int rank, type = 99; | |
| int DEBUG = 1; | |
| MPI_Init(&argc, &argv); | |
| MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| MPI_Status status; | |
| int *vPart = (int*) calloc(10, sizeof(int)); | |
| int *vTotal = (int*) calloc(10, sizeof(int)); | |
| gerarNumerosAleatorios(vTotal, 10); | |
| if (rank == 0){ | |
| } | |
| //GnomeSort(); | |
| return 0; | |
| } | |
| void swap(int *A, int *B) | |
| { | |
| int C = *A; | |
| * A = *B; | |
| * B = C; | |
| } | |
| void GnomeSort(){ | |
| int next = 0; | |
| int previous = 0; | |
| int i = 0; | |
| for(i = 0; i < size ; i++){ | |
| if(VectorSort[i] > VectorSort[i + 1]){ | |
| previous = i; | |
| next = i + 1; | |
| while(VectorSort[previous] > VectorSort[next]){ | |
| swap(&VectorSort[previous],&VectorSort[next]); | |
| previous--; | |
| next--; | |
| } | |
| } | |
| } | |
| void gerarNumerosAleatorios(int *v, int tamanho){ | |
| int i; | |
| srand(time(0)); | |
| for(i = 0; i < tamanho; i++){ | |
| v[i] = rand(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <mpi.h> | |
| int main(int argc, char **argv){ | |
| int i, rank, size; | |
| int *x_total, *x_part; | |
| MPI_Init(&argc, &argv); | |
| MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| x_total = (int*) calloc (10*size, sizeof(int)); | |
| x_part = (int*) calloc (10, sizeof(int)); | |
| if (rank == 0){ | |
| for (i = 0; i < 10 * size; i++){ | |
| x_total[i] = i; | |
| } | |
| } | |
| MPI_Scatter(x_total, 10, MPI_INT, x_part, 10, MPI_INT, 0, MPI_COMM_WORLD); | |
| for (i = 0; i < 10; i++){ | |
| x_part[i] *=2; | |
| } | |
| MPI_Gather(x_part, 10, MPI_INT, x_total, 10, MPI_INT, 0, MPI_COMM_WORLD); | |
| if (rank == 0){ | |
| printf ("processo %d \n", rank); | |
| for( i = 0; i < 10 * size; i++){ | |
| printf("%d ", x_total[i]); | |
| if (i % 10 == 0){ | |
| printf(" \n"); | |
| } | |
| } | |
| printf ("\n"); | |
| } | |
| MPI_Finalize(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment