How to send dynamic vector?

Discussion in 'C Programming' started by dopiotr, Oct 21, 2007.

  1. dopiotr

    dopiotr Guest

    Hello Group,

    int Msg[size];
    MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    this is working fine.

    But how to send Msg declared like this:
    int *Msg=(int*)malloc(sizeof(int)*size);

    It gives me
    p4_error: interrupt SIGSEGV: 11
    not_send: could not write to fd=4, errno = 32

    Thanks!
    dopiotr, Oct 21, 2007
    #1
    1. Advertising

  2. dopiotr

    santosh Guest

    dopiotr wrote:

    > Hello Group,
    >
    > int Msg[size];
    > MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    > this is working fine.
    >
    > But how to send Msg declared like this:
    > int *Msg=(int*)malloc(sizeof(int)*size);
    >
    > It gives me
    > p4_error: interrupt SIGSEGV: 11
    > not_send: could not write to fd=4, errno = 32


    Without further code I can't really tell what your problem is. It may
    not be a C problem but an incorrect use of MPI functions. You might do
    better to ask in a forum dedicated to your MPI implementation.

    <http://en.wikipedia.org/wiki/Message_Passing_Interface>
    <http://www.mpi-forum.org/docs/>
    <http://www.open-mpi.org/>
    <http://www.personal.leeds.ac.uk/~bgy1mm/MPITutorial/MPIHome.html>
    santosh, Oct 21, 2007
    #2
    1. Advertising

  3. dopiotr

    CryptiqueGuy Guest

    On Oct 22, 12:45 am, dopiotr <> wrote:
    > Hello Group,
    >
    > int Msg[size];
    > MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    > this is working fine.
    >
    > But how to send Msg declared like this:
    > int *Msg=(int*)malloc(sizeof(int)*size);
    >


    Did u check the return value of malloc?
    It might be NULL, due to failed memory allocation.
    CryptiqueGuy, Oct 21, 2007
    #3
  4. dopiotr

    dopiotr Guest

    On 21 Oct 2007 at 19:56, santosh wrote:
    > dopiotr wrote:
    >
    >> Hello Group,
    >>
    >> int Msg[size];
    >> MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    >> this is working fine.
    >>
    >> But how to send Msg declared like this:
    >> int *Msg=(int*)malloc(sizeof(int)*size);
    >>
    >> It gives me
    >> p4_error: interrupt SIGSEGV: 11
    >> not_send: could not write to fd=4, errno = 32

    >
    > Without further code I can't really tell what your problem is. It may
    > not be a C problem but an incorrect use of MPI functions. You might do
    > better to ask in a forum dedicated to your MPI implementation.
    >
    ><http://en.wikipedia.org/wiki/Message_Passing_Interface>
    ><http://www.mpi-forum.org/docs/>
    ><http://www.open-mpi.org/>
    ><http://www.personal.leeds.ac.uk/~bgy1mm/MPITutorial/MPIHome.html>
    >


    Working wersion:
    #include "mpi.h"
    #include<stdio.h>
    #include<stdlib.h>
    uint n_sigm;
    float *suma_sigm;

    void main(int c, char *v[])
    {
    int size,rank;
    int j;
    float *s_tmp;
    MPI_Init(&c,&v);
    MPI_Comm_size(MPI_COMM_WORLD,&size);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    n_sigm=1000;

    suma_sigm=(float *)malloc(sizeof(float)*n_sigm);
    s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference

    if(rank != 0)
    {
    for(j=0;j<n_sigm;j++)
    suma_sigm[j]=rank*1000+j;
    }
    else
    {
    for(j=0;j<n_sigm;j++)
    s_tmp[j]=0;
    }
    MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    0,MPI_COMM_WORLD);
    if( rank == 0 )
    for(j=0;j<n_sigm;j++)
    printf("%i %f\n",j,s_tmp[j]);
    free(suma_sigm);
    free(s_tmp);
    MPI_Finalize();
    }

    Why it is not working:
    #include "mpi.h"
    #include<stdio.h>
    #include<stdlib.h>
    uint n_sigm;
    float *suma_sigm;
    int main(int c, char *v[])
    {
    int size,rank;
    int j;
    float *s_tmp;
    MPI_Init(&c,&v);
    MPI_Comm_size(MPI_COMM_WORLD,&size);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    n_sigm=1000;

    suma_sigm=(float *)malloc(sizeof(float)*n_sigm);

    if(rank != 0)
    {
    for(j=0;j<n_sigm;j++)
    suma_sigm[j]=rank*1000+j;
    }
    else
    {
    for(j=0;j<n_sigm;j++)
    s_tmp[j]=0;
    }
    s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference
    MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    0,MPI_COMM_WORLD);
    if( rank == 0 )
    for(j=0;j<n_sigm;j++)
    printf("%i %f\n",j,s_tmp[j]);
    free(suma_sigm);
    free(s_tmp);
    MPI_Finalize();
    }

    And why value of s_tmp[0] & s_tmp[1] is incorrect (in working
    version).
    dopiotr, Oct 21, 2007
    #4
  5. dopiotr

    santosh Guest

    dopiotr wrote:

    > On 21 Oct 2007 at 19:56, santosh wrote:
    >> dopiotr wrote:
    >>
    >>> Hello Group,
    >>>
    >>> int Msg[size];
    >>> MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    >>> this is working fine.
    >>>
    >>> But how to send Msg declared like this:
    >>> int *Msg=(int*)malloc(sizeof(int)*size);
    >>>
    >>> It gives me
    >>> p4_error: interrupt SIGSEGV: 11
    >>> not_send: could not write to fd=4, errno = 32

    >>
    >> Without further code I can't really tell what your problem is. It may
    >> not be a C problem but an incorrect use of MPI functions. You might
    >> do better to ask in a forum dedicated to your MPI implementation.
    >>
    >><http://en.wikipedia.org/wiki/Message_Passing_Interface>
    >><http://www.mpi-forum.org/docs/>
    >><http://www.open-mpi.org/>
    >><http://www.personal.leeds.ac.uk/~bgy1mm/MPITutorial/MPIHome.html>
    >>

    >
    > Working wersion:
    > #include "mpi.h"
    > #include<stdio.h>
    > #include<stdlib.h>
    > uint n_sigm;
    > float *suma_sigm;
    >
    > void main(int c, char *v[])


    Use int main

    > {
    > int size,rank;
    > int j;
    > float *s_tmp;
    > MPI_Init(&c,&v);
    > MPI_Comm_size(MPI_COMM_WORLD,&size);
    > MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    > n_sigm=1000;
    >
    > suma_sigm=(float *)malloc(sizeof(float)*n_sigm);
    > s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference


    In C the cast of malloc's return value is not needed. I'd write your
    statements as:

    suma_sigm = malloc(sizeof *suma_sigm * n_sigm);
    s_tmp = malloc(sizeof *s_tmp * n_sigm);

    Also be sure to check that malloc actually succeeded.

    > if(rank != 0)
    > {
    > for(j=0;j<n_sigm;j++)
    > suma_sigm[j]=rank*1000+j;
    > }
    > else
    > {
    > for(j=0;j<n_sigm;j++)
    > s_tmp[j]=0;
    > }
    > MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    > 0,MPI_COMM_WORLD);
    > if( rank == 0 )
    > for(j=0;j<n_sigm;j++)
    > printf("%i %f\n",j,s_tmp[j]);
    > free(suma_sigm);
    > free(s_tmp);
    > MPI_Finalize();


    Return a value here.

    > }
    >
    > Why it is not working:
    > #include "mpi.h"
    > #include<stdio.h>
    > #include<stdlib.h>
    > uint n_sigm;
    > float *suma_sigm;
    > int main(int c, char *v[])
    > {
    > int size,rank;
    > int j;
    > float *s_tmp;
    > MPI_Init(&c,&v);
    > MPI_Comm_size(MPI_COMM_WORLD,&size);
    > MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    > n_sigm=1000;
    >
    > suma_sigm=(float *)malloc(sizeof(float)*n_sigm);
    >
    > if(rank != 0)
    > {
    > for(j=0;j<n_sigm;j++)
    > suma_sigm[j]=rank*1000+j;
    > }
    > else
    > {
    > for(j=0;j<n_sigm;j++)
    > s_tmp[j]=0;


    Well, here s_tmp is not yet pointing to any valid memory. You're writing
    to memory you don't own or should not be writing to. Initialise s_tmp
    to a valid object or an array of objects before using it.

    > }
    > s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference


    /Now/ you're doing it, but it's too late, unless rank was not zero.

    > MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    > 0,MPI_COMM_WORLD);
    > if( rank == 0 )
    > for(j=0;j<n_sigm;j++)
    > printf("%i %f\n",j,s_tmp[j]);
    > free(suma_sigm);
    > free(s_tmp);
    > MPI_Finalize();
    > }
    >
    > And why value of s_tmp[0] & s_tmp[1] is incorrect (in working
    > version).


    How should I know? What value did you expect? The obvious bug waiting to
    happen in your second version is the use of the pointer s_tmp without
    making it point to anything valid beforehand.
    santosh, Oct 21, 2007
    #5
  6. On Oct 21, 1:06 pm, dopiotr <> wrote:

    snip

    > > dopiotr wrote:

    >
    > >> Hello Group,

    >
    > >> int Msg[size];
    > >> MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    > >> this is working fine.

    >
    > >> But how to send Msg declared like this:
    > >> int *Msg=(int*)malloc(sizeof(int)*size);

    >
    > >> It gives me
    > >> p4_error: interrupt SIGSEGV: 11
    > >> not_send: could not write to fd=4, errno = 32


    snip

    > Working wersion:


    This is not a working version. It invokes undefined behavior and you
    state it produces incorrect results.

    > #include "mpi.h"
    > #include<stdio.h>
    > #include<stdlib.h>
    > uint n_sigm;
    > float *suma_sigm;
    >
    > void main(int c, char *v[])


    main should return int.

    > {
    > int size,rank;
    > int j;
    > float *s_tmp;
    > MPI_Init(&c,&v);
    > MPI_Comm_size(MPI_COMM_WORLD,&size);
    > MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    > n_sigm=1000;
    >
    > suma_sigm=(float *)malloc(sizeof(float)*n_sigm);


    Do not cast the return from malloc. It can never help and the only
    effect would be to suppress a diagnostic you really want to see if it
    applies to your code.

    > s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference


    You should always check that malloc succeeds.

    >
    > if(rank != 0)
    > {
    > for(j=0;j<n_sigm;j++)
    > suma_sigm[j]=rank*1000+j;
    > }
    > else
    > {
    > for(j=0;j<n_sigm;j++)
    > s_tmp[j]=0;
    > }


    At this point, the elements of suma_sigm or s_tmp (but not both) have
    been assigned values. The elements of the other array are
    indeterminate (uninitialized).

    > MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    > 0,MPI_COMM_WORLD);


    Since you don't pass rank to this function, how is it supposed to
    determine which of the arrays has valid values and which doesn't. Any
    attempt by the function to evaluate an indeterminate element will
    invoke undefined behavior.

    > if( rank == 0 )
    > for(j=0;j<n_sigm;j++)
    > printf("%i %f\n",j,s_tmp[j]);
    > free(suma_sigm);
    > free(s_tmp);
    > MPI_Finalize();
    >
    > }
    >
    > Why it is not working:
    > #include "mpi.h"
    > #include<stdio.h>
    > #include<stdlib.h>
    > uint n_sigm;
    > float *suma_sigm;
    > int main(int c, char *v[])
    > {
    > int size,rank;
    > int j;
    > float *s_tmp;
    > MPI_Init(&c,&v);
    > MPI_Comm_size(MPI_COMM_WORLD,&size);
    > MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    > n_sigm=1000;
    >
    > suma_sigm=(float *)malloc(sizeof(float)*n_sigm);
    >
    > if(rank != 0)
    > {
    > for(j=0;j<n_sigm;j++)
    > suma_sigm[j]=rank*1000+j;
    > }
    > else
    > {
    > for(j=0;j<n_sigm;j++)
    > s_tmp[j]=0;


    At this point, s_tmp is still indeterminate; it does not yet point to
    any memory you can access. s_tmp[j] does not exist. This invokes
    undefined behavior.

    > }
    > s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference


    And if the previous undefined behavior were not sufficient, this would
    replace the address that s_tmp was pointing to with the address of the
    newly allocated memory making all the elements of the array
    indeterminate again.

    > MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    > 0,MPI_COMM_WORLD);
    > if( rank == 0 )
    > for(j=0;j<n_sigm;j++)
    > printf("%i %f\n",j,s_tmp[j]);
    > free(suma_sigm);
    > free(s_tmp);
    > MPI_Finalize();
    >
    > }
    >
    > And why value of s_tmp[0] & s_tmp[1] is incorrect (in working
    > version).


    By definition, a working version would produce correct results. What
    is the vlaue of rank when you see these incorrect values? What is the
    function MPI_Reduce supposed to do with the two arrays you pass?
    Barry Schwarz, Oct 21, 2007
    #6
  7. "dopiotr" <> wrote in message
    > Hello Group,
    >
    > int Msg[size];
    > MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    > this is working fine.
    >
    > But how to send Msg declared like this:
    > int *Msg=(int*)malloc(sizeof(int)*size);
    >
    > It gives me
    > p4_error: interrupt SIGSEGV: 11
    > not_send: could not write to fd=4, errno = 32
    >

    Should be fine. If the call sends a static array it should work exactly the
    same way with a dynamic buffer allocated with malloc(). This is a general
    feature of C functions, not just MPI.

    However you have to know the message length, and allocate another buffer, to
    receive the message at the other end.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Oct 21, 2007
    #7
  8. dopiotr

    Tor Rustad Guest

    dopiotr wrote:
    > Hello Group,
    >
    > int Msg[size];
    > MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    > this is working fine.
    >
    > But how to send Msg declared like this:
    > int *Msg=(int*)malloc(sizeof(int)*size);


    Have you included <stdlib.h>? We recommend dropping the cast, and write
    this:

    int *Msg = malloc(sizeof(int)*size);

    > It gives me
    > p4_error: interrupt SIGSEGV: 11
    > not_send: could not write to fd=4, errno = 32


    MPI related questions are off-topic here, try

    comp.parallel.mpi


    --
    Tor <torust [at] online [dot] no>

    "Technical skill is mastery of complexity, while creativity is mastery
    of simplicity"
    Tor Rustad, Oct 21, 2007
    #8
  9. Tor Rustad said:

    > dopiotr wrote:
    >> int *Msg=(int*)malloc(sizeof(int)*size);

    >
    > Have you included <stdlib.h>? We recommend dropping the cast, and write
    > this:
    >
    > int *Msg = malloc(sizeof(int)*size);


    Who's this "we"? Dropping the cast, sure, but repeating the type? Blech.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Oct 21, 2007
    #9
  10. dopiotr

    Richard Guest

    CryptiqueGuy <> writes:

    > On Oct 22, 12:45 am, dopiotr <> wrote:
    >> Hello Group,
    >>
    >> int Msg[size];
    >> MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    >> this is working fine.
    >>
    >> But how to send Msg declared like this:
    >> int *Msg=(int*)malloc(sizeof(int)*size);
    >>

    >
    > Did u check the return value of malloc?
    > It might be NULL, due to failed memory allocation.


    I wonder how many times people have come across this? I must admit that
    malloc has never failed me under Linux or Windows...
    Richard, Oct 21, 2007
    #10
  11. dopiotr

    Tor Rustad Guest

    Richard Heathfield wrote:
    > Tor Rustad said:
    >
    >> dopiotr wrote:
    >>> int *Msg=(int*)malloc(sizeof(int)*size);

    >> Have you included <stdlib.h>? We recommend dropping the cast, and write
    >> this:
    >>
    >> int *Msg = malloc(sizeof(int)*size);

    >
    > Who's this "we"?


    The FAQ

    > Dropping the cast, sure, but repeating the type? Blech.


    Agreed, I didn't notice the sizeof(type).


    int *msg = malloc(sizeof(*msg) * size);


    --
    Tor <torust [at] online [dot] no>

    "Technical skill is mastery of complexity, while creativity is mastery
    of simplicity"
    Tor Rustad, Oct 21, 2007
    #11
  12. dopiotr

    Tor Rustad Guest

    Richard wrote:
    > CryptiqueGuy <> writes:


    [...]

    >> Did u check the return value of malloc?
    >> It might be NULL, due to failed memory allocation.

    >
    > I wonder how many times people have come across this?


    I can remember, doing my first matrix computations under DOS. The C
    compiler had a size limit at 64 kb for objects. Not only could malloc
    fail, but the max matrix size, was rather useless for doing scientific
    double precision calculations.

    > I must admit that malloc has never failed me under Linux or Windows...


    With the default setting in Linux, malloc should never fail. :)

    --
    Tor <torust [at] online [dot] no>

    "Technical skill is mastery of complexity, while creativity is mastery
    of simplicity"
    Tor Rustad, Oct 22, 2007
    #12
  13. Tor Rustad said:

    > Richard Heathfield wrote:
    >> Tor Rustad said:
    >>
    >>> dopiotr wrote:
    >>>> int *Msg=(int*)malloc(sizeof(int)*size);
    >>> Have you included <stdlib.h>? We recommend dropping the cast, and write
    >>> this:
    >>>
    >>> int *Msg = malloc(sizeof(int)*size);

    >>
    >> Who's this "we"?

    >
    > The FAQ


    Then the FAQ needs fixing. The above is poor style, and it is evident that
    you agree...

    >> Dropping the cast, sure, but repeating the type? Blech.

    >
    > Agreed, I didn't notice the sizeof(type).
    >
    >
    > int *msg = malloc(sizeof(*msg) * size);


    Close enough. Personally, I'd use: int *msg = malloc(size * sizeof *msg);

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Oct 22, 2007
    #13
  14. dopiotr

    Guest

    In article <>,
    Barry Schwarz <> wrote:
    > On Oct 21, 1:06 pm, dopiotr <> wrote:
    >
    > snip
    >
    > > > dopiotr wrote:

    > >
    > > >> Hello Group,

    > >
    > > >> int Msg[size];
    > > >> MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD);
    > > >> this is working fine.

    > >
    > > >> But how to send Msg declared like this:
    > > >> int *Msg=(int*)malloc(sizeof(int)*size);

    > >
    > > >> It gives me
    > > >> p4_error: interrupt SIGSEGV: 11
    > > >> not_send: could not write to fd=4, errno = 32

    >
    > snip
    >
    > > Working wersion:

    >
    > This is not a working version. It invokes undefined behavior and you
    > state it produces incorrect results.



    First -- agreed that this is off-topic and that comp.parallel.mpi
    would be a more appropriate newsgroup. A couple of points for the
    record, one here, one later:

    When I correct the problems mentioned by others here, the OP's
    program produces what appear to me to be correct results (using
    OpenMPI on a Fedora 7 system).


    > > #include "mpi.h"
    > > #include<stdio.h>
    > > #include<stdlib.h>
    > > uint n_sigm;
    > > float *suma_sigm;
    > >
    > > void main(int c, char *v[])

    >
    > main should return int.
    >
    > > {
    > > int size,rank;
    > > int j;
    > > float *s_tmp;
    > > MPI_Init(&c,&v);
    > > MPI_Comm_size(MPI_COMM_WORLD,&size);
    > > MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    > > n_sigm=1000;
    > >
    > > suma_sigm=(float *)malloc(sizeof(float)*n_sigm);

    >
    > Do not cast the return from malloc. It can never help and the only
    > effect would be to suppress a diagnostic you really want to see if it
    > applies to your code.
    >
    > > s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference

    >
    > You should always check that malloc succeeds.
    >
    > >
    > > if(rank != 0)
    > > {
    > > for(j=0;j<n_sigm;j++)
    > > suma_sigm[j]=rank*1000+j;
    > > }
    > > else
    > > {
    > > for(j=0;j<n_sigm;j++)
    > > s_tmp[j]=0;
    > > }

    >
    > At this point, the elements of suma_sigm or s_tmp (but not both) have
    > been assigned values. The elements of the other array are
    > indeterminate (uninitialized).
    >
    > > MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    > > 0,MPI_COMM_WORLD);

    >
    > Since you don't pass rank to this function, how is it supposed to
    > determine which of the arrays has valid values and which doesn't. Any
    > attempt by the function to evaluate an indeterminate element will
    > invoke undefined behavior.



    Well, this *is* a library function, part of the same library that
    initialized the local "rank" variable in the first place (via
    the call to MPI_Comm_rank). Agreed that this isn't necessarily
    obvious to readers of comp.lang.c, of course.


    > > if( rank == 0 )
    > > for(j=0;j<n_sigm;j++)
    > > printf("%i %f\n",j,s_tmp[j]);
    > > free(suma_sigm);
    > > free(s_tmp);
    > > MPI_Finalize();
    > >
    > > }
    > >
    > > Why it is not working:
    > > #include "mpi.h"
    > > #include<stdio.h>
    > > #include<stdlib.h>
    > > uint n_sigm;
    > > float *suma_sigm;
    > > int main(int c, char *v[])
    > > {
    > > int size,rank;
    > > int j;
    > > float *s_tmp;
    > > MPI_Init(&c,&v);
    > > MPI_Comm_size(MPI_COMM_WORLD,&size);
    > > MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    > > n_sigm=1000;
    > >
    > > suma_sigm=(float *)malloc(sizeof(float)*n_sigm);
    > >
    > > if(rank != 0)
    > > {
    > > for(j=0;j<n_sigm;j++)
    > > suma_sigm[j]=rank*1000+j;
    > > }
    > > else
    > > {
    > > for(j=0;j<n_sigm;j++)
    > > s_tmp[j]=0;

    >
    > At this point, s_tmp is still indeterminate; it does not yet point to
    > any memory you can access. s_tmp[j] does not exist. This invokes
    > undefined behavior.
    >
    > > }
    > > s_tmp=(float *)malloc(sizeof(float)*n_sigm);//difference

    >
    > And if the previous undefined behavior were not sufficient, this would
    > replace the address that s_tmp was pointing to with the address of the
    > newly allocated memory making all the elements of the array
    > indeterminate again.
    >
    > > MPI_Reduce(suma_sigm,s_tmp ,n_sigm,MPI_FLOAT,MPI_SUM,
    > > 0,MPI_COMM_WORLD);
    > > if( rank == 0 )
    > > for(j=0;j<n_sigm;j++)
    > > printf("%i %f\n",j,s_tmp[j]);
    > > free(suma_sigm);
    > > free(s_tmp);
    > > MPI_Finalize();
    > >
    > > }
    > >
    > > And why value of s_tmp[0] & s_tmp[1] is incorrect (in working
    > > version).

    >
    > By definition, a working version would produce correct results. What
    > is the vlaue of rank when you see these incorrect values? What is the
    > function MPI_Reduce supposed to do with the two arrays you pass?
    >


    --
    B. L. Massingill
    ObDisclaimer: I don't speak for my employers; they return the favor.
    , Oct 22, 2007
    #14
  15. "Tor Rustad" <> a écrit dans le message de news:
    ...
    >
    > "Technical skill is mastery of complexity, while creativity is mastery of
    > simplicity"


    What a striking quote! (attributed to Erik Christopher Zeeman)

    --
    Chqrlie.
    Charlie Gordon, Oct 22, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,028
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  2. pmatos
    Replies:
    6
    Views:
    23,727
  3. Replies:
    8
    Views:
    1,890
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    543
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    347
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page