MCPcopy Create free account
hub / github.com/clMathLibraries/clFFT / permutation_calculation

Function permutation_calculation

src/library/generator.transpose.cpp:363–420  ·  view source on GitHub ↗

calculate the permutation cycles consumed in swap kernels. each cycle is strored in a vecotor. hopfully there are mutliple independent vectors thus we use a vector of vecotor */

Source from the content-addressed store, hash-verified

361each cycle is strored in a vecotor. hopfully there are mutliple independent vectors thus we use a vector of vecotor
362*/
363void permutation_calculation(size_t m, size_t n, std::vector<std::vector<size_t> > &permutationVec)
364{
365 /*
366 calculate inplace transpose permutation lists
367 reference:
368 https://en.wikipedia.org/wiki/In-place_matrix_transposition
369 and
370 http://www.netlib.org/utk/people/JackDongarra/CCDSC-2014/talk35.pdf
371 row major matrix of size n x m
372 p(k) = (k*n)mod(m*n-1), if 0 < k < m*n-1
373 when k = 0 or m*n-1, it does not require movement
374 */
375 if (m < 1 || n < 1)
376 return;
377
378 size_t mn_minus_one = m*n - 1;
379 //maintain a table so check is faster
380 size_t *table = new size_t[mn_minus_one + 1]();//init to zeros
381 table[0] = 1;
382
383 for (size_t i = 1; i < mn_minus_one; i++)
384 {
385 //first check if i is already stored in somewhere in vector of vectors
386 bool already_checked = false;
387 if (table[i] >= 1)
388 already_checked = true;
389 if (already_checked == true)
390 continue;
391
392 //if not checked yet
393 std::vector<size_t> vec;
394 vec.push_back(i);
395 table[i] += 1;
396 size_t temp = i;
397
398 while (1)
399 {
400 temp = (temp*n);
401 temp = temp % (mn_minus_one);
402 if (find(vec.begin(), vec.end(), temp) != vec.end())
403 {
404 //what goes around comes around and it should
405 break;
406 }
407 if (table[temp] >= 1)
408 {
409 already_checked = true;
410 break;
411 }
412 vec.push_back(temp);
413 table[temp] += 1;
414 }
415 if (already_checked == true)
416 continue;
417 permutationVec.push_back(vec);
418 }
419 delete[] table;
420}

Callers 2

getWorkSizesMethod · 0.85
genSwapKernelGeneralFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected