[問題] OpenMP + STL一問

看板C_and_CPP作者 (蘇打)時間14年前 (2009/09/18 12:02), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/2 (看更多)
我嘗試使用OpenMP 但是一直失敗... 原始的程式碼大概如下 set<myclassA> myArray; set<myclassA>::iterator it; set<myclassB> myArray2; set<myclassC> myArray3; int idCounter = 0; //id不能重複 for( it = myArray.begin() ; it != myArray.end() ; ++it ) { // convert (*it) to new myclassB newit = convert( (*it) ); if( myArray2.find( newit ) != myArray2.end() ) { // 如果轉換後可以在myArray2找到,則新增資料到myArray3 newArray3.id = idCounter++; myArray3.insert( newArray3 ); } } 大致程式碼如上 首先他會從myArray中取得資料,轉換為myArray2的格式 接著去確認該資料是否存在於myArray2中 若存在的話,則新增一筆資料到myArray3 其中myArray3的資料都有一個id,此id不得重複 若使用單核心執行,以上程式碼是OK的 但由於資料過大,每次處理都要約20~30分鐘 所以我想使用OpenMP來加速他的處理 翻了一些資料,大概改寫成這樣 #pragma omp parallel private(it, newit) for( it = myArray.begin() ; it != myArray.end() ; ++it ) { // convert (*it) to new myclassB newit = convert( (*it) ); if( myArray2.find( newit ) != myArray2.end() ) { // 如果轉換後可以在myArray2找到,則新增資料到myArray3 newArray3.id = idCounter++; myArray3.insert( newArray3 ); } } 程式執行後會產生segmentation fault 請問這樣的話應該怎麼改呢? 網路上得範例查了很多…但是沒有找到比較符合的 compiler為gcc 4.1.2-14 感謝各位m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.152.129 ※ 編輯: DRLai 來自: 140.138.152.129 (09/18 12:03)

09/18 16:52, , 1F
id那邊會不會有寫入時間差上的問題?
09/18 16:52, 1F

09/18 21:15, , 2F
id只要是唯一就好,先後順序沒差,1,3,5,2,4這樣插入都可以
09/18 21:15, 2F
文章代碼(AID): #1AimPlle (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1AimPlle (C_and_CPP)