1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 int
 saf_extend_collection(SAF_ParMode pmode,        /* The parallel mode. */
                       SAF_Set *containing_set,  /* The containing set of the collection. */
                       SAF_Cat *cat,             /* The collection category of the collection. */
                       int add_count,            /* The number of members to add to the collection. */
                       SAF_IndexSpec add_ispec   /* The new indexing scheme. */
                       )
 {
     SAF_ENTER(saf_extend_collection, SAF_PRECONDITION_ERROR);
     ss_collection_t     coll=SS_COLLECTION_NULL;
     ss_indexspec_t      idx=SS_INDEXSPEC_NULL;
     int                 i;

     SAF_REQUIRE(_saf_valid_pmode(pmode), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("PMODE must be valid"));
     if (!_saf_is_participating_proc(pmode)) SAF_RETURN(-1);

     SAF_REQUIRE(SS_SET(containing_set), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("CONTAINING_SET must be a valid set handle for participating processes"));
     SAF_REQUIRE(SS_CAT(cat), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("CAT must be a valid category handle for participating processes"));
     SAF_REQUIRE(_saf_valid_add_indexspec(pmode, containing_set, cat, add_ispec, add_count),
                 SAF_MED_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("ADD_ISPEC sizes must be valid, total ADD_COUNT and be compatible with the existing indexing"
                             " for participating processes"));

     /* If this isn't the self collection, confirm this collection is, indeed, defined on an extendible set */
     if (!_saf_is_self_decomp(cat) && !SS_SET(containing_set)->is_extendible)
         SAF_RETURN(SAF_ASSERTION_ERROR);


     /* Get collection and update relevant portions */
     _saf_getCollection_set(containing_set, cat, &coll);
     SAF_DIRTY(&coll, pmode);
     SS_COLLECTION(&coll)->count += add_count;

     /* Get the default indexing spec and update relevant portions */
     ss_array_get(SS_COLLECTION_P(&coll,indexing), ss_pers_tm, (size_t)0, (size_t)1, &idx);
     SAF_DIRTY(&idx, pmode);
     for (i=0; i<add_ispec.ndims; i++)
         SS_INDEXSPEC(&idx)->sizes[i] += add_ispec.sizes[i];

     /* If this is a non-primitive collection, update the member list */
     if (SS_COLLECTION(&coll)->cell_type == SAF_CELLTYPE_SET)
         ss_array_resize(SS_COLLECTION_P(&coll,members), (size_t)(SS_COLLECTION(&coll)->count));

     SAF_LEAVE(SAF_SUCCESS);
 }