Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26752 Discussions

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

digonto_i_
Beginner
91 Views

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.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 = {};
    	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=0;
    			}
    		for(int l=1;l<i;l++)
    		{
    			totalpk += network.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.size())/totalpk;
    				
    				
    				if(u<pk)
    				{	
    					concheck = 0;
    					for(int n=0;n<m;n++)
    					{
    						
    						if(a==k)
    						{
    							
    							concheck = 1;
    						}
    					}
    					if(concheck==0) 
    					{
    						a[countm]=k;
    						countm++;
    						
    						network.push_back(i);
    						network.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<0) return i;
    	
    	return ptr=findroot(ptr,ptr);
    }	
    
    //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=0;
    		delmx=0;
    		entropycalc=0;
    	}
    
    	for(int i=0;i<=connectionNumber;i++)
    	{
    		random = i;
    	}
    	int* ptr = new int[vertices+1];
    	for(int i=0;i<vertices+1;i++) ptr=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=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 = EMPTY;
    
    		for(int i=1;i<=connectionNumber;i++)
    		{
    			
    			if(i!=connectionNumber)
    			{
    				
    				node1 = netmap1[random];
    				node2 = netmap2[random];
    				node3 = netmap1[random[i+1]];
    				node4 = netmap2[random[i+1]];
    				
    				if(ptr[node1]==EMPTY) clus1 = 1;
    				else
    				{
    					int x = findroot(ptr,node1);
    					clus1 = -ptr;
    				}
    				
    				if(ptr[node2]==EMPTY) clus2 = 1;
    				else
    				{
    					int b = findroot(ptr,node2);
    					clus2 = -ptr;
    				}
    				
    				if(ptr[node3]==EMPTY) clus3 = 1;
    				else 
    				{
    					int c = findroot(ptr,node3);
    					clus3 = -ptr;
    				}
    
    				if(ptr[node4]==EMPTY) clus4 = 1;
    				else 
    				{
    					int d = findroot(ptr,node4);
    					clus4 = -ptr;
    				}
    				
    				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;
    					random = random[i+1];
    					random[i+1] = temp;
    				}
    				else
    				{
    					nodeA = node3;
    					nodeB = node4;
    					
    					int temp = random[i+1];
    					random[i+1] = random;
    					random = temp;
    					int N1=connectionNumber;
    					int M1=i+1;					
    					int u = M1 + rand()/(RAND_MAX/(N1-M1+1) + 1);
    									
    					temp = random;
    					random = random[i+1];
    					random[i+1] = temp;
    				}
    			}
    			else
    			{
    				nodeA = netmap1[random];
    				nodeB = netmap2[random];
    			}
    
    			
    			
    
    			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);
    			ptr[nodeA] = e;
    			ptr += -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);
    			ptr[nodeB] = f;
    			ptr += -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);
    				h = findroot(ptr,nodeB);
    				en2 = -(ptr);
    				if(g!=h)
    				{
    					if(ptr<ptr)
    					{
    			
    						ptr += ptr;
    						ptr = g;
    						index = g;
    					}
    					else 
    					{
    			
    						ptr += ptr;
    						ptr = 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 += big;
    					delmx += jump;
    					if(entropy<0) entropy = 0;
    					entropycalc += entropy;
    					bigtemp = big;
    					
    					
    					continue;
    				}
    			}	
    		
    			if(-ptr[index]>big) big = -ptr[index];
    			
    			jump = big - bigtemp;
    			maxclus += big;
    			delmx += jump;
    			entropycalc += 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/vertices/run<<endl;
    		fout2<<(double)i/connectionNumber<<'\t'<<(double)delmx/run<<endl;
    		fout3<<(double)i/connectionNumber<<'\t'<<(double)entropycalc/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 = 0;
    		ntmp2 = 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.

 

 

0 Kudos
1 Reply
mecej4
Black Belt
91 Views

This is the Intel Fortran for Linux/Mac forum, and if there is a connection of your post to Fortran, I don't see it! There is a separate forum for the Intel C/C++ compiler.

Reply