Folks,

Here is attached a simplified C only version of the test program.
it can be ran with two or one task.

on rhel7, valgrind complains about an invalid read when accessing the recv buffer after MPI_Recv.
this is pretty odd since :
- the buffer is initialized *before* MPI_Recv is invoked
- MPI_Recv *do* write the buffer

i added some trace, and OpenMPI told valgrind to mark the buffer as non accessible
(e.g. VALGRIND_MAKE_MEM_NOACCESS) *after* it marked it as defined
(e.g. VALGRIND_MAKE_MEM_DEFINED)

the issue can be seen on both master and v1.10 when OpenMPI is configure'd with
--enable-memchecker --with-valgrind

in mca_pml_ob1_recv_request_progress_match() from ompi/mca/pml/ob1/pml_ob1_recvreq.c, what is the rationale for marking the buffer an unaccessable after the unpack ?

    /*
     *  Unpacking finished, make the user buffer unaccessable again.
     */
    MEMCHECKER(
memchecker_call(&opal_memchecker_base_mem_noaccess,
recvreq->req_recv.req_base.req_addr,
recvreq->req_recv.req_base.req_count,
recvreq->req_recv.req_base.req_datatype);
               );

also, in MPI_Send (ompi/mpi/c/isend.c) what is the rationale for marking the buffer as non accessible before calling the PML isend ? if this is an attempt to track users modifying the buffer after MPI_Isend(), should valgrind be invoked *after* the PML is invoked ?

if i #if out these two calls, then the test program runs just fine

fwiw :
- MPI_Sendrecv do not issue any warning
- MPI_Send/MPI_Recv issues one warning in the test code
- MPI_Isend/MPI_Recv issues three warning, one in the test, and two in OpenMPI i previously reported a very weird behaviour ... and the root cause is one subroutine in the test program was called "send", which conflicts with the send libc function ...


Cheers,

Gilles

On 3/3/2016 9:43 PM, Jeff Squyres (jsquyres) wrote:
All of those valgrind reports below are from within your code -- not from 
within Open MPI.

All Open MPI can do is pass the contents of your message properly; you can 
verify that it is being sent and received properly by checking the byte 
contents of your received array (e.g., assert that the string is there 
correctly and is \0-terminated).

If cout or some other std:: thing is going beyond the end of your allocated 
buffer, that's a different problem -- perhaps you have a busted std:: 
implementation...?


On Mar 3, 2016, at 2:47 AM, Florian Lindner <mailingli...@xgm.de> wrote:

I am still getting errors, even with your script.

I will also try to modified build of openmpi that Jeff suggested.

Best,
Florian

% mpicxx -std=c++11 -g -O0 -Wall -Wextra -fno-builtin-strlen mpi_gilles.cpp && 
mpirun -n 2 ./a.out
Stringlength = 64
123456789012345678901234567890123456789012345678901234567890123

