Changeset 562d8f in git
- Timestamp:
- Jul 10, 2019, 7:46:35 PM (5 years ago)
- Branches:
- (u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
- Children:
- 2fb52dfda50207f5e8f1be93c4aed7752b7af4a1
- Parents:
- c36a59349478e81a9b576d5483791fd3ec54e789
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/flint_mpoly.cc
rc36a59 r562d8f 64 64 65 65 #if 1 66 // m allocis not thread safe; singular polynomials must be constructed in serial66 // memory allocation is not thread safe; singular polynomials must be constructed in serial 67 67 68 68 void convSingPFlintMP(fmpq_mpoly_t res, fmpq_mpoly_ctx_t ctx, poly p, int lp, const ring r) … … 165 165 166 166 #else 167 // m alloc is thread safe; singular polynomials may be constructed in serial167 // memory allocator is thread safe; singular polynomials may be constructed in parallel 168 168 169 169 // like convSingNFlintN_QQ but it takes an initialized fmpq_t f … … 199 199 200 200 convert_sing_to_fmpq_mpoly_base(slong num_threads_, fmpq_mpoly_struct * res_, 201 const fmpq_mpoly_ctx_struct * ctx_, const ring r_ )201 const fmpq_mpoly_ctx_struct * ctx_, const ring r_, poly p) 202 202 : num_threads(num_threads_), 203 203 res(res_), … … 205 205 r(r_) 206 206 { 207 }208 209 void init_poly(poly p)210 {211 207 length = 0; 212 while ( p != NULL)208 while (1) 213 209 { 214 markers.push_back(p); 215 for (int i = 4096; i > 0; i--) 216 { 217 pIter(p); 218 length++; 219 if (p == NULL) 220 break; 221 } 210 if ((length % 4096) == 0) 211 markers.push_back(p); 212 if (p == NULL) 213 return; 214 length++; 215 pIter(p); 222 216 } 223 224 fmpq_mpoly_init3(res, length, SI_LOG2(r->bitmask), ctx);225 217 } 226 218 }; … … 232 224 slong start_idx, end_idx; 233 225 convert_sing_to_fmpq_mpoly_base* base; 226 flint_bitcnt_t required_bits; 234 227 235 228 convert_sing_to_fmpq_mpoly_arg() {fmpq_init(content);} … … 237 230 }; 238 231 239 static void convert_sing_to_fmpq_mpoly_content_ worker(void * varg)232 static void convert_sing_to_fmpq_mpoly_content_bits(void * varg) 240 233 { 241 234 convert_sing_to_fmpq_mpoly_arg* arg = (convert_sing_to_fmpq_mpoly_arg*) varg; 235 convert_sing_to_fmpq_mpoly_base * base = arg->base; 236 ulong * exp = (ulong*) flint_malloc((base->r->N + 1)*sizeof(ulong)); 242 237 fmpq_t c; 243 238 fmpq_init(c); … … 252 247 } 253 248 254 /* first find gcd of coeffs */249 flint_bitcnt_t required_bits = MPOLY_MIN_BITS; 255 250 fmpq_zero(arg->content); 251 256 252 while (idx < arg->end_idx) 257 253 { 258 254 my_convSingNFlintN_QQ(c, number(pGetCoeff(p))); 259 255 fmpq_gcd(arg->content, arg->content, c); 256 257 #if SIZEOF_LONG==8 258 p_GetExpVL(p, (int64*)exp, base->r); 259 flint_bitcnt_t exp_bits = mpoly_exp_bits_required_ui(exp, base->ctx->zctx->minfo); 260 #else 261 p_GetExpV(p, (int*)exp, base->r); 262 flint_bitcnt_t exp_bits = mpoly_exp_bits_required_ui(&(exp[1]), base->ctx->zctx->minfo); 263 #endif 264 265 required_bits = FLINT_MAX(required_bits, exp_bits); 266 260 267 pIter(p); 261 268 idx++; 262 269 } 263 270 271 arg->required_bits = required_bits; 272 264 273 fmpq_clear(c); 274 flint_free(exp); 265 275 } 266 276 … … 330 340 } 331 341 332 convert_sing_to_fmpq_mpoly_base base(num_handles + 1, res, ctx, r );333 base.init_poly(p); 334 342 convert_sing_to_fmpq_mpoly_base base(num_handles + 1, res, ctx, r, p); 343 344 /* fill in thread division points */ 335 345 convert_sing_to_fmpq_mpoly_arg * args = new convert_sing_to_fmpq_mpoly_arg[base.num_threads]; 336 346 slong cur_idx = 0; … … 346 356 } 347 357 348 /* get content */ 349 for (slong i = 0; i < num_handles; i++) 350 thread_pool_wake(global_thread_pool, handles[i], convert_sing_to_fmpq_mpoly_content_worker, args + i); 351 convert_sing_to_fmpq_mpoly_content_worker(args + num_handles); 352 for (slong i = 0; i < num_handles; i++) 353 { 358 /* get content and bits */ 359 for (slong i = 0; i < num_handles; i++) 360 thread_pool_wake(global_thread_pool, handles[i], convert_sing_to_fmpq_mpoly_content_bits, args + i); 361 convert_sing_to_fmpq_mpoly_content_bits(args + num_handles); 362 for (slong i = 0; i < num_handles; i++) 354 363 thread_pool_wait(global_thread_pool, handles[i]); 355 } 364 365 flint_bitcnt_t required_bits = MPOLY_MIN_BITS; 366 for (slong i = 0; i <= num_handles; i++) 367 required_bits = FLINT_MAX(required_bits, args[i].required_bits); 368 369 /* initialize res with optimal bits */ 370 fmpq_mpoly_init3(res, base.length, mpoly_fix_bits(required_bits, ctx->zctx->minfo), ctx); 356 371 357 372 /* sign of content should match sign of first coeff */ … … 418 433 convert_fmpq_mpoly_to_sing_arg * arg = (convert_fmpq_mpoly_to_sing_arg *) varg; 419 434 convert_fmpq_mpoly_to_sing_base * base = arg->base; 420 ulong* exp = (ulong*) flint_ calloc(base->r->N + 1,sizeof(ulong));435 ulong* exp = (ulong*) flint_malloc((base->r->N + 1)*sizeof(ulong)); 421 436 fmpq_t c; 422 437 fmpq_init(c); … … 528 543 529 544 convert_sing_to_nmod_mpoly_base(slong num_threads_, nmod_mpoly_struct * res_, 530 const nmod_mpoly_ctx_struct * ctx_, const ring r_ )545 const nmod_mpoly_ctx_struct * ctx_, const ring r_, poly p) 531 546 : num_threads(num_threads_), 532 547 res(res_), … … 534 549 r(r_) 535 550 { 536 }537 538 void init_poly(poly p)539 {540 551 length = 0; 541 while ( p != NULL)552 while (1) 542 553 { 543 markers.push_back(p); 544 for (int i = 4096; i > 0; i--) 545 { 546 pIter(p); 547 length++; 548 if (p == NULL) 549 break; 550 } 554 if ((length % 4096) == 0) 555 markers.push_back(p); 556 if (p == NULL) 557 return; 558 length++; 559 pIter(p); 551 560 } 552 553 nmod_mpoly_init3(res, length, SI_LOG2(r->bitmask), ctx);554 561 } 555 562 }; … … 560 567 slong start_idx, end_idx; 561 568 convert_sing_to_nmod_mpoly_base* base; 569 flint_bitcnt_t required_bits; 562 570 }; 571 572 static void convert_sing_to_nmod_mpoly_bits(void * varg) 573 { 574 convert_sing_to_nmod_mpoly_arg * arg = (convert_sing_to_nmod_mpoly_arg *) varg; 575 convert_sing_to_nmod_mpoly_base * base = arg->base; 576 ulong * exp = (ulong*) flint_malloc((base->r->N + 1)*sizeof(ulong)); 577 578 slong idx = arg->start_idx/4096; 579 poly p = base->markers[idx]; 580 idx *= 4096; 581 while (idx < arg->start_idx) 582 { 583 pIter(p); 584 idx++; 585 } 586 587 flint_bitcnt_t required_bits = MPOLY_MIN_BITS; 588 589 while (idx < arg->end_idx) 590 { 591 #if SIZEOF_LONG==8 592 p_GetExpVL(p, (int64*)exp, base->r); 593 flint_bitcnt_t exp_bits = mpoly_exp_bits_required_ui(exp, base->ctx->minfo); 594 #else 595 p_GetExpV(p, (int*)exp, base->r); 596 flint_bitcnt_t exp_bits = mpoly_exp_bits_required_ui(&(exp[1]), base->ctx->minfo); 597 #endif 598 599 required_bits = FLINT_MAX(required_bits, exp_bits); 600 601 pIter(p); 602 idx++; 603 } 604 605 arg->required_bits = required_bits; 606 607 flint_free(exp); 608 } 609 563 610 564 611 static void convert_sing_to_nmod_mpoly_worker(void * varg) … … 618 665 } 619 666 620 convert_sing_to_nmod_mpoly_base base(num_handles + 1, res, ctx, r );621 base.init_poly(p); 622 667 convert_sing_to_nmod_mpoly_base base(num_handles + 1, res, ctx, r, p); 668 669 /* fill in thread division points */ 623 670 convert_sing_to_nmod_mpoly_arg * args = new convert_sing_to_nmod_mpoly_arg[base.num_threads]; 624 671 slong cur_idx = 0; … … 635 682 } 636 683 684 /* find required bits */ 685 for (slong i = 0; i < num_handles; i++) 686 thread_pool_wake(global_thread_pool, handles[i], convert_sing_to_nmod_mpoly_bits, args + i); 687 convert_sing_to_nmod_mpoly_bits(args + num_handles); 688 for (slong i = 0; i < num_handles; i++) 689 thread_pool_wait(global_thread_pool, handles[i]); 690 691 flint_bitcnt_t required_bits = MPOLY_MIN_BITS; 692 for (slong i = 0; i <= num_handles; i++) 693 required_bits = FLINT_MAX(required_bits, args[i].required_bits); 694 695 /* initialize res with optimal bits */ 696 nmod_mpoly_init3(res, base.length, mpoly_fix_bits(required_bits, ctx->minfo), ctx); 697 637 698 /* fill in res */ 638 699 for (slong i = 0; i < num_handles; i++) … … 685 746 convert_nmod_mpoly_to_sing_arg * arg = (convert_nmod_mpoly_to_sing_arg *) varg; 686 747 convert_nmod_mpoly_to_sing_base * base = arg->base; 687 ulong* exp = (ulong*) flint_ calloc(base->r->N + 1,sizeof(ulong));748 ulong* exp = (ulong*) flint_malloc((base->r->N + 1)*sizeof(ulong)); 688 749 689 750 for (slong idx = arg->end_idx - 1; idx >= arg->start_idx; idx--)
Note: See TracChangeset
for help on using the changeset viewer.