473,508 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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.?

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<iostream>
  5. #include<fstream>
  6. #include<omp.h>
  7. #include<map>
  8. #include <sstream>
  9.  
  10. using namespace std;
  11. struct predicate
  12. {
  13.     string att_name;
  14.     string op;
  15.     int val;
  16. };
  17. stringstream convert1;
  18. string whole="";
  19.  
  20. map<string,int> sub_map;
  21. map<string,int>::iterator sub_i;
  22.  
  23. map<int,int> count_map;
  24. map<int,int>::iterator count_i;
  25.  
  26. map<string,int> pred_map;
  27. map<string,int>::iterator pred_i;
  28.  
  29. int subs_count=1;
  30.  
  31. void output()
  32. {
  33.     cout<<endl<<"----------Subs Map:--------"<<endl;
  34.     for ( sub_i=sub_map.begin() ; sub_i!= sub_map.end(); sub_i++ )
  35.         {
  36.             cout<<sub_i->first<<"----->"<<sub_i->second<<endl;
  37.         }
  38.     cout<<endl<<"----------Preds Map:--------"<<endl;
  39.         for ( pred_i=pred_map.begin() ; pred_i!= pred_map.end(); pred_i++ )
  40.         {
  41.             cout<<pred_i->first<<"----->"<<pred_i->second<<endl;
  42.         }
  43.     cout<<endl<<"----------Count Map:--------"<<endl;
  44.         for ( count_i=count_map.begin() ; count_i!= count_map.end(); count_i++ )
  45.         {
  46.             cout<<count_i->first<<"----->"<<count_i->second<<endl;
  47.         }
  48.  
  49. }
  50.  
  51. void map_sub(string name)
  52. {
  53.     sub_map[name]=subs_count;
  54.     count_map[subs_count]=0;
  55.     subs_count++;
  56. }
  57.  
  58. void map_preds(string name)
  59. {
  60.     pred_map[name]=subs_count;
  61. }
  62.  
  63. void inc2(int a)
  64. {
  65.     count_map[a]++;
  66. }
  67.  
  68. void inc(string name)
  69. {
  70.     for ( pred_i=pred_map.begin() ; pred_i!= pred_map.end(); pred_i++ )
  71.         {
  72.             if(pred_i->first==name)
  73.                 inc2(pred_i->second);
  74.         }
  75. }
  76.  
  77. void inc3(string name,string op,int val,int z)
  78. {
  79.     #pragma omp critical
  80.     {
  81.         cout<<name<<":"<<op<<":"<<val<<":"<<z<<endl;
  82.     }
  83.     convert1 << val;
  84.     whole=string(name)+string(op)+string(convert1.str());
  85.     convert1.str("");
  86.     inc(whole);
  87. }
  88.  
  89. void read_sub()
  90. {
  91.     string attr;
  92.       string op;
  93.       string value;
  94.     string event_line="";
  95.     int len_event=0;
  96.     int val=0;
  97.     //int no_preds_sub=0;
  98.     string whole_pred="";
  99.     stringstream convert;
  100.     //int pred_id=0;
  101.  
  102.     ifstream sub("/home/Suhas/Data/sub.txt");
  103.     if(sub.is_open())
  104.     {
  105.         while ( sub.good() )
  106.             {
  107.               getline (sub,event_line);
  108.               if(event_line.length()==0)
  109.                   break;
  110.  
  111.             len_event=event_line.length();
  112.             attr="";
  113.               op="";
  114.               value="";
  115.               val=0;
  116.               //no_preds_sub=0;
  117.               for(int i=0;i<len_event;i++)
  118.               {
  119.                   if(event_line[i]==';')
  120.                   {
  121.                       val=atoi(value.c_str()); //converting string to integer...                     
  122.                       convert << val;
  123.                       whole_pred=string(attr)+string(op)+string(convert.str());
  124.                       convert.str("");
  125.                       map_preds(whole_pred);
  126.  
  127.                       attr="";     op="";  value="";
  128.                       i++;
  129.                   }
  130.                   if(event_line[i]>='a' || event_line[i]>='A') //for alphabets...
  131.                       attr+=event_line[i];
  132.  
  133.                   else if(event_line[i]>=48 && event_line[i]<=57) //for value...
  134.                       value+=event_line[i];
  135.  
  136.                   else                 // for operator...
  137.                       op+=event_line[i];
  138.               }//end for....
  139.               map_sub(event_line);
  140.         }//end while....
  141.     }
  142.     else
  143.         cout<<"Error";
  144.  
  145.     sub.close();    
  146.     //h1.output();    
  147. }
  148.  
  149.  
  150. void read_pub()
  151. {
  152.     predicate preds_t[15];
  153.     string attr="";
  154.       string op="";
  155.       string value="";
  156.     string pub_line="";
  157.     string whole="";
  158.     int len_pub=0;
  159.     stringstream convert;
  160.     int val=0;
  161.     //--------------------------------------/
  162.     int no_preds=0;
  163.     int j=0;
  164.     //--------------------------------------/
  165.     ifstream pub("/home/Suhas/Data/pub.txt");
  166.     if(pub.is_open())
  167.     {
  168.         while ( pub.good() )
  169.             {
  170.               getline (pub,pub_line);
  171.               if(pub_line.length()==0)
  172.                   break;    
  173.             len_pub=pub_line.length();
  174.  
  175.             //--------------------------------------/
  176.  
  177.             no_preds=0;
  178.             for(int i=0;i<len_pub;i++)
  179.             {
  180.                 if(pub_line[i]==';')
  181.                     no_preds++;
  182.             }
  183.             cout<<endl<<no_preds<<endl;
  184.             j=0;        
  185.             attr="";
  186.               op="";
  187.               value="";
  188.               for(int i=0;i<len_pub;i++)
  189.               {
  190.                   if(pub_line[i]==';')
  191.                   {
  192.                       val=atoi(value.c_str()); //converting string to integer...
  193.                       preds_t[j].att_name=attr;
  194.                       preds_t[j].op=op;
  195.                       preds_t[j].val=val;
  196.                       j++;                      
  197.                       attr="";     op="";  value="";
  198.                       i++;
  199.                   }
  200.                   if(pub_line[i]>='a' || pub_line[i]>='A') //for alphabets...
  201.                       attr+=pub_line[i];
  202.  
  203.                   else if(pub_line[i]>=48 && pub_line[i]<=57) //for value...
  204.                       value+=pub_line[i];
  205.  
  206.                   else                 // for operator...
  207.                       op+=pub_line[i];
  208.               }//end for....
  209.  
  210.  
  211.             for(int i=0;i<j;i++)
  212.             {
  213.                 cout<<preds_t[i].att_name<<"    :    "<<preds_t[i].op<<" :    "<<preds_t[i].val<<endl;
  214.             }
  215.  
  216.  
  217.  
  218.             #pragma omp parallel for
  219.             for(int i=0;i<j;i++)
  220.             {
  221.                 inc3(preds_t[i].att_name,preds_t[i].op,preds_t[i].val,omp_get_thread_num());
  222.             }    
  223.  
  224.  
  225.  
  226.         #pragma omp barrier        
  227.         }//end while....
  228.     }
  229.     else
  230.         cout<<"Error";
  231.     pub.close();    
  232. }
  233.  
  234.  
  235. int main()
  236. {
  237.     read_sub();
  238.     output();
  239.     read_pub();
  240.     cout<<endl<<endl<<"-:SDASDASDAD:-"<<endl;
  241.     output();
  242. }
  243.  
  244.  

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

ABLS=8;ALS=3;ASL=12;Ab=6;Abnaki=3;Abutilon=5;Ac=8; Acanthophis=13;Acanthurus=5;Accra=4;

AEC=10;ANSI=6;ASCII=9;AZ=5;Abenaki=3;Abib=4;Abkhaz ian=1;Abor=14;Acalypha=15;Acarina=7;

ABLS=11;ADR=8;AEC=4;APC=2;ATP=10;Abkhas=12;Abnaki= 4;Abo=4;Abraham=4;Acanthocybium=12;

AA=8;ALS=15;ANSI=8;ATM=13;Ab=11;Abib=13;Abies=13;A borigine=14;Ac=2;Accadian=2;



I am getting output/error as:-
----------Subs Map:--------
AA=8;ALS=15;ANSI=8;ATM=13;Ab=11;Abib=13;Abies=13;A borigine=14;Ac=2;Accadian=2;----->4
ABLS=11;ADR=8;AEC=4;APC=2;ATP=10;Abkhas=12;Abnaki= 4;Abo=4;Abraham=4;Acanthocybium=12;----->3
ABLS=8;ALS=3;ASL=12;Ab=6;Abnaki=3;Abutilon=5;Ac=8; Acanthophis=13;Acanthurus=5;Accra=4;----->1
AEC=10;ANSI=6;ASCII=9;AZ=5;Abenaki=3;Abib=4;Abkhaz ian=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=12----->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:=:13:3
*** glibc detected *** ./a.out: double free or corruption (fasttop): 0x00007f4458000920 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x75916)[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]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted
Dec 19 '12 #1
1 2638
zmbd
5,501 Recognized Expert Moderator Expert
When I look up your error (*** glibc detected *** ./a.out: double free or corruption (fasttop): 0x00007f4458000920 ***) 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.
Dec 19 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
8179
by: Gil | last post by:
trying to use a template in a vector, in Visual Studio 6 on Windows 2000 #include <vector> using namespace std; template <typename T> class AnyValue { T val;
3
1986
by: IMS.Rushikesh | last post by:
Hi Friends, My work is stuck up because of this unresolvable and unbelievable Error. I'm trying to Serialize my Class object using XmlSerialization. And at below line, I m getting "error File...
8
9987
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
5
9104
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
2
9468
by: =?Utf-8?B?R3lhbmVuZHJh?= | last post by:
I am using Ajax control(Update Panel) in my web page(ASP.Net 2.0) and putting Report Viewer(Sql Server Reporting Services 2005) Control in it. When I am displaying any report it is coming...
4
1462
by: Shailesh Patel | last post by:
Hi, I was adding referance of vb6 COM in asp.net/vb.net web project in bin folder. Every time when I created new vb6 COM, I was re-refrancing it and was copying to web site. Recently, again...
1
2498
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
21
3799
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
3
1393
by: Pallav singh | last post by:
Hi All , i writing a shared library ,containing code in template i trying to explicitly instantiate functional & class template ........But i am getting Error #include<iostream> #include...
4
4008
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.