t_chat *init(t_chat *chatterbot) { if ((chatterbot = malloc(1 * sizeof(*chatterbot))) == NULL) printf("Error\n"); else if ((chatterbot->str = malloc_tab(chatterbot->str)) == NULL) printf("Error1\n"); else if ((chatterbot->Fichier = fopen("data/cerveau.txt", "rw")) == NULL) printf("Error2\n"); else if ((chatterbot->question = malloc_tab(chatterbot->question)) == NULL) printf("error\n"); else if ((chatterbot->reponse = malloc_tab(chatterbot->reponse)) == NULL) printf("error\n"); else return (chatterbot); return (NULL); }
int make(int ac, char **av) { int nb_col; int nb_line; char **tab; int mem; int mem_i; int mem_j; nb_col = nb_colonne(av[1], 0, 0); nb_line = nb_ligne(av[1]); tab = malloc_tab(nb_col, nb_line); all_in_tab(tab, nb_line, nb_col, av[1]); one_or_zero(tab); replace_number(tab, nb_col); mem = check_bigger(tab, av, nb_col); mem_i = check_i(tab, mem, av, nb_col); mem_j = check_j(tab, mem, av, nb_col); replace_square(tab, mem, mem_i, mem_j); replace_all(tab, av, nb_col, nb_line); show_double_tab(tab); }
int main ( int argc, char *argv[] ) { int id; int ierr; int p=3; double wtime = 0, total; int n,m, bad_edges=0, oriented=0, i, diameter, leftover, lines; int **tab; int print = 0; char FILENAME[100]; int *process_lines, *process_start; /******************** MPI Initialisation *************************/ ierr = MPI_Init ( &argc, &argv ); if(ierr != MPI_SUCCESS) { perror("Error with initializing MPI"); exit(1); } // Get the number of processes. ierr = MPI_Comm_size ( MPI_COMM_WORLD, &p ); // Get the individual process ID. ierr = MPI_Comm_rank ( MPI_COMM_WORLD, &id ); /******************** Problem Initialisation *************************/ // Process 0 reads data + prints welcome n = 0; if (id==0) { for(i=1; i<argc; i++) { if(!strcmp(argv[i], "-print")) { print = 1; } else if (!strcmp(argv[i], "-read")) { strcpy(FILENAME, argv[i+1]); i++; } else if (!strcmp(argv[i], "-random")) { n = atoi(argv[i+1]); oriented = atoi(argv[i+2]); i+=2; } else { n = 4000; oriented = 1; } } if (n>0) init_tab(n,&m,&tab,oriented); // last one = oriented or not ... else bad_edges = read_tab(FILENAME, &n, &m, &tab, &oriented); fprintf(stderr, "Running program with %d rows and %d edges (%d are bad)\n", n, m, bad_edges); fprintf(stderr, "The number of processes is %d.\n", p); } // Distribute the problem size to all machines MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); // Malloc the table, which was not yet done for the other processes if(id != 0) malloc_tab(n, &tab); // Distribute the table to all machines. for(i = 0; i < n; i++) MPI_Bcast(tab[i], n, MPI_INT, 0, MPI_COMM_WORLD); // Determine the lines and start per process process_lines = malloc(p * sizeof(int)); process_start = malloc(p * sizeof(int)); leftover = n % p; lines = n / p; for(i = 0; i < p; i++) { process_lines[i] = i < leftover ? lines + 1 : lines; process_start[i] = i * lines + (i < leftover ? i : leftover); } printf("%d - Pointers: %d & %d\n", id, (int)process_lines, (int)process_start); /******************** Distance calculation *************************/ MPI_Barrier(MPI_COMM_WORLD); if(id == 0) wtime = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); printf("%d - Pointers: %d & %d\n", id, (int)process_lines, (int)process_start); total = do_dist(tab, n, id, p, process_start, process_lines); printf("%d - Pointers: %d & %d\n", id, (int)process_lines, (int)process_start); if(id == 0) { wtime = MPI_Wtime() - wtime; fprintf (stderr, "Distance took %10.3f seconds.\n", wtime); } /******************** ASP *************************/ MPI_Barrier(MPI_COMM_WORLD); if(id == 0) wtime = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); //do_asp(tab, n, id, p, process_start, process_lines); do_asp_lin(tab, n, id, p, process_start, process_lines); if(id == 0) { wtime = MPI_Wtime() - wtime; fprintf (stderr, "ASP took %10.3f seconds.\n", wtime); } /******************** Diameter *************************/ MPI_Barrier(MPI_COMM_WORLD); if(id == 0) wtime = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); diameter = do_diam(tab, n, id, p, process_start, process_lines); if(id == 0) { wtime = MPI_Wtime() - wtime; fprintf (stderr, "Diameter took %10.3f seconds.\n", wtime); } if(id == 0 && print == 1) { print_tab(tab, n); printf("Total distance: %.0lf\n", total); printf("Diameter: %d\n", diameter); } // Clean up free_tab(tab, n); free(process_start); free(process_lines); // Shut down MPI. ierr = MPI_Finalize(); return 0; }