[Top][All Lists]

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

[igraph] segmentation fault

From: Yi Cao
Subject: [igraph] segmentation fault
Date: Thu, 24 Mar 2011 13:47:47 -0400

Hello everyone,

The following is my program for calculating the distribution of components size of a given graph. It works for small edge list file. However, when I tried the bigger files (which are .txt files and about 20M), it failed. The input edge list file is a file in which there are two columns numbers, each row contains two numbers representing the two nodes of an edge. (probably because the input file is too big, it returned error info when I tired to attach it and send it.).

I compiled and ran my program under suse linux:

The program is:

 // compile:
// gcc componenthistogram.c -I ~/include/igraph -ligraph -L ~/lib -o componenthistogram
// ./componenthistogram inputfile

#include <igraph.h>
#include <stdlib.h>

void free_complist(igraph_vector_
ptr_t *complist)
  long int i;
  for (i=0; i<igraph_vector_ptr_size(complist); i++) {

int main(int argc, char *argv[ ])
  igraph_t  g;
  igraph_vector_ptr_t complist;
  long int b[1000000]={0};
  long int i,j;

if (argc!=2)
 {printf("You must suppy edge file name!\n"); exit(0);}
  //first,read an edgelist in order to reate a graph.
   FILE *input;
      input=fopen(argv[1], "r");
       if (!input) {
      igraph_read_graph_edgelist(&g, input,  0, IGRAPH_UNDIRECTED);

   printf("Vertices count: %d\n", (int)igraph_vcount(&g));
   printf("Edge count : %d\n", (int)igraph_ecount(&g));
   igraph_vector_ptr_init(&complist, 0);
   igraph_decompose(&g, &complist, IGRAPH_WEAK, -1,1);

   printf("Components and their sizes:\n");
   for (i=0; i<igraph_vector_ptr_size(&complist); i++)
     printf("%d   ", i);
     printf("%d\n", (int)igraph_vcount(VECTOR(complist)[i]));

//now, let us compute maximum compoonent size (to be placed in variable max);
long int max=0;
long int size;

for (i=0; i<igraph_vector_ptr_size(&complist); i++)
   if (size>max) max=size;

//compute histogram
for (i=0; i<igraph_vector_ptr_size(&complist); i++)

//print the histogram
 printf("Histogram (first column=size, second column=nr of components with this size)\n");
  for(j=0; j<=max;j++)
    printf("%d   %d\r\n",j,b[j] );

//   igraph_destroy(&g);
return 0;

 I was thinking, was the segmentation fault a problem of my program or a problem of the computer's computation capacity, or a problem of the functions (such as igraph_decompse ) in igraph package I used?  Anyone have some ideas or solutions about this?  I appreciate your help. Thanks a lot.

reply via email to

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