문제

Can somebody help me by formatting the following type of for loop to the GCD dispatch_apply query?

for (y = a; y + b < h - c; y += d)
{
    // body independent of y
    *m++ = *n++ - *p++; 
}

where *m, *n and *p are float pointers

The dispatch_apply API has the following description:

dispatch_apply(<#size_t iterations#>, <#dispatch_queue_t queue#>, <#^(size_t)block#>)

This might be more of a mathematical puzzle, but any help will be great!

Thanks.

EDIT: My working is as follows:

dispatch_apply((h-c-b-a)/d + 1, someQueue, ^(size_t blkId){
    m[blkId] = n[blkId] - p[blkId];
});
도움이 되었습니까?

해결책

dispatch_apply((h - c - b - a + d - 1)/d, dispatch_main(), ^(blkId) {
    m[blkId] = n[blkId] - p[blkId]
});

UPDATE: following should have the same result

dispatch_apply(ceil((double)(h - c - b - a) / d ), dispatch_main(), ^(blkId) {
    m[blkId] = n[blkId] - p[blkId]
});

in first variant I have used that (int)ceil( x / y ) == (int)( x + y - 1 / y )

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top