I want to produce an irregular graph. i find a code that produce irregular graph but because i use windows 7 it doesn't support functions drand48() and srand48(), so i use srand() and ((float) rand()) / (float) RAND_MAX) instead of them.
when i run my program for small nodes and edges it works but when i run it for large nodes and edges( for example 90000 nodes and 900000 edges it doesn't work.
"my error is CRT detected that the application wrote after end of heap buffer"
i don't know if it is because my memory card size or my code is wrong or i shouldn't use srand()and srand48() instead of those functions.
could any one help me?
my RAM is 4GB and i use windows 7 32 bit
gpgraph * create_RMAT_graph(int N, int M,int rseed, double a, double b, double c, bool permute)
{
double d;
d=1-(a+b+c);
double drand48(void);
gpgraph* g1=new gpgraph();
g1->allocate_node(N,M);
int *src=new int[M];
int *dest=new int[M];
int *degree=new int[N];
for(int i=0;i<n;i++)>
degree[i]=0;
int SCALE=(int) log2((double)N);
srand(rseed);
for(int i=0;i<m;i++)>
{
int u=1;
int v=1;
int step=N/2;
double av=a;
double bv=b;
double cv=c;
double dv=d;
double p=(((float) rand()) / (float) RAND_MAX);
if(p<av){}>
else if(p<(av+bv))
v+=step;
else if(p<(av+bv+cv))
u+=step;
else
{
v+=step;
u+=step;
}
for(int j=1;j<scale;j++)>
{
step=step/2;
double var=0.1;
av*=0.95+var*(((float) rand()) / (float) RAND_MAX);
bv*=0.95+var*(((float) rand()) / (float) RAND_MAX);
cv*=0.95+var*(((float) rand()) / (float) RAND_MAX);
dv*=0.95+var*(((float) rand()) / (float) RAND_MAX);
double S=av+bv+cv+dv;
av=av/S;
bv=bv/S;
cv=cv/S;
dv=dv/S;
p=(((float) rand()) / (float) RAND_MAX);
if(p<av){}>
else if(p<(av+bv))
v+=step;
else if(p<(av+bv+cv))
u+=step;
else{
v+=step;
u+=step;
}
}
src[i]=u-1;
dest[i]=v-1;
if(src[i]==dest[i])
{
i=i-1;
continue;
}
}
if(permute)
{
int* p=new int[N];
for(int i=0;i<n;i++)>
p[i]=i;
for(int i=0;i<n;i++)>
{
int j=(int)(N * (((float) rand()) / (float) RAND_MAX));
int temp=p[j];
p[j]=p[i];
p[i]=temp;
}
for(int i=0;i<m;i++)>
{
src[i]=p[src[i]];
dest[i]=p[dest[i]];
}
delete []p;
}
for(int i=0;i<m;i++)>
degree[src[i]]++;
g1->h_nodes[0]=0;
for(int i=1;i<n;i++)>
g1->h_nodes[i]=g1->h_nodes[i-1]+degree[i-1];
for(int i=0;i<m;i++)>
{
int u=src[i];
int v=dest[i];
int pos=degree[u]--;
g1->h_edges[g1->h_nodes[u]+pos-1]=v;
}
delete [] src;
delete []dest;
delete []degree;
return g1;
}
int main( int argc, char** argv)
{
g=create_RMAT_graph(90000,9000000,1993,0.45,0.25,0.15,true);
}