6

I need to get min-cut partitions of a given graph iteratively until a subgraph has number of odes below some given threshold min_node. This will be used as a preprocessing step for the CHAMELEON clustering algorithm. For that i am using METIS library with R. I have made a simple wrapper for the METIS_PartGraphRecursive () function in the METIS library, which i am using to call from R code with the .C interface. Calling the wrapper function goes okay, and does the partition and returns the result which i process and retrieve the subgraphs by eliminating the edged between the two partitions. Then i pass one of the subgraph to make further partitions. This call crashes R. The crash trace is shown in the Crash Report section below. (UPDATE) Also the Valgrind output is shown below (as Martin Morgan Commented).

It seems that the cause of the crash is some code inside the METIS library.

I am posting the METIS wrapper i am using and also how i call this wrapper.

After crash fedora shows the notification that "A problem in the R-core-2.15.0-1.fc16 package has been detected". R is killed by the OS with SIGABRT or SIGSEGV, and the bug reporting tool message tells the following:

 Source     Problem                                                           
 kernel     BUG: unable to handle kernel NULL pointer dereference at 00000004 

My system:

$ uname -r
3.3.7-1.fc16.x86_64

Can anyone help me resolve this issue ?

Test data set

> x
      [,1] [,2]
 [1,]   13    0
 [2,]    9    0
 [3,]   11   26
 [4,]    9    1
 [5,]   13    2
 [6,]    5    3
 [7,]    6    0
 [8,]   17   13
 [9,]    1    6
[10,]    6   14
[11,]    4    6
[12,]   15   10
[13,]    1    1

Sample run

Graph in metis format generated from the above points partitioned once, which is working okay in this particular example. But if i take one of the partitioned component and further repartition it, then the program crashes. Also with a larger data set with 600 points the very first partition crashes.

> cm (x, 4)
The below graph is to be partitioned: 
$xadj
 [1]  1  5  9 13 17 21 25 29 33 37 41 45 49 53

$adjncy
 [1]  5  2  4  7  4  7  1  5 10  8 12 11  2  7  1  5  1  4  2  7  7 11 13  4  2
[26]  6  4 13 12 10  5  1 11 13  6  7 11  9 12  8  9  6 13  7  8  5 10  1  6  9
[51]  7 11

$adjwgt
 [1]  2.000000  4.000000  4.123106  7.000000  1.000000  3.000000  4.000000
 [8]  4.472136 13.000000 14.317821 16.492423 21.189620  1.000000  3.162278
[15]  4.123106  4.123106  2.000000  4.123106  4.472136  7.280110  3.162278
[22]  3.162278  4.472136  4.472136  3.000000  3.162278  3.162278  5.099020
[29]  3.605551 11.045361 11.704700 13.601471  3.000000  5.000000  5.000000
[36]  7.810250  8.246211  9.433981  9.848858 11.045361  3.000000  3.162278
[43]  5.830952  6.324555  3.605551  8.246211  9.848858 10.198039  4.472136
[50]  5.000000  5.099020  5.830952

#Original list of points
$vertex_id
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13

Initial Cut: 145

METIS_OK

Partition 1 list of original points
[[1]]
[[1]]$vertex_id
[1] 1 2 4 5 6 7

[[1]]$xadj
[1]  1  5  9 13 17 19 22

Point index local to this partition
[[1]]$adjncy
 [1] 5 2 4 7 4 7 1 5 2 7 1 5 1 4 2 7 7 4 2 6 4

[[1]]$adjwgt
 [1] 2.000000 4.000000 4.123106 7.000000 1.000000 3.000000 4.000000 4.472136
 [9] 1.000000 3.162278 4.123106 4.123106 2.000000 4.123106 4.472136 7.280110
[17] 3.162278 4.472136 3.000000 3.162278 3.162278


Partition 2 list of original points    
[[2]]
[[2]]$vertex_id
[1]  3  8  9 10 11 12 13

[[2]]$xadj
[1]  1  5  7  9 13 15 17 19

