[Mochi-devel] Error in the bulk transfer example in Mochi documentation

Dorier, Matthieu mdorier at anl.gov
Fri Apr 10 05:32:40 CDT 2020


Hi Hyogi,

I think you're right. I'll correct the documentation.
Thanks for reporting the issue!

Matthieu

On 09/04/2020, 21:18, "mochi-devel on behalf of Sim, Hyogi" <mochi-devel-bounces at lists.mcs.anl.gov on behalf of simh at ornl.gov> wrote:

    Hello,
    
    I think the bulk transfer example program in the Mochi documentation (https://mochi.readthedocs.io/en/latest/margo/04_bulk.html) is wrong. Specifically, in the client code:
    
    ---
    int32_t values[10] = { 1,4,2,5,6,3,5,3,2,5 };
    hg_size_t size = 10*sizeof(int32_t);
    
    hg_bulk_t local_bulk;
    margo_bulk_create(mid, 1, (void**)&values, &size, HG_BULK_READ_ONLY, &local_bulk);
    ---
    
    The second parameter of `margo_bulk_create` is expected to be an array of segment addresses (void * type). But, since `values` is an array (instead of a pointer), `&values` becomes the address of the first element in the array (instead of the address of the pointer as intended). This results in a segmentation fault when serializing the data (`hg_bulk_serialize_memcpy`), because it tries to access address '1' (the first integer element in the `values` array), instead of the address of the `values`:
    
    ---
    Breakpoint 3 at 0x7ffff77aac2c: file /home/hyogi/workspace/mochi/mercury/src/mercury_bulk.c, line 405.
    (gdb) c
    Continuing.
    
    Breakpoint 3, hg_bulk_create (hg_class=0xa04450, count=1, buf_ptrs=0x7fffffffd2a0, buf_sizes=0x7fffffffd2e8,
    	flags=1 '\001', hg_bulk_ptr=0x7fffffffd230) at /home/hyogi/workspace/mochi/mercury/src/mercury_bulk.c:405
    405         	hg_bulk->segments[i].size = buf_sizes[i];
    (gdb) n
    406         	hg_bulk->total_size += hg_bulk->segments[i].size;
    (gdb)
    408         	if (buf_ptrs)
    (gdb)
    409             	hg_bulk->segments[i].address = (hg_ptr_t) buf_ptrs[i];
    (gdb) p buf_ptrs[i]
    $5 = (void *) 0x400000001
    (gdb) p (int)buf_ptrs[i]
    $6 = 1
    
    ...
    
    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff6e1fb90 in __memcpy_sse2 () from /lib64/libc.so.6
    (gdb) bt
    #0  0x00007ffff6e1fb90 in __memcpy_sse2 () from /lib64/libc.so.6
    #1  0x00007ffff77aa931 in hg_bulk_serialize_memcpy (dest=0x7fffffffced0, dest_left=0x7fffffffcec8,
    	src=0x400000001, n=40) at /home/hyogi/workspace/mochi/mercury/src/mercury_bulk.c:332
    #2  0x00007ffff77adedd in HG_Bulk_serialize (buf=0xa8c024, buf_size=107, request_eager=1 '\001', handle=0xa294c0)
    	at /home/hyogi/workspace/mochi/mercury/src/mercury_bulk.c:1445
    #3  0x000000000040118e in hg_proc_hg_bulk_t (proc=0xa290d0, data=0x7fffffffd2f8)
    	at /home/hyogi/workspace/mochi/__prefix/include/mercury_proc_bulk.h:67
    #4  0x000000000040134f in hg_proc_sum_in_t (proc=0xa290d0, data=0x7fffffffd2f0) at bulk-types.h:7
    #5  0x00007ffff77a6076 in hg_set_struct (hg_handle=0xa29010, hg_proc_info=0xa19fc0, op=HG_INPUT,
    	struct_ptr=0x7fffffffd2f0, payload_size=0x7fffffffd060, more_data=0x7fffffffd05f "")
    	at /home/hyogi/workspace/mochi/mercury/src/mercury.c:642
    #6  0x00007ffff77a9daf in HG_Forward (handle=0xa29010, callback=0x7ffff7bcf781 <margo_cb>, arg=0x7fffffffd210,
    	in_struct=0x7fffffffd2f0) at /home/hyogi/workspace/mochi/mercury/src/mercury.c:1900
    #7  0x00007ffff7bd0387 in margo_provider_iforward_internal (provider_id=0, handle=0xa29010, timeout_ms=0,
    	in_struct=0x7fffffffd2f0, req=0x7fffffffd210) at ../src/margo.c:1264
    #8  0x00007ffff7bd043b in margo_provider_forward_timed (provider_id=0, handle=0xa29010, in_struct=0x7fffffffd2f0,
    	timeout_ms=0) at ../src/margo.c:1292
    #9  0x00007ffff7bd03c3 in margo_provider_forward (provider_id=0, handle=0xa29010, in_struct=0x7fffffffd2f0)
    	at ../src/margo.c:1272
    #10 0x0000000000401630 in main (argc=2, argv=0x7fffffffd418) at bulk-client.c:57
    (gdb) f 1
    #1  0x00007ffff77aa931 in hg_bulk_serialize_memcpy (dest=0x7fffffffced0, dest_left=0x7fffffffcec8,
    	src=0x400000001, n=40) at /home/hyogi/workspace/mochi/mercury/src/mercury_bulk.c:332
    332     	memcpy(*dest, src, n);
    (gdb) p src
    $7 = (const void *) 0x400000001
    (gdb)
    
    ---
    
    So, the `values` array should be dynamically allocated as in the server code, or another pointer variable should be used before passing to `margo_bulk_create`:
    
    --
    void *pvalues = values;
    margo_bulk_create(mid, 1, &pvalues, ...);
    --
    
    Thanks,
    Hyogi
    
    _______________________________________________
    mochi-devel mailing list
    mochi-devel at lists.mcs.anl.gov
    https://lists.mcs.anl.gov/mailman/listinfo/mochi-devel
    https://www.mcs.anl.gov/research/projects/mochi
    



More information about the mochi-devel mailing list