% LD_PRELOAD=/usr/lib/valgrind/libmpiwrap-amd64-linux.so mpirun -n 2 valgrind 
./a.out
==5324== Memcheck, a memory error detector
==5324== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==5324== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==5324== Command: ./a.out
==5324==
==5325== Memcheck, a memory error detector
==5325== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==5325== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==5325== Command: ./a.out
==5325==
valgrind MPI wrappers  5324: Active for pid 5324
valgrind MPI wrappers  5324: Try MPIWRAP_DEBUG=help for possible options
valgrind MPI wrappers  5325: Active for pid 5325
valgrind MPI wrappers  5325: Try MPIWRAP_DEBUG=help for possible options
Stringlength = 64
==5325== Invalid read of size 1
==5325==    at 0x4C2D992: strlen (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x56852D8: length (char_traits.h:267)
==5325==    by 0x56852D8: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:562)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff800 is on thread 1's stack
==5325==  in frame #2, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 1
==5325==    at 0x4C2D9A4: strlen (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x56852D8: length (char_traits.h:267)
==5325==    by 0x56852D8: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:562)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff801 is on thread 1's stack
==5325==  in frame #2, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 1
==5325==    at 0x60A0FF1: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff83e is on thread 1's stack
==5325==  in frame #4, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 1
==5325==    at 0x60A100D: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff83d is on thread 1's stack
==5325==  in frame #4, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 8
==5325==    at 0x4C2F758: __GI_memcpy (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff800 is on thread 1's stack
==5325==  in frame #5, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 8
==5325==    at 0x4C2F766: __GI_memcpy (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff810 is on thread 1's stack
==5325==  in frame #5, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 2
==5325==    at 0x4C2F7B0: __GI_memcpy (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff838 is on thread 1's stack
==5325==  in frame #5, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 2
==5325==    at 0x4C2F7BE: __GI_memcpy (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff83c is on thread 1's stack
==5325==  in frame #5, created by receive() (mpi_gilles.cpp:8)
==5325==
==5325== Invalid read of size 1
==5325==    at 0x4C2F7E8: __GI_memcpy (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5325==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in 
/usr/lib/libc-2.23.so)
==5325==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==5325==    by 0x5684F75: sputn (streambuf:451)
==5325==    by 0x5684F75: __ostream_write<char, std::char_traits<char> > 
(ostream_insert.h:50)
==5325==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, 
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) 
(ostream_insert.h:101)
==5325==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char> >& std::operator<< 
<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) 
(ostream:561)
==5325==    by 0x408A45: receive() (mpi_gilles.cpp:22)
==5325==    by 0x408B88: main (mpi_gilles.cpp:44)
==5325==  Address 0xffefff83e is on thread 1's stack
==5325==  in frame #5, created by receive() (mpi_gilles.cpp:8)
==5325==
123456789012345678901234567890123456789012345678901234567890123
==5325==
==5325== HEAP SUMMARY:
==5325==     in use at exit: 96,351 bytes in 247 blocks
==5325==   total heap usage: 15,007 allocs, 14,760 frees, 13,362,050 bytes 
allocated
==5325==
==5325== LEAK SUMMARY:
==5325==    definitely lost: 9,154 bytes in 39 blocks
==5325==    indirectly lost: 4,008 bytes in 22 blocks
==5325==      possibly lost: 0 bytes in 0 blocks
==5325==    still reachable: 83,189 bytes in 186 blocks
==5325==         suppressed: 0 bytes in 0 blocks
==5325== Rerun with --leak-check=full to see details of leaked memory
==5325==
==5325== For counts of detected and suppressed errors, rerun with: -v
==5325== ERROR SUMMARY: 138 errors from 9 contexts (suppressed: 0 from 0)
==5324==
==5324== HEAP SUMMARY:
==5324==     in use at exit: 96,351 bytes in 247 blocks
==5324==   total heap usage: 15,028 allocs, 14,781 frees, 13,370,286 bytes 
allocated
==5324==
==5324== LEAK SUMMARY:
==5324==    definitely lost: 9,154 bytes in 39 blocks
==5324==    indirectly lost: 4,008 bytes in 22 blocks
==5324==      possibly lost: 0 bytes in 0 blocks
==5324==    still reachable: 83,189 bytes in 186 blocks
==5324==         suppressed: 0 bytes in 0 blocks
==5324== Rerun with --leak-check=full to see details of leaked memory
==5324==
==5324== For counts of detected and suppressed errors, rerun with: -v
==5324== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Am Donnerstag, 3. März 2016, 14:53:24 CET schrieb Gilles Gouaillardet:
I was unable to reproduce this in my environment.

here is a slightly modified version of your test program.
buffers are 64 bytes aligned and the string (including the null
terminator) is 64 bytes long,
hopefully, strlen will not complain any more.

Cheers,

Gilles

On 3/3/2016 12:51 AM, Florian Lindner wrote:
Hello Gilles,

Am Mittwoch, 2. März 2016, 23:36:56 CET schrieb Gilles Gouaillardet:
Florian,

under the hood, strlen() can use vector instructions, and then read memory
above the end of the string. valgrind is extremely picky and does warn
about that.
iirc, there are some filter options not to issue these warnings, but I
forgot the details.
Ok, i'll try to research in that direction.

can you try to send "Bonjour" instead of "Halo" and see if the warning
disappear ?
They are still there. But, was this meant as a joke or didn't I understand?

Best,
Florian

Cheers,

Gilles

PS if it works, do not jump to the erroneous conclusion valgrind likes
French and dislikes German ;-)

On Wednesday, March 2, 2016, Florian Lindner <mailingli...@xgm.de> wrote:

Hello,

using OpenMPI 1.10.2 and valgrind 3.11.0 I try to use the code below to
send a c++ string.

It works fine, but running through valgrind gives a lot of memory errors,
invalid read of size...

What is going wrong there?

Valgrind output, see below.

Thanks!
Florian


// Compile with: mpicxx -std=c++11 -g -O0 -Wall -Wextra mpi.cpp
#include <mpi.h>
#include <iostream>
#include <string>

using namespace std;


void receive() {
   int length = 0;
   MPI_Status status;
   MPI_Probe(MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
   MPI_Get_count(&status, MPI_CHAR, &length);
   cout << "Stringlength = " << length << endl;
   char cstr[length];
   MPI_Recv(cstr,
            length,
            MPI_CHAR,
            MPI_ANY_SOURCE,
            MPI_ANY_TAG,
            MPI_COMM_WORLD,
            MPI_STATUS_IGNORE);
   cout << cstr << endl;
}

void send(int rankReceiver) {
   std::string s = "Hallo";
   MPI_Send(s.c_str(),
            s.size()+1,
            MPI_CHAR,
            rankReceiver,
            0,
            MPI_COMM_WORLD);
}

int main(int argc, char* argv[])
{
   int rank;
   MPI_Init(&argc, &argv);

   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   if (rank == 0)
     send(1);
   else {
     receive();
   }
   MPI_Finalize();
   return 0;
}


VALGRIND OUTPUT

% mpicxx -std=c++11 -g -O0 -Wall -Wextra mpi.cpp && mpirun -n 2 ./a.out
Stringlength = 6
Hallo
florian@asaru ~/scratch (git)-[master] %
LD_PRELOAD=/usr/lib/valgrind/libmpiwrap-amd64-linux.so mpirun -n 2 valgrind
./a.out
==9290== Memcheck, a memory error detector
==9290== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==9290== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==9290== Command: ./a.out
==9290==
==9291== Memcheck, a memory error detector
==9291== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==9291== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==9291== Command: ./a.out
==9291==
valgrind MPI wrappers  9290: Active for pid 9290
valgrind MPI wrappers  9291: Active for pid 9291
valgrind MPI wrappers  9290: Try MPIWRAP_DEBUG=help for possible options
valgrind MPI wrappers  9291: Try MPIWRAP_DEBUG=help for possible options
Stringlength = 6
==9291== Invalid read of size 1
==9291==    at 0x4C2DBA2: strlen (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9291==    by 0x56852D8: length (char_traits.h:267)
==9291==    by 0x56852D8: std::basic_ostream<char, std::char_traits<char>
& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (ostream:562)
==9291==    by 0x408A39: receive() (mpi.cpp:22)
==9291==    by 0x408B61: main (mpi.cpp:46)
==9291==  Address 0xffefff870 is on thread 1's stack
==9291==  in frame #2, created by receive() (mpi.cpp:8)
==9291==
==9291== Invalid read of size 1
==9291==    at 0x4C2DBB4: strlen (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9291==    by 0x56852D8: length (char_traits.h:267)
==9291==    by 0x56852D8: std::basic_ostream<char, std::char_traits<char>
& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (ostream:562)
==9291==    by 0x408A39: receive() (mpi.cpp:22)
==9291==    by 0x408B61: main (mpi.cpp:46)
==9291==  Address 0xffefff871 is on thread 1's stack
==9291==  in frame #2, created by receive() (mpi.cpp:8)
==9291==
==9291== Invalid read of size 1
==9291==    at 0x60A0FF1: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/
libc-2.23.so)
==9291==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==9291==    by 0x5684F75: sputn (streambuf:451)
==9291==    by 0x5684F75: __ostream_write<char, std::char_traits<char> >
(ostream_insert.h:50)
==9291==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char>
& std::__ostream_insert<char, std::char_traits<char>
(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
(ostream_insert.h:101)
==9291==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char>
& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (ostream:561)
==9291==    by 0x408A39: receive() (mpi.cpp:22)
==9291==    by 0x408B61: main (mpi.cpp:46)
==9291==  Address 0xffefff874 is on thread 1's stack
==9291==  in frame #4, created by receive() (mpi.cpp:8)
==9291==
==9291== Invalid read of size 1
==9291==    at 0x60A100D: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/
libc-2.23.so)
==9291==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==9291==    by 0x5684F75: sputn (streambuf:451)
==9291==    by 0x5684F75: __ostream_write<char, std::char_traits<char> >
(ostream_insert.h:50)
==9291==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char>
& std::__ostream_insert<char, std::char_traits<char>
(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
(ostream_insert.h:101)
==9291==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char>
& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (ostream:561)
==9291==    by 0x408A39: receive() (mpi.cpp:22)
==9291==    by 0x408B61: main (mpi.cpp:46)
==9291==  Address 0xffefff873 is on thread 1's stack
==9291==  in frame #4, created by receive() (mpi.cpp:8)
==9291==
==9291== Invalid read of size 2
==9291==    at 0x4C2F9C0: __GI_memcpy (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9291==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/
libc-2.23.so)
==9291==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==9291==    by 0x5684F75: sputn (streambuf:451)
==9291==    by 0x5684F75: __ostream_write<char, std::char_traits<char> >
(ostream_insert.h:50)
==9291==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char>
& std::__ostream_insert<char, std::char_traits<char>
(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
(ostream_insert.h:101)
==9291==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char>
& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (ostream:561)
==9291==    by 0x408A39: receive() (mpi.cpp:22)
==9291==    by 0x408B61: main (mpi.cpp:46)
==9291==  Address 0xffefff870 is on thread 1's stack
==9291==  in frame #5, created by receive() (mpi.cpp:8)
==9291==
==9291== Invalid read of size 1
==9291==    at 0x4C2F9F8: __GI_memcpy (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9291==    by 0x60A0F3A: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/
libc-2.23.so)
==9291==    by 0x6096D1A: fwrite (in /usr/lib/libc-2.23.so)
==9291==    by 0x5684F75: sputn (streambuf:451)
==9291==    by 0x5684F75: __ostream_write<char, std::char_traits<char> >
(ostream_insert.h:50)
==9291==    by 0x5684F75: std::basic_ostream<char, std::char_traits<char>
& std::__ostream_insert<char, std::char_traits<char>
(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
(ostream_insert.h:101)
==9291==    by 0x56852E6: std::basic_ostream<char, std::char_traits<char>
& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (ostream:561)
==9291==    by 0x408A39: receive() (mpi.cpp:22)
==9291==    by 0x408B61: main (mpi.cpp:46)
==9291==  Address 0xffefff874 is on thread 1's stack
==9291==  in frame #5, created by receive() (mpi.cpp:8)
==9291==
Hallo
==9291==
==9291== HEAP SUMMARY:
==9291==     in use at exit: 96,351 bytes in 247 blocks
==9291==   total heap usage: 15,020 allocs, 14,773 frees, 13,362,383 bytes
allocated
==9291==
==9291== LEAK SUMMARY:
==9291==    definitely lost: 9,154 bytes in 39 blocks
==9291==    indirectly lost: 4,008 bytes in 22 blocks
==9291==      possibly lost: 0 bytes in 0 blocks
==9291==    still reachable: 83,189 bytes in 186 blocks
==9291==         suppressed: 0 bytes in 0 blocks
==9291== Rerun with --leak-check=full to see details of leaked memory
==9291==
==9291== For counts of detected and suppressed errors, rerun with: -v
==9291== ERROR SUMMARY: 14 errors from 6 contexts (suppressed: 0 from 0)
==9290==
==9290== HEAP SUMMARY:
==9290==     in use at exit: 96,351 bytes in 247 blocks
==9290==   total heap usage: 15,018 allocs, 14,771 frees, 13,370,045 bytes
allocated
==9290==
==9290== LEAK SUMMARY:
==9290==    definitely lost: 9,154 bytes in 39 blocks
==9290==    indirectly lost: 4,008 bytes in 22 blocks
==9290==      possibly lost: 0 bytes in 0 blocks
==9290==    still reachable: 83,189 bytes in 186 blocks
==9290==         suppressed: 0 bytes in 0 blocks
==9290== Rerun with --leak-check=full to see details of leaked memory
==9290==
==9290== For counts of detected and suppressed errors, rerun with: -v
==9290== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

_______________________________________________
users mailing list
us...@open-mpi.org <javascript:;>
Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
Link to this post:
http://www.open-mpi.org/community/lists/users/2016/03/28617.php

_______________________________________________
users mailing list
us...@open-mpi.org
Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
Link to this post: 
http://www.open-mpi.org/community/lists/users/2016/03/28619.php


_______________________________________________
users mailing list
us...@open-mpi.org
Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
Link to this post: 
http://www.open-mpi.org/community/lists/users/2016/03/28623.php


#include <stdio.h>
#include <mpi.h>
#include <string.h>

#define SUBROUTINE 1

void mysend() {
    const char * s = "Halo";
    MPI_Send(s, strlen(s)+1, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
}

void myreceive() {
    char buf[256];
    MPI_Recv(buf, 256, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    if ('H' != buf[0]) {
        fprintf(stderr,"not H\n");
    }
}
void mysendrecv() {
    const char * s = "Halo";
    char buf[256];
    MPI_Request request;
    buf[0] = 0;
    if (0 != buf[0]) {
        fprintf(stderr,"not 0\n");
    }
#if 0
    MPI_Sendrecv(s, strlen(s)+1, MPI_CHAR, 0, 0, buf, 256, MPI_CHAR, 0, 0, 
MPI_COMM_WORLD, MPI_STATUS_IGNORE);
#elif 0
    MPI_Isend(s, strlen(s)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &request);
    MPI_Recv(buf, 256, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    MPI_Wait(&request, MPI_STATUS_IGNORE);
#else
    MPI_Send(s, strlen(s)+1, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
    MPI_Recv(buf, 256, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
#endif
    if ('H' != buf[0]) {
        fprintf(stderr,"not H\n");
    }
}

int main(int argc, char *argv[]) {
  int rank, size;
  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  printf ("rank = %d / %d\n", rank, size);
  if (1 == size) {
    mysendrecv();
  } else if (0 == rank) {
    mysend();
  } else if (1 == rank) {
    myreceive();
  }

  MPI_Finalize();
  return 0;
}

Reply via email to