Point index local to this partition    
[[2]]$adjncy
 [1] 10  8 12 11 12 10 11 13 11  9 12  8  9 13  8 10  9 11

[[2]]$adjwgt
 [1] 13.000000 14.317821 16.492423 21.189620  3.605551 11.045361  3.000000
 [8]  5.000000  8.246211  9.433981  9.848858 11.045361  3.000000  5.830952
[15]  3.605551  9.848858  5.000000  5.830952

METIS wrapper

void metis_wrap (idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, idx_t *adjwgt, idx_t *nparts, idx_t *objval, idx_t *part)
{
  int retval, i, j;
  idx_t options[METIS_NOPTIONS];
  idx_t *vwgt = NULL, *vsize = NULL;
  real_t *ubvec = NULL, *tpwgts = NULL;

  METIS_SetDefaultOptions (options);
  options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT;
  options[METIS_OPTION_NUMBERING] = 1;
  options[METIS_OPTION_DBGLVL] = METIS_DBG_IPART;

  retval = METIS_PartGraphRecursive (nvtxs, ncon, xadj, adjncy, vwgt, vsize, adjwgt, nparts, tpwgts, ubvec, options, objval, part);

  switch (retval)
  {
    case METIS_OK:
      printf ("\nMETIS_OK\n");
      break;
    case METIS_ERROR_INPUT:
      printf ("\nMETIS_ERROR_INPUT\n");
      break;
    case METIS_ERROR_MEMORY:
      printf ("\nMETIS_ERROR_MEMORY\n");
      break;
    case METIS_ERROR:
      printf ("\nMETIS_ERROR\n");
      break;

  }
}

.C code within R

  part_graph <- function (knn_data)
  {
    nvtxs <- as.integer (length (knn_data$vertex_id));
    nparts <- 2; 
    ncon <- 1;
    ubvec <- 25;

    objval <- 0;
    part <- rep (0, nvtxs);

    knn_data$adjwgt <- 1/knn_data$adjwgt * 200;
    mode (knn_data$adjwgt) <- "integer";

    dyn.load ("libmetis.so");
    dyn.load ("metiswrap.so");
    ret <-.C ("metis_wrap", nvtxs = as.integer (nvtxs), ncon = as.integer (ncon), xadj = as.integer (knn_data$xadj), adjncy = as.integer (knn_data$adjncy), adjwgt = as.integer (knn_data$adjwgt), nparts = as.integer (nparts), objval = as.integer (objval), part = as.integer (part))

    return (list (part = ret$part, objval = ret$objval))
  }

Crash Report

