int main(int argc, const char * argv[]) { ISAutoreleasePoolPush(); /* create a mutable string */ ISMutableStringRef mutableString = ISStringCreateMutable("hello world", ISASCIIStringEncoding); /* retain + 1 */ ISRetain(mutableString); /* mutable string length */ int length = ISStringLength(mutableString); printf("length %i\n", length); /* make a non mutable copy */ ISStringRef otherString = ISCopy(mutableString); printf("%s\n", ISStringCString(otherString)); ISRelease(otherString); /* replace chars, only works on mutable */ ISStringReplaceChar(mutableString, 'l', 'x'); printf("%s\n", ISStringCString(mutableString)); /* release mutable string */ ISRelease(mutableString); ISAutorelease(mutableString); ISAutoreleasePoolPop(); return 0; }
static PetscErrorCode VecNestSetSubVec_Private(Vec X,PetscInt idxm,Vec x) { Vec_Nest *bx = (Vec_Nest*)X->data; PetscInt i,offset=0,n=0,bs; IS is; PetscErrorCode ierr; PetscBool issame = PETSC_FALSE; PetscInt N=0; /* check if idxm < bx->nb */ if (idxm >= bx->nb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Out of range index value %D maximum %D",idxm,bx->nb); PetscFunctionBegin; ierr = VecDestroy(&bx->v[idxm]);CHKERRQ(ierr); /* destroy the existing vector */ ierr = VecDuplicate(x,&bx->v[idxm]);CHKERRQ(ierr); /* duplicate the layout of given vector */ ierr = VecCopy(x,bx->v[idxm]);CHKERRQ(ierr); /* copy the contents of the given vector */ /* check if we need to update the IS for the block */ offset = X->map->rstart; for (i=0; i<idxm; i++) { n=0; ierr = VecGetLocalSize(bx->v[i],&n);CHKERRQ(ierr); offset += n; } /* get the local size and block size */ ierr = VecGetLocalSize(x,&n);CHKERRQ(ierr); ierr = VecGetBlockSize(x,&bs);CHKERRQ(ierr); /* create the new IS */ ierr = ISCreateStride(PetscObjectComm((PetscObject)x),n,offset,1,&is);CHKERRQ(ierr); ierr = ISSetBlockSize(is,bs);CHKERRQ(ierr); /* check if they are equal */ ierr = ISEqual(is,bx->is[idxm],&issame);CHKERRQ(ierr); if (!issame) { /* The IS of given vector has a different layout compared to the existing block vector. Destroy the existing reference and update the IS. */ ierr = ISDestroy(&bx->is[idxm]);CHKERRQ(ierr); ierr = ISDuplicate(is,&bx->is[idxm]);CHKERRQ(ierr); ierr = ISCopy(is,bx->is[idxm]);CHKERRQ(ierr); offset += n; /* Since the current IS[idxm] changed, we need to update all the subsequent IS */ for (i=idxm+1; i<bx->nb; i++) { /* get the local size and block size */ ierr = VecGetLocalSize(bx->v[i],&n);CHKERRQ(ierr); ierr = VecGetBlockSize(bx->v[i],&bs);CHKERRQ(ierr); /* destroy the old and create the new IS */ ierr = ISDestroy(&bx->is[i]);CHKERRQ(ierr); ierr = ISCreateStride(((PetscObject)bx->v[i])->comm,n,offset,1,&bx->is[i]);CHKERRQ(ierr); ierr = ISSetBlockSize(bx->is[i],bs);CHKERRQ(ierr); offset += n; } n=0; ierr = VecSize_Nest_Recursive(X,PETSC_TRUE,&N);CHKERRQ(ierr); ierr = VecSize_Nest_Recursive(X,PETSC_FALSE,&n);CHKERRQ(ierr); ierr = PetscLayoutSetSize(X->map,N);CHKERRQ(ierr); ierr = PetscLayoutSetLocalSize(X->map,n);CHKERRQ(ierr); } ierr = ISDestroy(&is);CHKERRQ(ierr); PetscFunctionReturn(0); }
void PETSC_STDCALL iscopy_(IS is,IS isy, int *__ierr ){ *__ierr = ISCopy( (IS)PetscToPointer((is) ), (IS)PetscToPointer((isy) )); }