[mpich-discuss] (no subject)

Chafik sanaa san.chafik at gmail.com
Tue Nov 11 09:42:52 CST 2014


Hi,
What should I do? i have the folowing error (error C4703: variable de
pointeur locale potentiellement non initialisée 'sendbuf' utilisée and
error C4703: variable de pointeur locale potentiellement non initialisée
'tab_indice' utilisée ) when I execute this program:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

#define DIMENSION 10

int main(int argc, char** argv)
{
int myrank, i, n_procs;
int * sendbuf;      //buffer à disperser
int * tab_indice;   //indice de début de chaque subdivision
int * tab_taille;   //nombre d'éléments à envoyer
// pour chaque processus
int * rbuf;         //buffer de reception
int taille;         //taille de la partie reçue

//Initialisation de MPI
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &n_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

if (myrank == 0)
{
//allocation mémoire
sendbuf = (int *)malloc(n_procs*DIMENSION*sizeof(int));
tab_indice = (int *)malloc(n_procs*sizeof(int));
tab_taille = (int *)malloc(n_procs*sizeof(int));
//remplissage du buffer à disperser
printf("la taille de la boucle %d \n", n_procs*DIMENSION);
for (i = 0; i<n_procs*DIMENSION; i++) sendbuf[i] = i;
//initialisation des subdivisions
for (i = 0; i<n_procs; i++)
{
//nombre d'éléments à envoyer
tab_taille[i] = DIMENSION - i;
printf("tab_taille[%d]=%d \n", i, tab_taille[i]);
//indice de début du processus i
// = celui de i-1 + nombre d'éléments
// envoyés par i-1
if (i != 0) tab_indice[i] = tab_indice[i - 1] + tab_taille[i - 1];
else tab_indice[i] = 0;
printf("tab_indice[%d]=%d \n", i, tab_indice[i]);
}
}
//communication de la taille de la partie reçue à chaque processus
MPI_Scatter(tab_taille, 1, MPI_INT, &taille, 1, MPI_INT, 0, MPI_COMM_WORLD);
//allocation du buffer de reception
rbuf = (int *)malloc(taille*sizeof(int));
//dispersion
MPI_Scatterv(sendbuf, tab_taille, tab_indice, MPI_INT, rbuf,DIMENSION,
MPI_INT, 0, MPI_COMM_WORLD);
//affichage
printf("processus %d : [ ", myrank);
for (i = 0; i<taille; i++) printf("%d ", rbuf[i]);
printf("]\n");

//desallocation mémoire
free(rbuf);
if (myrank == 0) {
free(sendbuf);
free(tab_indice);
free(tab_taille);
}
 MPI_Finalize();
exit(EXIT_SUCCESS);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpich.org/pipermail/discuss/attachments/20141111/f4fab1e0/attachment.html>
-------------- next part --------------
_______________________________________________
discuss mailing list     discuss at mpich.org
To manage subscription options or unsubscribe:
https://lists.mpich.org/mailman/listinfo/discuss


More information about the discuss mailing list