*** glibc detected *** /usr/lib64/R/bin/exec/R: free(): invalid next size (fast): 0x000000000263a420 ***
======= Backtrace: =========
/lib64/libc.so.6[0x313a47dda6]
/lib64/libc.so.6[0x313a47f08e]
/home/phoxis/Documents/Works/Programming/R/libmetis.so(gk_free+0x9a)[0x7fd5ef3a7eba]
/home/phoxis/Documents/Works/Programming/R/libmetis.so(libmetis__FreeRData+0x71)[0x7fd5ef3cf5e1]
/home/phoxis/Documents/Works/Programming/R/libmetis.so(libmetis__FreeGraph+0x5a)[0x7fd5ef3cf65a]
/home/phoxis/Documents/Works/Programming/R/libmetis.so(libmetis__MlevelRecursiveBisection+0x15c)[0x7fd5ef3d242c]
/home/phoxis/Documents/Works/Programming/R/libmetis.so(METIS_PartGraphRecursive+0x166)[0x7fd5ef3d2796]
/home/phoxis/Documents/Works/Programming/R/metiswrap.so(metis_wrap+0xc6)[0x7fd5ef184d86]
/usr/lib64/R/lib/libR.so[0x376b8b148d]
/usr/lib64/R/lib/libR.so(Rf_eval+0x739)[0x376b8e1b09]
/usr/lib64/R/lib/libR.so[0x376b8e4790]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so[0x376b8e4910]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so(Rf_applyClosure+0x322)[0x376b8e5c32]
/usr/lib64/R/lib/libR.so(Rf_eval+0x430)[0x376b8e1800]
/usr/lib64/R/lib/libR.so[0x376b8e4790]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so[0x376b8e4910]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so[0x376b8e4910]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so[0x376b8e65ec]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so[0x376b8e4910]
/usr/lib64/R/lib/libR.so(Rf_eval+0x55b)[0x376b8e192b]
/usr/lib64/R/lib/libR.so(Rf_applyClosure+0x322)[0x376b8e5c32]
/usr/lib64/R/lib/libR.so(Rf_eval+0x430)[0x376b8e1800]
/usr/lib64/R/lib/libR.so(Rf_ReplIteration+0x1e3)[0x376b9178b3]
/usr/lib64/R/lib/libR.so[0x376b917b40]
/usr/lib64/R/lib/libR.so(run_Rmainloop+0x50)[0x376b918060]
/usr/lib64/R/bin/exec/R(main+0x1b)[0x40076b]
/lib64/libc.so.6(__libc_start_main+0xed)[0x313a42169d]
/usr/lib64/R/bin/exec/R[0x40079d]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:01 1051073                            /usr/lib64/R/bin/exec/R
00600000-00601000 r--p 00000000 08:01 1051073                            /usr/lib64/R/bin/exec/R
00601000-00603000 rw-p 00001000 08:01 1051073                            /usr/lib64/R/bin/exec/R
022f8000-03928000 rw-p 00000000 00:00 0                                  [heap]
313a000000-313a022000 r-xp 00000000 08:01 786460                         /lib64/ld-2.14.90.so
313a221000-313a222000 r--p 00021000 08:01 786460                         /lib64/ld-2.14.90.so
313a222000-313a223000 rw-p 00022000 08:01 786460                         /lib64/ld-2.14.90.so
313a223000-313a224000 rw-p 00000000 00:00 0 
313a400000-313a5ad000 r-xp 00000000 08:01 786461                         /lib64/libc-2.14.90.so
313a5ad000-313a7ad000 ---p 001ad000 08:01 786461                         /lib64/libc-2.14.90.so
313a7ad000-313a7b1000 r--p 001ad000 08:01 786461                         /lib64/libc-2.14.90.so
313a7b1000-313a7b3000 rw-p 001b1000 08:01 786461                         /lib64/libc-2.14.90.so
313a7b3000-313a7b8000 rw-p 00000000 00:00 0 
313a800000-313a883000 r-xp 00000000 08:01 788752                         /lib64/libm-2.14.90.so
313a883000-313aa82000 ---p 00083000 08:01 788752                         /lib64/libm-2.14.90.so
313aa82000-313aa83000 r--p 00082000 08:01 788752                         /lib64/libm-2.14.90.so
313aa83000-313aa84000 rw-p 00083000 08:01 788752                         /lib64/libm-2.14.90.so
313ac00000-313ac17000 r-xp 00000000 08:01 786462                         /lib64/libpthread-2.14.90.so
313ac17000-313ae16000 ---p 00017000 08:01 786462                         /lib64/libpthread-2.14.90.so
313ae16000-313ae17000 r--p 00016000 08:01 786462                         /lib64/libpthread-2.14.90.so
313ae17000-313ae18000 rw-p 00017000 08:01 786462                         /lib64/libpthread-2.14.90.so
313ae18000-313ae1c000 rw-p 00000000 00:00 0 
313b000000-313b002000 r-xp 00000000 08:01 786502                         /lib64/libdl-2.14.90.so
313b002000-313b202000 ---p 00002000 08:01 786502                         /lib64/libdl-2.14.90.so
313b202000-313b203000 r--p 00002000 08:01 786502                         /lib64/libdl-2.14.90.so
313b203000-313b204000 rw-p 00003000 08:01 786502                         /lib64/libdl-2.14.90.so
313b400000-313b407000 r-xp 00000000 08:01 786463                         /lib64/librt-2.14.90.so
313b407000-313b606000 ---p 00007000 08:01 786463                         /lib64/librt-2.14.90.so
313b606000-313b607000 r--p 00006000 08:01 786463                         /lib64/librt-2.14.90.so
313b607000-313b608000 rw-p 00007000 08:01 786463                         /lib64/librt-2.14.90.so
313b800000-313b815000 r-xp 00000000 08:01 788765                         /lib64/libgcc_s-4.6.3-20120306.so.1
313b815000-313ba14000 ---p 00015000 08:01 788765                         /lib64/libgcc_s-4.6.3-20120306.so.1
313ba14000-313ba15000 rw-p 00014000 08:01 788765                         /lib64/libgcc_s-4.6.3-20120306.so.1
313bc00000-313bc17000 r-xp 00000000 08:01 786474                         /lib64/libz.so.1.2.5
313bc17000-313be16000 ---p 00017000 08:01 786474                         /lib64/libz.so.1.2.5
313be16000-313be17000 rw-p 00016000 08:01 786474                         /lib64/libz.so.1.2.5
313ec00000-313ece8000 r-xp 00000000 08:01 150116                         /usr/lib64/libstdc++.so.6.0.16
313ece8000-313eee8000 ---p 000e8000 08:01 150116                         /usr/lib64/libstdc++.so.6.0.16
313eee8000-313eef0000 r--p 000e8000 08:01 150116                         /usr/lib64/libstdc++.so.6.0.16
313eef0000-313eef2000 rw-p 000f0000 08:01 150116                         /usr/lib64/libstdc++.so.6.0.16
313eef2000-313ef07000 rw-p 00000000 00:00 0 
3140400000-314043c000 r-xp 00000000 08:01 786583                         /lib64/libreadline.so.6.2
314043c000-314063b000 ---p 0003c000 08:01 786583                         /lib64/libreadline.so.6.2
314063b000-3140643000 rw-p 0003b000 08:01 786583                         /lib64/libreadline.so.6.2
3140643000-3140644000 rw-p 00000000 00:00 0 
3145000000-314500f000 r-xp 00000000 08:01 788834                         /lib64/libbz2.so.1.0.6
314500f000-314520e000 ---p 0000f000 08:01 788834                         /lib64/libbz2.so.1.0.6
314520e000-3145210000 rw-p 0000e000 08:01 788834                         /lib64/libbz2.so.1.0.6
3148c00000-3148c23000 r-xp 00000000 08:01 815621                         /lib64/libtinfo.so.5.9
3148c23000-3148e22000 ---p 00023000 08:01 815621                         /lib64/libtinfo.so.5.9
3148e22000-3148e26000 r--p 00022000 08:01 815621                         /lib64/libtinfo.so.5.9
3148e26000-3148e27000 rw-p 00026000 08:01 815621                         /lib64/libtinfo.so.5.9
3149200000-3149338000 r-xp 00000000 08:01 177515                         /usr/lib64/libicuuc.so.46.0
3149338000-3149538000 ---p 00138000 08:01 177515                         /usr/lib64/libicuuc.so.46.0
3149538000-3149547000 r--p 00138000 08:01 177515                         /usr/lib64/libicuuc.so.46.0
3149547000-3149548000 rw-p 00147000 08:01 177515                         /usr/lib64/libicuuc.so.46.0
3149548000-314954c000 rw-p 00000000 00:00 0 
314b600000-314b7b1000 r-xp 00000000 08:01 148922                         /usr/lib64/libicui18n.so.46.0
314b7b1000-314b9b1000 ---p 001b1000 08:01 148922                         /usr/lib64/libicui18n.so.46.0
314b9b1000-314b9bc000 r--p 001b1000 08:01 148922                         /usr/lib64/libicui18n.so.46.0
314b9bc000-314b9be000 rw-p 001bc000 08:01 148922                         /usr/lib64/libicui18n.so.46.0
314da00000-314e873000 r-xp 00000000 08:01 137354                         /usr/lib64/libicudata.so.46.0
314e873000-314ea72000 ---p 00e73000 08:01 137354                         /usr/lib64/libicudata.so.46.0
314ea72000-314ea73000 r--p 00e72000 08:01 137354                         /usr/lib64/libicudata.so.46.0
314ea73000-314ea74000 rw-p 00e73000 08:01 137354                         /usr/lib64/libicudata.so.46.0
3158200000-315820d000 r-xp 00000000 08:01 165367                         /usr/lib64/libgomp.so.1.0.0
315820d000-315840c000 ---p 0000d000 08:01 165367                         /usr/lib64/libgomp.so.1.0.0
315840c000-315840d000 rw-p 0000c000 08:01 165367                         /usr/lib64/libgomp.so.1.0.0
315d600000-315d63c000 r-xp 00000000 08:01 788840                         /lib64/libpcre.so.0.0.1
315d63c000-315d83b000 ---p 0003c000 08:01 788840                         /lib64/libpcre.so.0.0.1
315d83b000-315d83c000 r--p 0003b000 08:01 788840                         /lib64/libpcre.so.0.0.1
315d83c000-315d83d000 rw-p 0003c000 08:01 788840                         /lib64/libpcre.so.0.0.1
376b400000-376b42b000 r-xp 00000000 08:01 1062362                        /usr/lib64/R/lib/libRblas.so
376b42b000-376b62a000 ---p 0002b000 08:01 1062362                        /usr/lib64/R/lib/libRblas.so
376b62a000-376b62b000 r--p 0002a000 08:01 1062362                        /usr/lib64/R/lib/libRblas.so
376b62b000-376b62c000 rw-p 0002b000 08:01 1062362                        /usr/lib64/R/lib/libRblas.so
376b800000-376baa7000 r-xp 00000000 08:01 1062365                        /usr/lib64/R/lib/libR.so
376baa7000-376bca7000 ---p 002a7000 08:01 1062365                        /usr/lib64/R/lib/libR.so
376bca7000-376bcad000 r--p 002a7000 08:01 1062365                        /usr/lib64/R/lib/libR.so
376bcad000-376bcbd000 rw-p 002ad000 08:01 1062365                        /usr/lib64/R/lib/libR.so
376bcbd000-376bdac000 rw-p 00000000 00:00 0 
376be00000-376bf78000 r-xp 00000000 08:01 1062364                        /usr/lib64/R/lib/libRlapack.so
376bf78000-376c178000 ---p 00178000 08:01 1062364                        /usr/lib64/R/lib/libRlapack.so
376c178000-376c179000 r--p 00178000 08:01 1062364                        /usr/lib64/R/lib/libRlapack.so
376c179000-376c17a000 rw-p 00179000 08:01 1062364                        /usr/lib64/R/lib/libRlapack.so
376c200000-376c235000 r-xp 00000000 08:01 136624                         /usr/lib64/libquadmath.so.0.0.0
376c235000-376c434000 ---p 00035000 08:01 136624                         /usr/lib64/libquadmath.so.0.0.0
376c434000-376c435000 rw-p 00034000 08:01 136624                         /usr/lib64/libquadmath.so.0.0.0
376c600000-376c714000 r-xp 00000000 08:01 138203                         /usr/lib64/libgfortran.so.3.0.0
376c714000-376c913000 ---p 00114000 08:01 138203                         /usr/lib64/libgfortran.so.3.0.0
376c913000-376c915000 rw-p 00113000 08:01 138203                         /usr/lib64/libgfortran.so.3.0.0
376c915000-376c916000 rw-p 00000000 00:00 0 
7fd5ef184000-7fd5ef185000 r-xp 00000000 08:03 7609099                    /home/phoxis/Documents/Works/Programming/R/metiswrap.so
7fd5ef185000-7fd5ef385000 ---p 00001000 08:03 7609099                    /home/phoxis/Documents/Works/Programming/R/metiswrap.so
7fd5ef385000-7fd5ef386000 r--p 00001000 08:03 7609099                    /home/phoxis/Documents/Works/Programming/R/metiswrap.so
7fd5ef386000-7fd5ef387000 rw-p 00002000 08:03 7609099                    /home/phoxis/Documents/Works/Programming/R/metiswrap.so
7fd5ef387000-7fd5ef3ea000 r-xp 00000000 08:03 7610359                    /home/phoxis/Documents/Works/Programming/R/libmetis.so
7fd5ef3ea000-7fd5ef5e9000 ---p 00063000 08:03 7610359                    /home/phoxis/Documents/Works/Programming/R/libmetis.so
7fd5ef5e9000-7fd5ef5eb000 rw-p 00062000 08:03 7610359                    /home/phoxis/Documents/Works/Programming/R/libmetis.so
7fd5ef5eb000-7fd5ef5f9000 r-xp 00000000 08:03 7740125                    /home/phoxis/R/x86_64-redhat-linux-gnu-library/2.15/RANN/libs/RANN.so
7fd5ef5f9000-7fd5ef7f9000 ---p 0000e000 08:03 7740125                    /home/phoxis/R/x86_64-redhat-linux-gnu-library/2.15/RANN/libs/RANN.so
7fd5ef7f9000-7fd5ef7fa000 r--p 0000e000 08:03 7740125                    /home/phoxis/R/x86_64-redhat-linux-gnu-library/2.15/RANN/libs/RANN.so
7fd5ef7fa000-7fd5ef7fb000 rw-p 0000f000 08:03 7740125                    /home/phoxis/R/x86_64-redhat-linux-gnu-library/2.15/RANN/libs/RANN.so
7fd5ef7fb000-7fd5ef869000 r-xp 00000000 08:01 1203642                    /usr/lib64/R/library/stats/libs/stats.so
7fd5ef869000-7fd5efa68000 ---p 0006e000 08:01 1203642                    /usr/lib64/R/library/stats/libs/stats.so
7fd5efa68000-7fd5efa6a000 r--p 0006d000 08:01 1203642                    /usr/lib64/R/library/stats/libs/stats.so
7fd5efa6a000-7fd5efa6c000 rw-p 0006f000 08:01 1203642                    /usr/lib64/R/library/stats/libs/stats.so
7fd5efa6c000-7fd5efbda000 rw-p 00000000 00:00 0 
7fd5efbda000-7fd5efbfd000 r-xp 00000000 08:01 1077695                    /usr/lib64/R/library/grDevices/libs/grDevices.so
7fd5efbfd000-7fd5efdfc000 ---p 00023000 08:01 1077695                    /usr/lib64/R/library/grDevices/libs/grDevices.so
7fd5efdfc000-7fd5efdfd000 r--p 00022000 08:01 1077695                    /usr/lib64/R/library/grDevices/libs/grDevices.so
7fd5efdfd000-7fd5efdfe000 rw-p 00023000 08:01 1077695                    /usr/lib64/R/library/grDevices/libs/grDevices.so
7fd5eff2e000-7fd5f0165000 rw-p 00000000 00:00 0 
7fd5f0165000-7fd5f016c000 r-xp 00000000 08:01 1078260                    /usr/lib64/R/library/methods/libs/methods.so
7fd5f016c000-7fd5f036b000 ---p 00007000 08:01 1078260                    /usr/lib64/R/library/methods/libs/methods.so
7fd5f036b000-7fd5f036c000 r--p 00006000 08:01 1078260                    /usr/lib64/R/library/methods/libs/methods.so
7fd5f036c000-7fd5f036d000 rw-p 00007000 08:01 1078260                    /usr/lib64/R/library/methods/libs/methods.so
7fd5f036d000-7fd5f0402000 rw-p 00000000 00:00 0 
7fd5f0402000-7fd5f040e000 r-xp 00000000 08:01 789196                     /lib64/libnss_files-2.14.90.so
7fd5f040e000-7fd5f060d000 ---p 0000c000 08:01 789196                     /lib64/libnss_files-2.14.90.so
7fd5f060d000-7fd5f060e000 r--p 0000b000 08:01 789196                     /lib64/libnss_files-2.14.90.so
7fd5f060e000-7fd5f060f000 rw-p 0000c000 08:01 789196                     /lib64/libnss_files-2.14.90.so
7fd5f0640000-7fd5f06f1000 rw-p 00000000 00:00 0 
7fd5f06f3000-7fd5f089c000 rw-p 00000000 00:00 0 
7fd5f089c000-7fd5f6cbf000 r--p 00000000 08:01 157303                     /usr/lib/locale/locale-archive
7fd5f6cbf000-7fd5f6cc9000 rw-p 00000000 00:00 0 
7fd5f6ccc000-7fd5f6cf3000 rw-p 00000000 00:00 0 
7fd5f6cf3000-7fd5f6cfa000 r--s 00000000 08:01 139093                     /usr/lib64/gconv/gconv-modules.cache
7fd5f6cfa000-7fd5f6cfc000 rw-p 00000000 00:00 0 
7fff473da000-7fff47403000 rw-p 00000000 00:00 0                          [stack]
7fff474a2000-7fff474a3000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Valgrind Dump

