Getting error while using OpenMP along with map in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doijadss
    New Member
    • Dec 2012
    • 1

    Getting error while using OpenMP along with map in c++

    I am using map for assigning an identifiers for a line from file in c++.
    also i am using IDs for a pattern in line {name,operator, val} which is separated by ';'.
    I am using read_pub() for calculating how many patterns are there in a line.

    What is the problem in this code.?

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<iostream>
    #include<fstream>
    #include<omp.h>
    #include<map>
    #include <sstream>
    
    using namespace std;
    struct predicate
    {
    	string att_name;
    	string op;
    	int val;
    };
    stringstream convert1;
    string whole="";
    
    map<string,int> sub_map;
    map<string,int>::iterator sub_i;
    
    map<int,int> count_map;
    map<int,int>::iterator count_i;
    
    map<string,int> pred_map;
    map<string,int>::iterator pred_i;
    
    int subs_count=1;
    
    void output()
    {
    	cout<<endl<<"----------Subs Map:--------"<<endl;
    	for ( sub_i=sub_map.begin() ; sub_i!= sub_map.end(); sub_i++ )
        	{
        		cout<<sub_i->first<<"----->"<<sub_i->second<<endl;
        	}
    	cout<<endl<<"----------Preds Map:--------"<<endl;
        	for ( pred_i=pred_map.begin() ; pred_i!= pred_map.end(); pred_i++ )
        	{
        		cout<<pred_i->first<<"----->"<<pred_i->second<<endl;
        	}
    	cout<<endl<<"----------Count Map:--------"<<endl;
        	for ( count_i=count_map.begin() ; count_i!= count_map.end(); count_i++ )
        	{
        		cout<<count_i->first<<"----->"<<count_i->second<<endl;
        	}
        	
    }
    
    void map_sub(string name)
    {
    	sub_map[name]=subs_count;
    	count_map[subs_count]=0;
    	subs_count++;
    }
    
    void map_preds(string name)
    {
    	pred_map[name]=subs_count;
    }
    
    void inc2(int a)
    {
    	count_map[a]++;
    }
    
    void inc(string name)
    {
    	for ( pred_i=pred_map.begin() ; pred_i!= pred_map.end(); pred_i++ )
        	{
        		if(pred_i->first==name)
        			inc2(pred_i->second);
        	}
    }
    
    void inc3(string name,string op,int val,int z)
    {
    	#pragma omp critical
    	{
    		cout<<name<<":"<<op<<":"<<val<<":"<<z<<endl;
    	}
    	convert1 << val;
    	whole=string(name)+string(op)+string(convert1.str());
    	convert1.str("");
    	inc(whole);
    }
    
    void read_sub()
    {
    	string attr;
      	string op;
      	string value;
    	string event_line="";
    	int len_event=0;
    	int val=0;
    	//int no_preds_sub=0;
    	string whole_pred="";
    	stringstream convert;
    	//int pred_id=0;
    	
    	ifstream sub("/home/Suhas/Data/sub.txt");
    	if(sub.is_open())
    	{
    		while ( sub.good() )
       	 	{
          		getline (sub,event_line);
          		if(event_line.length()==0)
          			break;
          
    			len_event=event_line.length();
    			attr="";
         	 	op="";
         	 	value="";
         	 	val=0;
         	 	//no_preds_sub=0;
         	 	for(int i=0;i<len_event;i++)
         	 	{
         	 		if(event_line[i]==';')
         	 		{
         	 			val=atoi(value.c_str()); //converting string to integer...    	 			
         	 			convert << val;
         	 			whole_pred=string(attr)+string(op)+string(convert.str());
         	 			convert.str("");
         	 			map_preds(whole_pred);
         	 			
         	 			attr=""; 	op="";  value="";
         	 			i++;
         	 		}
         	 		if(event_line[i]>='a' || event_line[i]>='A') //for alphabets...
         	 			attr+=event_line[i];
         	 				
         	 		else if(event_line[i]>=48 && event_line[i]<=57) //for value...
         	 			value+=event_line[i];
         	 				
         	 		else 				// for operator...
         	 			op+=event_line[i];
         	 	}//end for....
         	 	map_sub(event_line);
    		}//end while....
    	}
    	else
    		cout<<"Error";
    		
    	sub.close();	
    	//h1.output();	
    }
    
    
    void read_pub()
    {
    	predicate preds_t[15];
    	string attr="";
      	string op="";
      	string value="";
    	string pub_line="";
    	string whole="";
    	int len_pub=0;
    	stringstream convert;
    	int val=0;
    	//--------------------------------------/
    	int no_preds=0;
    	int j=0;
    	//--------------------------------------/
    	ifstream pub("/home/Suhas/Data/pub.txt");
    	if(pub.is_open())
    	{
    		while ( pub.good() )
       	 	{
          		getline (pub,pub_line);
          		if(pub_line.length()==0)
          			break;	
    			len_pub=pub_line.length();
    			
    			//--------------------------------------/
    			
    			no_preds=0;
    			for(int i=0;i<len_pub;i++)
    			{
    				if(pub_line[i]==';')
    					no_preds++;
    			}
    			cout<<endl<<no_preds<<endl;
    			j=0;		
    			attr="";
         	 	op="";
         	 	value="";
         	 	for(int i=0;i<len_pub;i++)
         	 	{
         	 		if(pub_line[i]==';')
         	 		{
         	 			val=atoi(value.c_str()); //converting string to integer...
         	 			preds_t[j].att_name=attr;
         	 			preds_t[j].op=op;
         	 			preds_t[j].val=val;
         	 			j++;     	 			
         	 			attr=""; 	op="";  value="";
         	 			i++;
         	 		}
         	 		if(pub_line[i]>='a' || pub_line[i]>='A') //for alphabets...
         	 			attr+=pub_line[i];
         	 				
         	 		else if(pub_line[i]>=48 && pub_line[i]<=57) //for value...
         	 			value+=pub_line[i];
         	 				
         	 		else 				// for operator...
         	 			op+=pub_line[i];
         	 	}//end for....
         	 	
         	 	
    			for(int i=0;i<j;i++)
    			{
    				cout<<preds_t[i].att_name<<"	:	"<<preds_t[i].op<<" :	"<<preds_t[i].val<<endl;
    			}
    			
    			
    			
    			#pragma omp parallel for
    			for(int i=0;i<j;i++)
    			{
    				inc3(preds_t[i].att_name,preds_t[i].op,preds_t[i].val,omp_get_thread_num());
    			}	
    			
    				
    
    		#pragma omp barrier		
    		}//end while....
    	}
    	else
    		cout<<"Error";
    	pub.close();	
    }
    
    
    int main()
    {
    	read_sub();
    	output();
    	read_pub();
    	cout<<endl<<endl<<"-:SDASDASDAD:-"<<endl;
    	output();
    }

    Both files sub.txt and pub.txt contains:--

    ABLS=8;ALS=3;AS L=12;Ab=6;Abnak i=3;Abutilon=5; Ac=8;Acanthophi s=13;Acanthurus =5;Accra=4;

    AEC=10;ANSI=6;A SCII=9;AZ=5;Abe naki=3;Abib=4;A bkhazian=1;Abor =14;Acalypha=15 ;Acarina=7;

    ABLS=11;ADR=8;A EC=4;APC=2;ATP= 10;Abkhas=12;Ab naki=4;Abo=4;Ab raham=4;Acantho cybium=12;

    AA=8;ALS=15;ANS I=8;ATM=13;Ab=1 1;Abib=13;Abies =13;Aborigine=1 4;Ac=2;Accadian =2;



    I am getting output/error as:-
    ----------Subs Map:--------
    AA=8;ALS=15;ANS I=8;ATM=13;Ab=1 1;Abib=13;Abies =13;Aborigine=1 4;Ac=2;Accadian =2;----->4
    ABLS=11;ADR=8;A EC=4;APC=2;ATP= 10;Abkhas=12;Ab naki=4;Abo=4;Ab raham=4;Acantho cybium=12;----->3
    ABLS=8;ALS=3;AS L=12;Ab=6;Abnak i=3;Abutilon=5; Ac=8;Acanthophi s=13;Acanthurus =5;Accra=4;----->1
    AEC=10;ANSI=6;A SCII=9;AZ=5;Abe naki=3;Abib=4;A bkhazian=1;Abor =14;Acalypha=15 ;Acarina=7;----->2

    ----------Preds Map:--------
    AA=8----->4
    ABLS=11----->3
    ABLS=8----->1
    ADR=8----->3
    AEC=10----->2
    AEC=4----->3
    ALS=15----->4
    ALS=3----->1
    ANSI=6----->2
    ANSI=8----->4
    APC=2----->3
    ASCII=9----->2
    ASL=12----->1
    ATM=13----->4
    ATP=10----->3
    AZ=5----->2
    Ab=11----->4
    Ab=6----->1
    Abenaki=3----->2
    Abib=13----->4
    Abib=4----->2
    Abies=13----->4
    Abkhas=12----->3
    Abkhazian=1----->2
    Abnaki=3----->1
    Abnaki=4----->3
    Abo=4----->3
    Abor=14----->2
    Aborigine=14----->4
    Abraham=4----->3
    Abutilon=5----->1
    Ac=2----->4
    Ac=8----->1
    Acalypha=15----->2
    Acanthocybium=1 2----->3
    Acanthophis=13----->1
    Acanthurus=5----->1
    Acarina=7----->2
    Accadian=2----->4
    Accra=4----->1

    ----------Count Map:--------
    1----->0
    2----->0
    3----->0
    4----->0

    10
    ABLS : = : 8
    ALS : = : 3
    ASL : = : 12
    Ab : = : 6
    Abnaki : = : 3
    Abutilon : = : 5
    Ac : = : 8
    Acanthophis : = : 13
    Acanthurus : = : 5
    Accra : = : 4
    ABLS:=:8:0
    Acanthurus:=:5: 4
    Ac:=:8:3
    Abnaki:=:3:2
    ASL:=:12:1
    ALS:=:3:0
    Accra:=:4:4
    Ab:=:6:1
    Acanthophis:=:1 3:3
    *** glibc detected *** ./a.out: double free or corruption (fasttop): 0x00007f4458000 920 ***
    ======= Backtrace: =========
    /lib64/libc.so.6(+0x75 916)[0x7f4470ecf916]
    /usr/lib64/libstdc++.so.6( _ZNSsD1Ev+0x39)[0x3cd629d4a9]
    ./a.out[0x402195]
    ./a.out[0x403527]
    /usr/lib64/libgomp.so.1[0x3cd6e08502]
    /lib64/libpthread.so.0 (+0x7851)[0x7f44711f4851]
    /lib64/libc.so.6(clone +0x6d)[0x7f4470f4211d]
    ======= Memory map: ========
    00400000-00408000 r-xp 00000000 fd:02 5377450 /home/Suhas/Desktop/Total Dissertation/cpp programs/try parellel/a.out
    00608000-00609000 rw-p 00008000 fd:02 5377450 /home/Suhas/Desktop/Total Dissertation/cpp programs/try parellel/a.out
    0189b000-018bc000 rw-p 00000000 00:00 0 [heap]
    3cd2600000-3cd2616000 r-xp 00000000 fd:00 36502 /lib64/libgcc_s-4.4.6-20120305.so.1
    3cd2616000-3cd2815000 ---p 00016000 fd:00 36502 /lib64/libgcc_s-4.4.6-20120305.so.1
    3cd2815000-3cd2816000 rw-p 00015000 fd:00 36502 /lib64/libgcc_s-4.4.6-20120305.so.1
    3cd6200000-3cd62e8000 r-xp 00000000 fd:00 76870 /usr/lib64/libstdc++.so.6. 0.13
    3cd62e8000-3cd64e8000 ---p 000e8000 fd:00 76870 /usr/lib64/libstdc++.so.6. 0.13
    3cd64e8000-3cd64ef000 r--p 000e8000 fd:00 76870 /usr/lib64/libstdc++.so.6. 0.13
    3cd64ef000-3cd64f1000 rw-p 000ef000 fd:00 76870 /usr/lib64/libstdc++.so.6. 0.13
    3cd64f1000-3cd6506000 rw-p 00000000 00:00 0
    3cd6e00000-3cd6e0d000 r-xp 00000000 fd:00 40701 /usr/lib64/libgomp.so.1.0. 0
    3cd6e0d000-3cd700c000 ---p 0000d000 fd:00 40701 /usr/lib64/libgomp.so.1.0. 0
    3cd700c000-3cd700d000 rw-p 0000c000 fd:00 40701 /usr/lib64/libgomp.so.1.0. 0
    7f4458000000-7f4458021000 rw-p 00000000 00:00 0
    7f4458021000-7f445c000000 ---p 00000000 00:00 0
    7f4460000000-7f4460021000 rw-p 00000000 00:00 0
    7f4460021000-7f4464000000 ---p 00000000 00:00 0
    7f4464000000-7f4464021000 rw-p 00000000 00:00 0
    7f4464021000-7f4468000000 ---p 00000000 00:00 0
    7f4468000000-7f4468021000 rw-p 00000000 00:00 0
    7f4468021000-7f446c000000 ---p 00000000 00:00 0
    7f446c64b000-7f446c64c000 ---p 00000000 00:00 0
    7f446c64c000-7f446d04c000 rw-p 00000000 00:00 0
    7f446d04c000-7f446d04d000 ---p 00000000 00:00 0
    7f446d04d000-7f446da4d000 rw-p 00000000 00:00 0
    7f446da4d000-7f446da4e000 ---p 00000000 00:00 0
    7f446da4e000-7f446e44e000 rw-p 00000000 00:00 0
    7f446e44e000-7f446e44f000 ---p 00000000 00:00 0
    7f446e44f000-7f446ee4f000 rw-p 00000000 00:00 0
    7f446ee4f000-7f446ee50000 ---p 00000000 00:00 0
    7f446ee50000-7f446f850000 rw-p 00000000 00:00 0
    7f446f850000-7f446f851000 ---p 00000000 00:00 0
    7f446f851000-7f4470251000 rw-p 00000000 00:00 0
    7f4470251000-7f4470252000 ---p 00000000 00:00 0
    7f4470252000-7f4470c52000 rw-p 00000000 00:00 0
    7f4470c52000-7f4470c59000 r-xp 00000000 fd:00 75980 /lib64/librt-2.12.so
    7f4470c59000-7f4470e58000 ---p 00007000 fd:00 75980 /lib64/librt-2.12.so
    7f4470e58000-7f4470e59000 r--p 00006000 fd:00 75980 /lib64/librt-2.12.so
    7f4470e59000-7f4470e5a000 rw-p 00007000 fd:00 75980 /lib64/librt-2.12.so
    7f4470e5a000-7f4470fe3000 r-xp 00000000 fd:00 30952 /lib64/libc-2.12.so
    7f4470fe3000-7f44711e3000 ---p 00189000 fd:00 30952 /lib64/libc-2.12.so
    7f44711e3000-7f44711e7000 r--p 00189000 fd:00 30952 /lib64/libc-2.12.so
    7f44711e7000-7f44711e8000 rw-p 0018d000 fd:00 30952 /lib64/libc-2.12.so
    7f44711e8000-7f44711ed000 rw-p 00000000 00:00 0
    7f44711ed000-7f4471204000 r-xp 00000000 fd:00 30976 /lib64/libpthread-2.12.so
    7f4471204000-7f4471404000 ---p 00017000 fd:00 30976 /lib64/libpthread-2.12.so
    7f4471404000-7f4471405000 r--p 00017000 fd:00 30976 /lib64/libpthread-2.12.so
    7f4471405000-7f4471406000 rw-p 00018000 fd:00 30976 /lib64/libpthread-2.12.so
    7f4471406000-7f447140a000 rw-p 00000000 00:00 0
    7f447140a000-7f447148d000 r-xp 00000000 fd:00 75974 /lib64/libm-2.12.so
    7f447148d000-7f447168c000 ---p 00083000 fd:00 75974 /lib64/libm-2.12.so
    7f447168c000-7f447168d000 r--p 00082000 fd:00 75974 /lib64/libm-2.12.so
    7f447168d000-7f447168e000 rw-p 00083000 fd:00 75974 /lib64/libm-2.12.so
    7f447168e000-7f44716ae000 r-xp 00000000 fd:00 30945 /lib64/ld-2.12.so
    7f4471893000-7f4471899000 rw-p 00000000 00:00 0
    7f44718aa000-7f44718ad000 rw-p 00000000 00:00 0
    7f44718ad000-7f44718ae000 r--p 0001f000 fd:00 30945 /lib64/ld-2.12.so
    7f44718ae000-7f44718af000 rw-p 00020000 fd:00 30945 /lib64/ld-2.12.so
    7f44718af000-7f44718b0000 rw-p 00000000 00:00 0
    7fff47604000-7fff47619000 rw-p 00000000 00:00 0 [stack]
    7fff476ed000-7fff476ee000 r-xp 00000000 00:00 0 [vdso]
    ffffffffff60000 0-ffffffffff60100 0 r-xp 00000000 00:00 0 [vsyscall]
    Aborted
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    When I look up your error (*** glibc detected *** ./a.out: double free or corruption (fasttop): 0x00007f4458000 920 ***) I get the impression that some how either you freed the same thing twice or you corrupted its data structures, perhaps by over running a buffer.

    Sorry, I'm not able to dig thru some 150+ lines of code right now to determine which or what; however, hopfully this will get you on the correct path to debuging your code.

    Comment

    Working...