| 14 | #define GB_MEM_CHUNK (1024*1024) |
| 15 | |
| 16 | void GB_memset // parallel memset |
| 17 | ( |
| 18 | void *dest, // destination |
| 19 | const int c, // value to to set |
| 20 | size_t n, // # of bytes to set |
| 21 | int nthreads // max # of threads to use |
| 22 | ) |
| 23 | { |
| 24 | |
| 25 | if (nthreads <= 1 || n <= GB_MEM_CHUNK) |
| 26 | { |
| 27 | |
| 28 | //---------------------------------------------------------------------- |
| 29 | // memset using a single thread |
| 30 | //---------------------------------------------------------------------- |
| 31 | |
| 32 | memset (dest, c, n) ; |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | |
| 37 | //---------------------------------------------------------------------- |
| 38 | // memset using multiple threads |
| 39 | //---------------------------------------------------------------------- |
| 40 | |
| 41 | size_t nchunks = 1 + (n / GB_MEM_CHUNK) ; |
| 42 | if (((size_t) nthreads) > nchunks) |
| 43 | { |
| 44 | nthreads = (int) nchunks ; |
| 45 | } |
| 46 | GB_void *pdest = (GB_void *) dest ; |
| 47 | |
| 48 | int64_t k ; |
| 49 | #pragma omp parallel for num_threads(nthreads) schedule(dynamic,1) |
| 50 | for (k = 0 ; k < nchunks ; k++) |
| 51 | { |
| 52 | size_t start = k * GB_MEM_CHUNK ; |
| 53 | if (start < n) |
| 54 | { |
| 55 | size_t chunk = GB_IMIN (n - start, GB_MEM_CHUNK) ; |
| 56 | memset (pdest + start, c, chunk) ; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |
no outgoing calls
no test coverage detected