partitioning : Initial Cut: 145

METIS_OK
partitioning : Initial Cut: 202

METIS_OK
partitioning : ==1410== Invalid read of size 4
==1410==    at 0xEFAA3E3: libmetis__CreateCoarseGraphNoMask (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xEFAB5E8: libmetis__Match_SHEM (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xEFACB84: libmetis__CoarsenGraph (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xEFA39FD: libmetis__MultilevelBisect (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xEFA43D0: libmetis__MlevelRecursiveBisection (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xEFA4795: METIS_PartGraphRecursive (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xF1BDD85: metis_wrap (metiswrap.c:45)
==1410==    by 0x376B8B148C: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B8E1B08: Rf_eval (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B8E478F: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B8E192A: Rf_eval (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B8E490F: ??? (in /usr/lib64/R/lib/libR.so)
==1410==  Address 0x397c7a00 is not stack'd, malloc'd or (recently) free'd
==1410== 

 *** caught segfault ***
address 0x397c7a00, cause 'memory not mapped'
==1410== 
==1410== Process terminating with default action of signal 11 (SIGSEGV)
==1410==  General Protection Fault
==1410==    at 0x313A505FD0: __snprintf_chk (in /lib64/libc-2.14.90.so)
==1410==    by 0x376B979097: Rf_EncodeReal (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B97A317: Rf_EncodeElement (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B89A50D: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B89C19C: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B89A21D: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B89C59D: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B8CC524: R_GetTraceback (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x376B915A30: ??? (in /usr/lib64/R/lib/libR.so)
==1410==    by 0x313AC0F4FF: ??? (in /lib64/libpthread-2.14.90.so)
==1410==    by 0xEFAA3E2: libmetis__CreateCoarseGraphNoMask (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410==    by 0xEFAB5E8: libmetis__Match_SHEM (in /home/phoxis/Documents/Works/Programming/R/libmetis.so)
==1410== 
==1410== HEAP SUMMARY:
==1410==     in use at exit: 28,683,682 bytes in 14,598 blocks
==1410==   total heap usage: 34,400 allocs, 19,802 frees, 50,987,649 bytes allocated
==1410== 
==1410== LEAK SUMMARY:
==1410==    definitely lost: 0 bytes in 0 blocks
==1410==    indirectly lost: 0 bytes in 0 blocks
==1410==      possibly lost: 0 bytes in 0 blocks
==1410==    still reachable: 28,683,682 bytes in 14,598 blocks
==1410==         suppressed: 0 bytes in 0 blocks
==1410== Rerun with --leak-check=full to see details of leaked memory
==1410== 
==1410== For counts of detected and suppressed errors, rerun with: -v
==1410== ERROR SUMMARY: 220 errors from 14 contexts (suppressed: 2 from 2)
Segmentation fault (core dumped)
phoxis
  • 60,131
  • 14
  • 81
  • 117
  • 1
    I have not read your problem properly, but you might want to use the more modern `.Call()` instead of `.C()` and see if the problem persists. It is heavily recommended these days (e.g., on R-devel), see the following links: [one](http://www.mail-archive.com/r-devel@r-project.org/msg26578.html), [two](http://www.mail-archive.com/r-devel@r-project.org/msg26631.html) – Henrik Jun 19 '12 at 12:47
  • That will be my next step if this does not work. Actually i will require to spend some time with the `.Call()` before i can use it. I would prefer staying with the current interface, if the error is not because of my code, or the way i am using it. – phoxis Jun 19 '12 at 12:50
  • And once you moved to `.Call()`, you can also consider [Rcpp](http://dirk.eddelbuettel.com/code/rcpp.html) which can help catch a few errors. – Dirk Eddelbuettel Jun 19 '12 at 13:43
  • Create a reproducible example that runs quickly, then use `R -d valgrind -f example.R` to get more information on the location of the error. Valgrind can slow execution speed 20x. – Martin Morgan Jun 19 '12 at 15:03
  • @MartinMorgan Code does not crash everytime with run with valgrind, but crashes almost every alternate time. But, then the code does not crash, it has incorrect output. I have added the crash dump by valgrind in the question. – phoxis Jun 19 '12 at 15:35
  • If you leave out all the actual metis code, and just dump the parameters you get from R, does it work then? Was metis compiled with 64 bit or 32 bit? Can you try building a single-threaded metis? it seems to use pthreads for multithreading. – Has QUIT--Anony-Mousse Jun 19 '12 at 18:12
  • I am in 64 bit, and metis was compiler with 64 bit, R is also 64 bit. If i comment the `.C` call it works fine. Also i have wrote a demo C code and tested if there was any problem in passing parameters from R to C, they were fine, also i called metis from C only program, which also worked fine for the same data set. I will try compiling it without threads, and be back. – phoxis Jun 19 '12 at 18:17
  • @Anony-Mousse: i don't think metis is multi threaded, it has no single/multi thread compilation options, also the code does not contain any posix thread calls. – phoxis Jun 19 '12 at 18:24
  • The reason that I'm asking is that a) valgrind shows e.g. 0xF1BDD85: metis_wrap (metiswrap.c:45) which looks like a 32 bit map of the 64 bit adresses. Plus, in the other trace, it goes from metis into pthread. But this could be an attempt of R to catch an error from metis maybe. Does `ldd` indicate that any of the metis/metiswrap files link against libpthread? – Has QUIT--Anony-Mousse Jun 19 '12 at 19:21
  • metiswrap is my implementation, `ldd` shows it is linked with libpthread.so . Compiled with `R CMD SHLIB metiswrap.c` – phoxis Jun 19 '12 at 19:24
  • Maybe not too helpful; perhaps your libmetis was compiled with #define INDEXTYPEWIDTH 64, whereas R is passing 32-bit ints (and the .C entry should have a signature `int *` rather than idx_t, with your C code paying more attention to data size?). It would help if you posted a reproducible (in the sense that you provide a minimal input object knn_data) example. – Martin Morgan Jun 19 '12 at 19:55
  • `INDEXTYPEWIDTH` is 32 and `idx_t` is typedef er to be 32 bit wide integer. Therefore i don't think there will be any problem passing the pointers through the .C interface. I am testing with a very minimal set of points, 13 points only. I am posting that example in the question. – phoxis Jun 20 '12 at 05:41
  • One problem noted, the `ncon` value i passed through the interface was incorrect which should have been 1 was a huge number. Passing `ncon` as local with `ncon = 1` didn't solve the problem, still again segmentation fault, and with the same error messages. All the error messages are related to overallocation of memory. – phoxis Jun 20 '12 at 06:25
  • You're passing one (or more) parameters of incorrect object pointers to the function. I hazard a guess that R allocates objects on the heap, so this would be causing a heap overflow... Hence the reason the error appears spurious and mentions `free`. The least of your problems could be an incompatible ABI, remember that... – autistic Dec 09 '15 at 14:42
  • @phoxis Did you get this to work with .C()? – warship Aug 06 '16 at 19:29
  • So I'm assuming you went down the .Call() or rcpp route? The issue I have with both the .C() and .Call() techniques is that it crashes my R session when I do, e.g., `.C("myFunction", arg1, arg2)`. It's quite strange, and I've been considering opening up a new question for it. – warship Aug 08 '16 at 01:29

0 Answers0