Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <mpi.h>
- void inicializaCadena(char *cadena, int n){
- int i;
- for(i=0; i<n/2; i++){
- cadena[i] = 'A';
- }
- for(i=n/2; i<3*n/4; i++){
- cadena[i] = 'C';
- }
- for(i=3*n/4; i<9*n/10; i++){
- cadena[i] = 'G';
- }
- for(i=9*n/10; i<n; i++){
- cadena[i] = 'T';
- }
- }
- int main(int argc, char *argv[])
- {
- int numprocs , rank , namelen;
- char processor_name [MPI_MAX_PROCESSOR_NAME];
- MPI_Init(&argc, &argv);
- MPI_Comm_size (MPI_COMM_WORLD , &numprocs);
- MPI_Comm_rank (MPI_COMM_WORLD , &rank);
- MPI_Get_processor_name (processor_name , &namelen);
- if(argc != 3){
- printf("Numero incorrecto de parametros\nLa sintaxis debe ser: program n L\n program es el nombre del ejecutable\n n es el tamaño de la cadena a generar\n L es la letra de la que se quiere contar apariciones (A, C, G o T)\n");
- exit(1);
- }
- int i, n, count=0;
- char *cadena;
- char L;
- if(rank==0) {
- n = atoi(argv[1]);
- L = *argv[2];
- }
- printf("%d\n",rank);
- cadena = (char *) malloc(n*sizeof(char));
- inicializaCadena(cadena, n);
- printf("%s\n",cadena);
- for(i=0; i<n; i++){
- if(cadena[i] == L){
- count++;
- }
- }
- if(rank == 0) {
- for(i=1; i<numprocs; i++){
- int count2=0;
- MPI_Status status;
- MPI_Recv(&count2, 1, MPI_INT, numprocs,0 ,MPI_COMM_WORLD, &status);
- count=count+count2;
- }
- printf("El numero de apariciones de la letra %c es %d\n", L, count);
- }else{
- MPI_Send(&count, 1, MPI_INT, 0,0 ,MPI_COMM_WORLD);
- }
- free(cadena);
- if(rank == 0) {
- MPI_Finalize();
- }
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement