/ani/mrses

To get this branch, use:
bzr branch http://darksoft.org/webbzr/ani/mrses

« back to all changes in this revision

Viewing changes to cell/mrses_impl.c

  • Committer: Suren A. Chilingaryan
  • Date: 2010-04-30 15:00:46 UTC
  • Revision ID: csa@dside.dyndns.org-20100430150046-1x5cwqqelzx420vf
Fix SPE crashes on big (above 4096) and non-power-of-2 number of properties

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    ctx->nB = nB;
61
61
    ctx->alloc = alloc;
62
62
    ctx->properties = properties;    
 
63
    ctx->palloc = calc_alloc(properties * sizeof(MRSESIntType), HW_ALIGN) / sizeof(MRSESIntType);
63
64
 
64
65
    posix_memalign((void*)&ctx->A, HW_ALIGN, (alloc * properties)*sizeof(MRSESDataType));
65
66
    posix_memalign((void*)&ctx->B, HW_ALIGN, (alloc * properties)*sizeof(MRSESDataType));
193
194
    ctx->nB = nB;
194
195
    ctx->alloc = alloc;
195
196
    ctx->properties = properties;    
 
197
    ctx->palloc = calc_alloc(properties * sizeof(MRSESIntType), HW_ALIGN) / sizeof(MRSESIntType);
196
198
 
197
199
    posix_memalign((void*)&ctx->A, HW_ALIGN, (alloc * properties)*sizeof(MRSESDataType));
198
200
    posix_memalign((void*)&ctx->B, HW_ALIGN, (alloc * properties)*sizeof(MRSESDataType));
388
390
}
389
391
 
390
392
int mrses_iterate(MRSESContext ctx, int iterations, int block_size, MRSESIntType *ires) {
391
 
    int i, width, properties;
 
393
    int i, width, properties, palloc;
392
394
#ifndef FIX_RANDOM
393
395
    struct timeval tv;
394
396
#endif /* FIX_RANDOM */
404
406
 
405
407
    width = ctx->width;
406
408
    properties = ctx->properties;
 
409
    palloc = ctx->palloc;
407
410
 
408
411
#ifdef FIX_RANDOM
409
412
    srandom(FIX_RANDOM);
416
419
        if (!ires) hw_sched_wait_task(ctx->sched);
417
420
        index = ctx->index;
418
421
    } else {
419
 
        posix_memalign((void*)&index, HW_ALIGN, (block_size * properties)*sizeof(MRSESIntType));
 
422
        posix_memalign((void*)&index, HW_ALIGN, (block_size * palloc)*sizeof(MRSESIntType));
420
423
        if (!index) {
421
424
            return 1;
422
425
        }
426
429
        index[i] = i;
427
430
    }
428
431
 
429
 
    iend = index + block_size * properties;    
430
 
    for (iptr = index + properties; iptr < iend; iptr += properties) {
 
432
    iend = index + block_size * palloc;    
 
433
    for (iptr = index + palloc; iptr < iend; iptr += palloc) {
431
434
        memcpy(iptr, index, properties * sizeof(MRSESIntType));
432
435
        
433
436
        for (i = 0; i < width; i++) {