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
49
50
51
52
53
54
55
56
57
58
 int
 saf_write_alternate_indexspec(SAF_ParMode pmode,        /* The parallel mode. */
                               SAF_AltIndexSpec *aspec,  /* The alternate index spec to write. */
                               hid_t data_type,          /* The datatype used to identify members of the collection, if not
                                                          * already supplied with saf_declare_alternate_indexspec(). */
                               void *buf,                /* The buffer of data to write. */
                               SAF_Db *file              /* The optional destination file to which to write the data. If this
                                                          * is a null pointer then the data is written to the same file as
                                                          * ASPEC. */
                               )
 {
     SAF_ENTER(saf_write_alternate_indexspec, SAF_PRECONDITION_ERROR);
     double              timer_start=0;
     hsize_t             offset;
     ss_collection_t     coll=SS_COLLECTION_NULL;
     ss_scope_t          scope=SS_SCOPE_NULL;

     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_INDEXSPEC(aspec), SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("ASPEC must be a valid alternate index spec handle"));
     SAF_REQUIRE(buf, SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("BUF must not be null"));
     SAF_REQUIRE(SS_INDEXSPEC(aspec)->m.data_type>0 || data_type>0, SAF_LOW_CHK_COST, SAF_PRECONDITION_ERROR,
                 _saf_errmsg("You must pass a datatype either in the call to saf_declare_alternate_indexspec() or here"));

     /* Start the timer */
     if (_SAF_GLOBALS.p.TraceTimes)
         timer_start = _saf_wall_clock(false);

     /* Get the collection record */
     ss_pers_scope(file?(ss_pers_t*)file:(ss_pers_t*)aspec, &scope);
     if (data_type<=0) data_type = SS_INDEXSPEC(aspec)->m.data_type;
     coll = SS_INDEXSPEC(aspec)->coll;

     /* Disallow overwrites to alt index specs */
     if (!SS_PERS_ISNULL(SS_INDEXSPEC_P(aspec,blob)))
         SAF_ERROR(SAF_FILE_ERROR, _saf_errmsg("cannot overwrite an alt index spec"));

     /* Write the BUF data */
     SAF_DIRTY(aspec, pmode);
     if (NULL==ss_blob_new(&scope, SAF_ALL==pmode?SS_ALLSAME:0U, SS_INDEXSPEC_P(aspec,blob)) ||
         ss_blob_bind_m1(SS_INDEXSPEC_P(aspec,blob), buf, data_type, (hsize_t)SS_COLLECTION(&coll)->count)<0 ||
         ss_blob_mkstorage(SS_INDEXSPEC_P(aspec,blob), &offset, SAF_ALL==pmode?SS_ALLSAME:0U, NULL)<0)
         SAF_ERROR(SAF_FILE_ERROR, _saf_errmsg("cannot allocate file space for the data"));
     if (ss_blob_write1(SS_INDEXSPEC_P(aspec,blob), offset, (hsize_t)SS_COLLECTION(&coll)->count,
                        SS_BLOB_COLLECTIVE|SS_BLOB_UNBIND|(SAF_ALL==pmode?SS_ALLSAME:0U), NULL)<0)
         SAF_ERROR(SAF_FILE_ERROR, _saf_errmsg("cannot write data"));

     /* Accumulate times */
     if (_SAF_GLOBALS.p.TraceTimes)
         _SAF_GLOBALS.CummWriteTime += (_saf_wall_clock(false) - timer_start);

     SAF_LEAVE(SAF_SUCCESS);
 }