ceed.c (5107b09fcb4710dffb8bf2363d6d7d4be3d24cc9) ceed.c (d79b80ece67d77696fb2bb48d63a0a17c4bf9d99)
1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3// reserved. See files LICENSE and NOTICE for details.
4//
5// This file is part of CEED, a collection of benchmarks, miniapps, software
6// libraries and APIs for efficient high-order finite element and spectral
7// element discretizations for exascale applications. For more information and
8// source code availability see http://github.com/ceed.

--- 227 unchanged lines hidden (view full) ---

236 return 0;
237}
238
239/**
240 @brief Allocate a cleared (zeroed) array on the host; use CeedCalloc()
241
242 Memory usage can be tracked by the library.
243
1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3// reserved. See files LICENSE and NOTICE for details.
4//
5// This file is part of CEED, a collection of benchmarks, miniapps, software
6// libraries and APIs for efficient high-order finite element and spectral
7// element discretizations for exascale applications. For more information and
8// source code availability see http://github.com/ceed.

--- 227 unchanged lines hidden (view full) ---

236 return 0;
237}
238
239/**
240 @brief Allocate a cleared (zeroed) array on the host; use CeedCalloc()
241
242 Memory usage can be tracked by the library.
243
244 @param n Number of units to allocate
244 @param n Number of units to allocate
245 @param unit Size of each unit
245 @param unit Size of each unit
246 @param p Address of pointer to hold the result.
246 @param p Address of pointer to hold the result.
247
248 @return An error code: 0 - success, otherwise - failure
249
250 @sa CeedFree()
251
252 @ref Advanced
253**/
254int CeedCallocArray(size_t n, size_t unit, void *p) {

--- 7 unchanged lines hidden (view full) ---

262 return 0;
263}
264
265/**
266 @brief Reallocate an array on the host; use CeedRealloc()
267
268 Memory usage can be tracked by the library.
269
247
248 @return An error code: 0 - success, otherwise - failure
249
250 @sa CeedFree()
251
252 @ref Advanced
253**/
254int CeedCallocArray(size_t n, size_t unit, void *p) {

--- 7 unchanged lines hidden (view full) ---

262 return 0;
263}
264
265/**
266 @brief Reallocate an array on the host; use CeedRealloc()
267
268 Memory usage can be tracked by the library.
269
270 @param n Number of units to allocate
270 @param n Number of units to allocate
271 @param unit Size of each unit
271 @param unit Size of each unit
272 @param p Address of pointer to hold the result.
272 @param p Address of pointer to hold the result.
273
274 @return An error code: 0 - success, otherwise - failure
275
276 @sa CeedFree()
277
278 @ref Advanced
279**/
280int CeedReallocArray(size_t n, size_t unit, void *p) {

--- 31 unchanged lines hidden (view full) ---

312**/
313int CeedRequestWait(CeedRequest *req) {
314 if (!*req)
315 return 0;
316 return CeedError(NULL, 2, "CeedRequestWait not implemented");
317}
318
319/**
273
274 @return An error code: 0 - success, otherwise - failure
275
276 @sa CeedFree()
277
278 @ref Advanced
279**/
280int CeedReallocArray(size_t n, size_t unit, void *p) {

--- 31 unchanged lines hidden (view full) ---

312**/
313int CeedRequestWait(CeedRequest *req) {
314 if (!*req)
315 return 0;
316 return CeedError(NULL, 2, "CeedRequestWait not implemented");
317}
318
319/**
320 @brief Initialize a \ref Ceed to use the specified resource.
320 @brief Initialize a \ref Ceed context to use the specified resource.
321
322 @param resource Resource to use, e.g., "/cpu/self"
321
322 @param resource Resource to use, e.g., "/cpu/self"
323 @param ceed The library context
323 @param ceed The library context
324 @sa CeedRegister() CeedDestroy()
325
326 @return An error code: 0 - success, otherwise - failure
327
328 @ref Basic
329**/
330int CeedInit(const char *resource, Ceed *ceed) {
331 int ierr;

--- 83 unchanged lines hidden (view full) ---

415 ierr = CeedCalloc(len+1, &tmp); CeedChk(ierr);
416 memcpy(tmp, backends[matchidx].prefix, len+1);
417 (*ceed)->resource = tmp;
418
419 return 0;
420}
421
422/**
324 @sa CeedRegister() CeedDestroy()
325
326 @return An error code: 0 - success, otherwise - failure
327
328 @ref Basic
329**/
330int CeedInit(const char *resource, Ceed *ceed) {
331 int ierr;

--- 83 unchanged lines hidden (view full) ---

415 ierr = CeedCalloc(len+1, &tmp); CeedChk(ierr);
416 memcpy(tmp, backends[matchidx].prefix, len+1);
417 (*ceed)->resource = tmp;
418
419 return 0;
420}
421
422/**
423 @brief Retrieve a parent CEED
423 @brief Retrieve a parent Ceed context
424
424
425 @param ceed Ceed to retrieve parent of
426 @param[out] parent Address to save the parent to
425 @param ceed Ceed context to retrieve parent of
426 @param[out] parent Address to save the parent to
427
428 @return An error code: 0 - success, otherwise - failure
429
430 @ref Developer
431**/
432int CeedGetParent(Ceed ceed, Ceed *parent) {
433 int ierr;
434 if (ceed->parent) {
435 ierr = CeedGetParent(ceed->parent, parent); CeedChk(ierr);
436 return 0;
437 }
438 *parent = ceed;
439 return 0;
440}
441
442/**
427
428 @return An error code: 0 - success, otherwise - failure
429
430 @ref Developer
431**/
432int CeedGetParent(Ceed ceed, Ceed *parent) {
433 int ierr;
434 if (ceed->parent) {
435 ierr = CeedGetParent(ceed->parent, parent); CeedChk(ierr);
436 return 0;
437 }
438 *parent = ceed;
439 return 0;
440}
441
442/**
443 @brief Retrieve a delegate CEED
443 @brief Retrieve a delegate Ceed context
444
444
445 @param ceed Ceed to retrieve delegate of
446 @param[out] delegate Address to save the delegate to
445 @param ceed Ceed context to retrieve delegate of
446 @param[out] delegate Address to save the delegate to
447
448 @return An error code: 0 - success, otherwise - failure
449
450 @ref Developer
451**/
452int CeedGetDelegate(Ceed ceed, Ceed *delegate) {
453 *delegate = ceed->delegate;
454 return 0;
455}
456
457/**
447
448 @return An error code: 0 - success, otherwise - failure
449
450 @ref Developer
451**/
452int CeedGetDelegate(Ceed ceed, Ceed *delegate) {
453 *delegate = ceed->delegate;
454 return 0;
455}
456
457/**
458 @brief Set a delegate CEED
458 @brief Set a delegate Ceed context
459
459
460 This function allows a CEED to set a delegate CEED. All backend
461 implementations default to the delegate CEED, unless overridden.
460 This function allows a Ceed context to set a delegate Ceed context. All
461 backend implementations default to the delegate Ceed context, unless
462 overridden.
462
463
463 @param ceed Ceed to set delegate of
464 @param ceed Ceed context to set delegate of
464 @param[out] delegate Address to set the delegate to
465
466 @return An error code: 0 - success, otherwise - failure
467
468 @ref Advanced
469**/
470int CeedSetDelegate(Ceed ceed, Ceed delegate) {
471 ceed->delegate = delegate;
472 delegate->parent = ceed;
473 return 0;
474}
475
476/**
465 @param[out] delegate Address to set the delegate to
466
467 @return An error code: 0 - success, otherwise - failure
468
469 @ref Advanced
470**/
471int CeedSetDelegate(Ceed ceed, Ceed delegate) {
472 ceed->delegate = delegate;
473 delegate->parent = ceed;
474 return 0;
475}
476
477/**
477 @brief Retrieve a delegate CEED for a specific object type
478 @brief Retrieve a delegate Ceed context for a specific object type
478
479
479 @param ceed Ceed to retrieve delegate of
480 @param ceed Ceed context to retrieve delegate of
480 @param[out] delegate Address to save the delegate to
481 @param[in] objname Name of the object type to retrieve delegate for
482
483 @return An error code: 0 - success, otherwise - failure
484
485 @ref Developer
486**/
487int CeedGetObjectDelegate(Ceed ceed, Ceed *delegate, const char *objname) {

--- 8 unchanged lines hidden (view full) ---

496
497 // Use default delegate if no object delegate
498 ierr = CeedGetDelegate(ceed, delegate); CeedChk(ierr);
499
500 return 0;
501}
502
503/**
481 @param[out] delegate Address to save the delegate to
482 @param[in] objname Name of the object type to retrieve delegate for
483
484 @return An error code: 0 - success, otherwise - failure
485
486 @ref Developer
487**/
488int CeedGetObjectDelegate(Ceed ceed, Ceed *delegate, const char *objname) {

--- 8 unchanged lines hidden (view full) ---

497
498 // Use default delegate if no object delegate
499 ierr = CeedGetDelegate(ceed, delegate); CeedChk(ierr);
500
501 return 0;
502}
503
504/**
504 @brief Set a delegate CEED for a specific object type
505 @brief Set a delegate Ceed context for a specific object type
505
506
506 This function allows a CEED to set a delegate CEED for a given type of
507 CEED object. All backend implementations default to the delegate CEED for
508 this object. For example,
507 This function allows a Ceed context to set a delegate Ceed context for a
508 given type of Ceed object. All backend implementations default to the
509 delegate Ceed context for this object. For example,
509 CeedSetObjectDelegate(ceed, refceed, "Basis")
510 uses refceed implementations for all CeedBasis backend functions.
511
510 CeedSetObjectDelegate(ceed, refceed, "Basis")
511 uses refceed implementations for all CeedBasis backend functions.
512
512 @param ceed Ceed to set delegate of
513 @param[out] delegate Address to set the delegate to
514 @param[in] objname Name of the object type to set delegate for
513 @param ceed Ceed context to set delegate of
514 @param[out] delegate Address to set the delegate to
515 @param[in] objname Name of the object type to set delegate for
515
516 @return An error code: 0 - success, otherwise - failure
517
518 @ref Advanced
519**/
520int CeedSetObjectDelegate(Ceed ceed, Ceed delegate, const char *objname) {
521 CeedInt ierr;
522 CeedInt count = ceed->objdelegatecount;

--- 16 unchanged lines hidden (view full) ---

539 delegate->parent = ceed;
540
541 return 0;
542}
543
544/**
545 @brief Set the fallback resource for CeedOperators. The current resource, if
546 any, is freed by calling this function. This string is freed upon the
516
517 @return An error code: 0 - success, otherwise - failure
518
519 @ref Advanced
520**/
521int CeedSetObjectDelegate(Ceed ceed, Ceed delegate, const char *objname) {
522 CeedInt ierr;
523 CeedInt count = ceed->objdelegatecount;

--- 16 unchanged lines hidden (view full) ---

540 delegate->parent = ceed;
541
542 return 0;
543}
544
545/**
546 @brief Set the fallback resource for CeedOperators. The current resource, if
547 any, is freed by calling this function. This string is freed upon the
547 destruction of the Ceed.
548 destruction of the Ceed context.
548
549 @param[out] ceed Ceed context
550 @param resource Fallback resource to set
551
552 @return An error code: 0 - success, otherwise - failure
553
554 @ref Advanced
555**/

--- 26 unchanged lines hidden (view full) ---

582**/
583
584int CeedGetOperatorFallbackResource(Ceed ceed, const char **resource) {
585 *resource = (const char *)ceed->opfallbackresource;
586 return 0;
587}
588
589/**
549
550 @param[out] ceed Ceed context
551 @param resource Fallback resource to set
552
553 @return An error code: 0 - success, otherwise - failure
554
555 @ref Advanced
556**/

--- 26 unchanged lines hidden (view full) ---

583**/
584
585int CeedGetOperatorFallbackResource(Ceed ceed, const char **resource) {
586 *resource = (const char *)ceed->opfallbackresource;
587 return 0;
588}
589
590/**
590 @brief Get the parent Ceed associated with a fallback Ceed for a CeedOperator
591 @brief Get the parent Ceed context associated with a fallback Ceed context
592 for a CeedOperator
591
592 @param ceed Ceed context
593
594 @param ceed Ceed context
593 @param[out] ceed Variable to store parent Ceed
595 @param[out] ceed Variable to store parent Ceed context
594
595 @return An error code: 0 - success, otherwise - failure
596
597 @ref Advanced
598**/
599
600int CeedGetOperatorFallbackParentCeed(Ceed ceed, Ceed *parent) {
601 *parent = ceed->opfallbackparent;
602 return 0;
603}
604
605/**
596
597 @return An error code: 0 - success, otherwise - failure
598
599 @ref Advanced
600**/
601
602int CeedGetOperatorFallbackParentCeed(Ceed ceed, Ceed *parent) {
603 *parent = ceed->opfallbackparent;
604 return 0;
605}
606
607/**
606 @brief Return Ceed preferred memory type
608 @brief Return Ceed context preferred memory type
607
609
608 @param ceed Ceed to get preferred memory type of
609 @param[out] type Address to save preferred memory type to
610 @param ceed Ceed context to get preferred memory type of
611 @param[out] type Address to save preferred memory type to
610
611 @return An error code: 0 - success, otherwise - failure
612
613 @ref Basic
614**/
615int CeedGetPreferredMemType(Ceed ceed, CeedMemType *type) {
616 int ierr;
617

--- 12 unchanged lines hidden (view full) ---

630
631 return 0;
632}
633
634/**
635 @brief Set a backend function
636
637 This function is used for a backend to set the function associated with
612
613 @return An error code: 0 - success, otherwise - failure
614
615 @ref Basic
616**/
617int CeedGetPreferredMemType(Ceed ceed, CeedMemType *type) {
618 int ierr;
619

--- 12 unchanged lines hidden (view full) ---

632
633 return 0;
634}
635
636/**
637 @brief Set a backend function
638
639 This function is used for a backend to set the function associated with
638 the CEED objects. For example,
640 the Ceed objects. For example,
639 CeedSetBackendFunction(ceed, "Ceed", ceed, "VectorCreate", BackendVectorCreate)
640 sets the backend implementation of 'CeedVectorCreate' and
641 CeedSetBackendFunction(ceed, "Basis", basis, "Apply", BackendBasisApply)
642 sets the backend implementation of 'CeedBasisApply'. Note, the prefix 'Ceed'
643 is not required for the object type ("Basis" vs "CeedBasis").
644
641 CeedSetBackendFunction(ceed, "Ceed", ceed, "VectorCreate", BackendVectorCreate)
642 sets the backend implementation of 'CeedVectorCreate' and
643 CeedSetBackendFunction(ceed, "Basis", basis, "Apply", BackendBasisApply)
644 sets the backend implementation of 'CeedBasisApply'. Note, the prefix 'Ceed'
645 is not required for the object type ("Basis" vs "CeedBasis").
646
645 @param ceed Ceed for error handling
647 @param ceed Ceed context for error handling
646 @param type Type of Ceed object to set function for
647 @param[out] object Ceed object to set function for
648 @param fname Name of function to set
649 @param f Function to set
650
651 @return An error code: 0 - success, otherwise - failure
652
653 @ref Advanced

--- 19 unchanged lines hidden (view full) ---

673
674 // LCOV_EXCL_START
675 return CeedError(ceed, 1, "Requested function '%s' was not found for CEED "
676 "object '%s'", fname, type);
677 // LCOV_EXCL_STOP
678}
679
680/**
648 @param type Type of Ceed object to set function for
649 @param[out] object Ceed object to set function for
650 @param fname Name of function to set
651 @param f Function to set
652
653 @return An error code: 0 - success, otherwise - failure
654
655 @ref Advanced

--- 19 unchanged lines hidden (view full) ---

675
676 // LCOV_EXCL_START
677 return CeedError(ceed, 1, "Requested function '%s' was not found for CEED "
678 "object '%s'", fname, type);
679 // LCOV_EXCL_STOP
680}
681
682/**
681 @brief Retrieve backend data for a CEED
683 @brief Retrieve backend data for a Ceed context
682
684
683 @param ceed Ceed to retrieve data of
684 @param[out] data Address to save data to
685 @param ceed Ceed context to retrieve data of
686 @param[out] data Address to save data to
685
686 @return An error code: 0 - success, otherwise - failure
687
688 @ref Advanced
689**/
690int CeedGetData(Ceed ceed, void **data) {
691 *data = ceed->data;
692 return 0;
693}
694
695/**
687
688 @return An error code: 0 - success, otherwise - failure
689
690 @ref Advanced
691**/
692int CeedGetData(Ceed ceed, void **data) {
693 *data = ceed->data;
694 return 0;
695}
696
697/**
696 @brief Set backend data for a CEED
698 @brief Set backend data for a Ceed context
697
699
698 @param ceed Ceed to set data of
700 @param ceed Ceed context to set data of
699 @param data Address of data to set
700
701 @return An error code: 0 - success, otherwise - failure
702
703 @ref Advanced
704**/
705int CeedSetData(Ceed ceed, void **data) {
706 ceed->data = *data;
707 return 0;
708}
709
710/**
701 @param data Address of data to set
702
703 @return An error code: 0 - success, otherwise - failure
704
705 @ref Advanced
706**/
707int CeedSetData(Ceed ceed, void **data) {
708 ceed->data = *data;
709 return 0;
710}
711
712/**
711 @brief Get the full resource name for a CEED
713 @brief Get the full resource name for a Ceed context
712
714
713 @param ceed Ceed to get resource name of
715 @param ceed Ceed context to get resource name of
714 @param[out] resource Variable to store resource name
715
716 @return An error code: 0 - success, otherwise - failure
717
718 @ref Basic
719**/
720
721int CeedGetResource(Ceed ceed, const char **resource) {

--- 40 unchanged lines hidden ---
716 @param[out] resource Variable to store resource name
717
718 @return An error code: 0 - success, otherwise - failure
719
720 @ref Basic
721**/
722
723int CeedGetResource(Ceed ceed, const char **resource) {

--- 40 unchanged lines hidden ---