*** glibc检测到*** ./PatMatch:双重免费或损坏(输出):0x00007fff202798d0 ***

时间:2013-02-09 12:46:55

标签: parallel-processing opencl

我编写了一个OpenCL程序来实现模式匹配算法。作为输入,程序采用两个二维字符数组。第一个数组用于字符串列表,其中行对应于字符串。第二个数组也是如此,它用于保存模式列表。在每一行的末尾附加一个空终止符('\ 0'),表示在内核中处理字符串时字符串的结尾。

每个工作项都匹配每个模式的单个字符串,并保留匹配模式数的记录,最后将此计数写回全局缓冲区。

程序似乎运行到最后并打印每个字符串中的匹配数。但是当程序终止时,我收到一条错误消息,我无法弄清楚为什么?

我无法继续下去,我需要你的帮助。下面我列出了我使用的内核函数和错误消息。

感谢。

内存映射的错误消息。

    *** glibc detected *** ./PatMatch: double free or corruption (out):    
    0x00007fff202798d0 ***
    ======= Backtrace: =========
    /lib64/libc.so.6[0x377c47247f]
    /lib64/libc.so.6(cfree+0x4b)[0x377c4728db]
    ./PatMatch[0x4016b6]
    /lib64/libc.so.6(__libc_start_main+0xf4)[0x377c41d9b4]
    ./PatMatch[0x400d99]
    ======= Memory map: ========

    00400000-00402000 r-xp 00000000 fd:00 41583479 
   /home/haileyesus/SPD/PatMatch
   00601000-00602000 rw-p 00001000 fd:00 41583479                            /home/haileyesus/SPD/PatMatch
  06e10000-0749e000 rw-p 06e10000 00:00 0                                  [heap]
  4063c000-4063d000 ---p 4063c000 00:00 0 

 ........
 ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0                  [vsyscall]
 Aborted

我有一个内核函数和一个字符串操作非内核函数。

    __global char* StrStr(__global char *hayStack, __global char *needle) {
    if(!*needle)
            return hayStack;
    __global char *tempStr = hayStack;
    while(*tempStr) {
            __global char *pos = tempStr;
            __global char *tempNeedle = needle;
            while(*tempStr && &tempNeedle && *tempStr == *tempNeedle) {
                    tempStr++;
                    tempNeedle++;
            }
            if(!*tempNeedle)
                    return pos;
            tempStr = pos + 1;
    }
    return '\0';
    }

    __kernel void matchPatterns_V1(__global char *strings, __global char *patterns,     

    __global int *matchCount,int strCount, int strLength, int patCount, int patLength)    

   {


    int id = get_global_id(0);
    int rowIndex = id*strLength;
    int i, matches = 0;     

    __global char *pos = strings;
    __global char *temp = strings;
    __global char *pat = patterns;

    for(i = 0; i < patCount; i++)
    {
            temp = &strings[rowIndex];      
            pat = &patterns[i*patLength];
            while(pos != '\0') {
                    pos = StrStr(temp, pat);
                    if(pos != '\0') {
                            matches++;
                            temp = pos + patLength;
                    }
            }
     }
     matchCount[id] = matches;
     }

0 个答案:

没有答案