[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] segmentation fault(core dumped)
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] segmentation fault(core dumped) |
Date: |
Fri, 1 Apr 2011 14:12:42 -0400 |
Hi,
the first idea is that you shouldn't allocate such big data structures
on the stack. This already causes a segfault on my system. Allocate
them in the heap. e.g.
myArray1 = new log[numberoflines];
Gabor
On Fri, Apr 1, 2011 at 1:31 PM, Yi Cao <address@hidden> wrote:
> Hello everyone,
>
> I wrote a small program by C++ to calculate the component size
> distribution of one vertex set in a bipartite graph. It seems everything is
> ok, and the compile is ok, but it returns segmentation fault and core dumped
> when runing it. There must be some mistakes in the code, maybe very generral
> ones, but I really can not figure them out. Can someone help me go through
> it and give me some ideas? Thanks in advance.
>
> The code is :
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> #include <igraph.h>
> #include<stdio.h>
> #include<iostream>
> #include<fstream>
> #define numberoflines 1077806
>
> using namespace std;
>
> int main(int argc, char *argv[ ])
> {
> igraph_t g;
> igraph_vector_t membership;
> igraph_vector_t csize;
> igraph_integer_t no;
>
> long int i,j=0,id=0;
> long int b[100000]={0};
> long int c[100000]={0};
>
> long myArray1[numberoflines]={0};
> long myArray2[numberoflines]={0};
> long myArray3[30000]={0};
>
> //first,read an edgelist in order to create a graph.
> if (argc!=2)
> {cout<<"You must suppy edge file name!"<<endl; }
>
> FILE * input;
> input=fopen(argv[1],"r");
> if (!input)
> { cout<<"error"<<endl;}
> igraph_read_graph_edgelist(&g, input, 0, IGRAPH_UNDIRECTED);
> fclose (input);
>
> cout<<"Vertices count: "<<(int)igraph_vcount(&g)<<endl;
> cout<<"Edge count: "<<(int)igraph_ecount(&g)<<endl;
>
> //decompose the graph and store component id of each vertex in vector
> membership, store component size of each
> //component in vector csize, store number of components in igraph_integer
> no.
> igraph_vector_init(&membership,1106000);
> igraph_vector_init(&csize, 100000);
> igraph_clusters(&g, &membership, &csize, &no,IGRAPH_WEAK);
>
> //in the following, we pick out the first column of vertices, and record
> each headword in myArray3[].
> ifstream fin;
> fin.open(argv[1]);
> if(fin.is_open())
> {
> for (int i=0; i<numberoflines; i++)
> {
> fin >> myArray1[i]; //read the first number in each line and
> store in myArray1
> fin >> myArray2[i]; //read the second number in each line and
> store in myArray2
> if(fin.eof()) break;
> }
> }
> fin.close();
>
> // record the headwords in myArray1 to myArray3, to make sure that each
> headword in myArray3 is different.
> myArray3[0]=myArray1[0];
> for(i=1;i<numberoflines;i++)
> {
> if (myArray1[i]!=myArray1[i-1])
> { j++;
> myArray3[j]=myArray1[i];
> }
> }
> cout<<"j="<<j<<endl;
> //in the following part, we find out headwords which are in the same
> component and compute the histogram.
> for(i=0;i<j+1;i++)
> { id=VECTOR(membership)[myArray3[i]];
> // b=(long int*)calloc(no,sizeof(int)); //no is the total number of
> components and calloc allocate memory to b.
> b[id]=b[id]+1;
> c[b[id]]=c[b[id]]+1;
> }
> //print the histogram
> cout<<"headword group size******number of this size\n"<<endl;
> for(i=0;i<no;i++)
> {cout<<b[i]<<" "<<c[b[i]]<<"\r\n"<<endl;}
>
> igraph_vector_destroy(&membership);
> igraph_vector_destroy(&csize);
>
> return 0;
>
> }
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
--
Gabor Csardi <address@hidden> MTA KFKI RMKI