Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

Barabasi Albert Network Generator and Percolator compiles with g++ but doesnt on icpc with strange error

$
0
0

Here is a code that creates Barabasi Albert model for any number of nodes for any number of degrees, the code fully compiles with g++ but shows error while compiling with icpc(intel c++ compiler). I am attaching the code with the error report with this post.

    #include<bits/stdc++.h>
    using namespace std;

    int EMPTY = 0;
    int connectionNumber = 0;
    vector<unsigned> network[3000001];

    //seed for the network to grow
    void seed(int netmap1[],int netmap2[],int N)
    {
    	connectionNumber = 0;

    	for(unsigned i=1;i<=N;i++)
    	{
    		for(unsigned j=1;j<=N;j++)
    		{
    			if(i!=j)
    			{
    				network[i].push_back(j);
    			}
    			if(j>i)
    			{

    				connectionNumber++;
    				netmap1[connectionNumber]=i;
    				netmap2[connectionNumber]=j;
    			}
    		}
    	}
    }

    //actual node building on the algorithm of barabasi albert model
    //stores the connection of each node in netmap1 and netmap2
    void BA(int netmap1[],int netmap2[],int N,int seedNumber, int m)
    {
    	srand(time(NULL));
    	int concheck=0;
    	int a[m] = {};
    	int countm=0;
    	double totalpk,pk;
    	for(int i = seedNumber+1;i<=N;i++)
    	{
    		countm=0;
    		cout<<"connection given to : "<<i<<endl;
    		totalpk = 0.0;
    		for(int n=0;n<m;n++)
    			{
    				a[n]=0;
    			}
    		for(int l=1;l<i;l++)
    		{
    			totalpk += network[l].size();
    		}

    		for(int j = 1; ; j++)
    		{

    			concheck = 0;
    			double u = (double)rand()/RAND_MAX;
    			pk = 0.0;

    			for(int k=1;k<i;k++)
    			{
    				if(concheck==1) break;
    				pk += (double)(network[k].size())/totalpk;


    				if(u<pk)
    				{
    					concheck = 0;
    					for(int n=0;n<m;n++)
    					{

    						if(a[n]==k)
    						{

    							concheck = 1;
    						}
    					}
    					if(concheck==0)
    					{
    						a[countm]=k;
    						countm++;

    						network[k].push_back(i);
    						network[i].push_back(k);
    						connectionNumber++;

    						netmap1[connectionNumber]=k;
    						netmap2[connectionNumber]=i;
    						totalpk += 2;

    						break;
    					}
    					else continue;
    				}
    			}
    			if(countm==m)
    			{
    				break;
    			}
    		}

    	}
    }

    int findroot(int ptr[],int i)
    {
    	if(ptr[i]<0) return i;

    	return ptr[i]=findroot(ptr,ptr[i]);
    }

    //does explosive percolation with newman-ziff algorithm
    void explosivepercolation(int netmap1[],int netmap2[],int vertices, int run, int filenum, int m)
    {
    	srand(time(NULL));
    	int A,B,C;
    	A = vertices;
    	B = run;
    	C = filenum;

    	string filename1;
    	filename1 = "maxclus_";
    	string filename2;
    	filename2 = "delmx_";
    	string filename3;
    	filename3 = "entropy_";

    	filename1 = filename1+to_string(A)+"node_"+to_string(m)+"M_"+to_string(B)+"ens_"+to_string(C)+".dat";
    	filename2 = filename2+to_string(vertices)+"node_"+to_string(m)+"M_"+to_string(run)+"ens"+to_string(filenum)+".dat";
    	filename3 = filename3+to_string(vertices)+"node_"+to_string(m)+"M_"+to_string(run)+"ens"+to_string(filenum)+".dat";

    	ofstream fout1,fout2,fout3;

    	int* random = NULL;
    	random = new int[connectionNumber+1];

    	double* maxclus = NULL;
    	maxclus = new double[connectionNumber+1];

    	double* delmx = NULL;
    	delmx = new double[connectionNumber+1];

    	double* entropycalc = NULL;
    	entropycalc = new double[connectionNumber+1];

    	for(int i=0;i<=connectionNumber;i++)
    	{
    		maxclus[i]=0;
    		delmx[i]=0;
    		entropycalc[i]=0;
    	}

    	for(int i=0;i<=connectionNumber;i++)
    	{
    		random[i] = i;
    	}
    	int* ptr = new int[vertices+1];
    	for(int i=0;i<vertices+1;i++) ptr[i]=0;

    	//here it starts percolating for number of runs to take ensemble average

    	for(int rx=1;rx<=run;rx++)
    	{
    		cout<<"run commencing : "<<rx<<endl;
    		for(int i=0;i<vertices+1;i++) ptr[i]=0;
    		int index=0,big=0,bigtemp=0,jump=0,en1=0,en2=0;
    		int node1=0,node2=0,node3=0,node4=0,nodeA=0,nodeB=0;
    		int clus1=0,clus2=0,clus3=0,clus4=0;
    		long double entropy = log(vertices);
    		random_shuffle(&random[1],&random[connectionNumber]);

    		for(int i=0;i<=vertices;i++) ptr[i] = EMPTY;

    		for(int i=1;i<=connectionNumber;i++)
    		{

    			if(i!=connectionNumber)
    			{

    				node1 = netmap1[random[i]];
    				node2 = netmap2[random[i]];
    				node3 = netmap1[random[i+1]];
    				node4 = netmap2[random[i+1]];

    				if(ptr[node1]==EMPTY) clus1 = 1;
    				else
    				{
    					int x = findroot(ptr,node1);
    					clus1 = -ptr[x];
    				}

    				if(ptr[node2]==EMPTY) clus2 = 1;
    				else
    				{
    					int b = findroot(ptr,node2);
    					clus2 = -ptr[b];
    				}

    				if(ptr[node3]==EMPTY) clus3 = 1;
    				else
    				{
    					int c = findroot(ptr,node3);
    					clus3 = -ptr[c];
    				}

    				if(ptr[node4]==EMPTY) clus4 = 1;
    				else
    				{
    					int d = findroot(ptr,node4);
    					clus4 = -ptr[d];
    				}

    				if(clus1*clus2<clus3*clus4)
    				{
    					nodeA = node1;
    					nodeB = node2;


    					int N1=connectionNumber;
    					int M1=i+1;
    					int u = M1 + rand()/(RAND_MAX/(N1-M1+1) + 1);

    					int temp = random[u];
    					random[u] = random[i+1];
    					random[i+1] = temp;
    				}
    				else
    				{
    					nodeA = node3;
    					nodeB = node4;

    					int temp = random[i+1];
    					random[i+1] = random[i];
    					random[i] = temp;
    					int N1=connectionNumber;
    					int M1=i+1;
    					int u = M1 + rand()/(RAND_MAX/(N1-M1+1) + 1);

    					temp = random[u];
    					random[u] = random[i+1];
    					random[i+1] = temp;
    				}
    			}
    			else
    			{
    				nodeA = netmap1[random[i]];
    				nodeB = netmap2[random[i]];
    			}




    			if(ptr[nodeA]==EMPTY && ptr[nodeB]==EMPTY)
    			{

    			en1=1;
    			en2=1;
    			ptr[nodeA] = -2;
    			ptr[nodeB] = nodeA;
    			index = nodeA;
    			entropy = (long double)(entropy-(-2.0/vertices*log(1.0/vertices))+(-2.0/vertices*log(2.0/vertices)));
    			if(entropy<0) entropy = 0;
    			}
    			else if(ptr[nodeA]==EMPTY && ptr[nodeB]!=EMPTY)
    			{

    			en1=1;
    			int e = findroot(ptr,nodeB);
    			en2 = -(ptr[e]);
    			ptr[nodeA] = e;
    			ptr[e] += -1;
    			index = e;
    			entropy = entropy-(-(double)1.0/vertices*log(1.0/(double)vertices))-(-(double)en2/vertices*log((double)en2/vertices))+(-( double)(-ptr[index])/vertices*log((-ptr[index])/(double)vertices));
    			if(entropy<0) entropy = 0;

    			}
    			else if(ptr[nodeA]!=EMPTY && ptr[nodeB]==EMPTY)
    			{

    			en2 = 1;
    			int f = findroot(ptr,nodeA);
    			en1 = -(ptr[f]);
    			ptr[nodeB] = f;
    			ptr[f] += -1;
    			index = f;
    			entropy = entropy-(-(double)1.0/(long double)vertices*log(1.0/(long double)vertices))-(-(double)en1/(long double)vertices*log((long double)en1/vertices))+(-(long double)(-ptr[index])/vertices*log((-ptr[index])/(long double)vertices));
    			if(entropy<0) entropy = 0;
    			}
    			else if(ptr[nodeA]!=EMPTY && ptr[nodeB]!=EMPTY)
    			{

    				int g,h;
    				g = findroot(ptr,nodeA);
    				en1 = -(ptr[g]);
    				h = findroot(ptr,nodeB);
    				en2 = -(ptr[h]);
    				if(g!=h)
    				{
    					if(ptr[g]<ptr[h])
    					{

    						ptr[g] += ptr[h];
    						ptr[h] = g;
    						index = g;
    					}
    					else
    					{

    						ptr[h] += ptr[g];
    						ptr[g] = h;
    						index = h;
    					}
    					entropy = entropy-(-(long double)en1/(long double)vertices*log((long double)en1/(long double)vertices))-(-(long double)en2/vertices*log((long double)en2/(long double)vertices))+(-(long double)(-ptr[index])/vertices*log((long double)(-ptr[index])/(long double)vertices));
    					if(entropy<0) entropy = 0;
    				}
    				else
    				{

    					jump=big-bigtemp;
    					maxclus[i] += big;
    					delmx[i] += jump;
    					if(entropy<0) entropy = 0;
    					entropycalc[i] += entropy;
    					bigtemp = big;


    					continue;
    				}
    			}

    			if(-ptr[index]>big) big = -ptr[index];

    			jump = big - bigtemp;
    			maxclus[i] += big;
    			delmx[i] += jump;
    			entropycalc[i] += entropy;
    			bigtemp = big;


    		}
    	}

    	fout1.open(filename1.c_str());
    	fout2.open(filename2.c_str());
    	fout3.open(filename3.c_str());

    	//saves the result of maxcluster, jump and entropy calculation to file

    	for(int i=1;i<=connectionNumber;i++)
    	{
    		fout1<<(double)i/connectionNumber<<'\t'<<(double)maxclus[i]/vertices/run<<endl;
    		fout2<<(double)i/connectionNumber<<'\t'<<(double)delmx[i]/run<<endl;
    		fout3<<(double)i/connectionNumber<<'\t'<<(double)entropycalc[i]/run<<endl;
    	}

    	fout1.close();
    	fout2.close();
    	fout3.close();


    	delete[] random;
    	random = NULL;
    	delete[] maxclus;
    	maxclus = NULL;
    	delete[] delmx;
    	delmx = NULL;
    	delete[] entropycalc;
    	entropycalc = NULL;

    }




    int main()
    {
    	int a,b,c,d,e,f;

    	cout<<"enter seed size: ";
    	cin>>a;
    	cout<<endl;
    	cout<<"enter vertice number: ";
    	cin>>b;
    	cout<<endl;
    	cout<<"order number: ";
    	cin>>c;
    	cout<<endl;
    	cout<<"enter ensemble number: ";
    	cin>>d;
    	cout<<endl;
    	cout<<"enter filenumber: ";
    	cin>>e;
    	cout<<endl;

    	int con = 0;

    	for(int i=1;i<a;i++)
    	{
    		con = con + i;
    	}

    	con = con + (b-a)*c;

    	int* ntmp1 = new int[con+1];
    	int* ntmp2 = new int[con+1];

    	for(int i=1;i<=con;i++)
    	{
    		ntmp1[i] = 0;
    		ntmp2[i] = 0;
    	}


    	seed(ntmp1,ntmp2,a);

    	BA(ntmp1,ntmp2,b,a,c);

    	explosivepercolation(ntmp1,ntmp2,b,d,e,c);


    	delete [] ntmp1;
    	ntmp1 = NULL;
    	delete [] ntmp2;
    	ntmp2 = NULL;

    	return 0;

    }

now the error it shows on icpc is

 

if any kind soul know how to fix this, please help me out.

 

 


Viewing all articles
Browse latest Browse all 2746

Trending Articles