igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] segmentation fault(core dumped)


From: Tamás Nepusz
Subject: Re: [igraph] segmentation fault(core dumped)
Date: Sat, 2 Mar 2013 22:50:44 +0100

Hi,

Please stay on the list with your follow-up emails.

Your code works fine for me (apart from the fact that you did not post your 
full code so I had to guess the missing parts myself). Some suggestions:

1. igraph_real_t is simply a double, so you can use fscanf directly on your 
input file with %lg instead of %d

2. Hardcoding the number of rows in your file is a bad idea. I strongly suspect 
that your problem stems from the fact that the value of ROW in your code and 
the number of rows in your file does not match.

3. You can use igraph_vector_push_back to grow a vector dynamically, so when 
you are reading your input file, you could do this:

igraph_vector_init(&edges);
while (1) {
    double u, v;
    int num_read;
    num_read = fscanf(data, "%lg %lg", &u, &v);
    if (num_read != 2) {
        /* most likely end of file */
        break;
    }
    igraph_vector_push_back(&edges, u);
    igraph_vector_push_back(&edges, v);
}

4. Best of all, you can simply use igraph_read_graph_edgelist to process your 
input file; all that you need then is to create the types vector manually. 
Don't worry that igraph_create_bipartite asks for the types vector, it only 
uses the types vector to *check* that your graph is really bipartite. 
Otherwise, bipartite graphs in igraph are "just" regular graphs, there is no 
distinction, and any function that requires a bipartite graph will _ask_ for 
the types vector anyway (that's why you need to construct it).

Cheers,
Tamas

On 2 Mar 2013, at 09:50, address@hidden wrote:

> Hi,
> 
> Now, I still face the problem "Segmentation fault (core dumped)
> " when I use igraph_create_bipartite(). I imported my data to create my 
> bipartite graph. Following is my code:
> 
> int _edges2[2*ROW];
> int main()
> {
>    int i,j,k;
>    igraph_t gb;
>    igraph_real_t edges2[2*ROW];
> 
>    FILE *data;
>    data = fopen("bipartite_2007.txt","r");
>    for(i=0;i<ROW;i++)
>    fscanf(data,"%d %d",&_edges2[2*i],&_edges2[2*i+1]);
> 
>    for(i=0;i<2*ROW;i++)
>    edges2[i] = _edges2[i];
>    fclose(data);
> 
>    for(i=0;i<ROW;i++)
>    printf("%d %d\n",(int)edges2[2*i],(int)edges2[2*i+1]);
> 
>    igraph_vector_bool_t types;
>    igraph_vector_t edges;
> 
>    int ret;
> 
>    igraph_vector_view(&edges, edges2, sizeof(edges2)/sizeof(igraph_real_t));
>    igraph_vector_bool_init(&types, igraph_vector_max(&edges)+1);
>    for (i=0; i<igraph_vector_bool_size(&types); i++) {
>        if(i<716812)
>            VECTOR(types)[i] = 0;
>        else
>            VECTOR(types)[i] = 1;
>    }
>    igraph_create_bipartite(&gb, &types, &edges, /*directed=*/ 0);
>    //igraph_write_graph_edgelist(&gb, stdout);
> 
>    igraph_vector_bool_destroy(&types);
>    ifile=fopen("gb.gml", "w");
>    igraph_write_graph_gml(&gb,ifile,0,"BIPARTITE");
>    fclose(ifile);
> 
> 
>   igraph_destroy(&gb);
>   return 0;
> }
> Explain: Because I don't know how to save as  igraph_real_t from int(%d) in 
> my data. So I imported as int and paste  it to igraph_real_t array one by 
> one. And my data is like...It's an edge between 2 id in the same row
> 716877 1458
> 716877 1459
> 716877 1460
> 716877 1461
> 716877 1479
> 716877 1480
> 716877 1481
> 716877 1482
> 716877 1483
> 716877 1489
> 716877 1490......
> 
> I have 300,000 rows(as same as edges) approximately, and the max id is 
> 721,816. I thought it causes from too many edges, or perhaps I can operate 
> igraph_real_t in another way. Could you tell me how to do for my situation. 
> It's really an emergency for me. I really need to solve this problem ASAP.
> 
> Thank you for your help
> 
> Sincerely,
> James Fu
> 在 2013/3/1 的來信中,"Tamás_Nepusz" <address@hidden> 提及:
> 
>> Hi,
>> 
>>> I'm confusing on the memory allocation. When I made a super-big matrix, 
>>> it'll show segmentation fault(core dumped). But I need a very big 
>>> matrix(graph) for my study. How to do that?
>> Judging from your code, you want to allocate a matrix of size 1000000 x 
>> 5000. This would require 1000000 x 5000 x 8 bytes, i.e. 37 GB. I strongly 
>> suspect that you don't have 37 GB of free memory available.
>> 
>>> I need a matrix 1000000*5000 for my study, is there any way to do that
>> Judging from your code, you don't actually need the matrix -- you want to 
>> construct a random bipartite graph instead. Your code would generate a 
>> bipartite graph where each edge is present with probability 0.5, but you 
>> would approximately need 18 GB for that and your graph would have 2.5 
>> billion edges -- is this really what you want? Maybe you should lower the 
>> edge probability a bit.
>> 
>> Also, there are other methods in igraph that can be used to generate 
>> bipartite graphs; igraph_incidence is just one option and it is not suitable 
>> for large bipartite graphs because of the size of the incidence matrix. Take 
>> a look at igraph_create_bipartite() instead, which takes the list of edges 
>> only, not a matrix. From igraph 0.6.5 (which will be released in a few 
>> days), we will also have an igraph_bipartite_game function, which simply 
>> generates a random bipartite graph like the one you want to construct.
>> 
>> Cheers,
>> Tamas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]