[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: petsc-dev recompile needed
Good morning everybody,
I finished to modify the code of the library in order to compile the
complex version with a C compiler. A few numbers of files have been
modified. This modifications include a modification of the file
language.py where I put in comment two lines forcing to compile the
library with a c++ compiler. Since I don't really know python, I just
put them as a comment, but i think it is better to put a message
indicating that compiling the complex version of Petsc needs a C90
compliant compiler (gcc 3.4 and after work, it works also with icc) and
is experimental. Actually I am working with this modifications and it
seems to work like a charm (I had no problem with it).
I still need some time to convert the example programs which do not
compile but it will be done soon.
Note for all of us :
Don't use the name I as a variable anymore. It is a reserved word of
the language.
For most of us, the modifications must be transparent.
Regards
Mathieu
diff -r cb4bd6829f52 include/petscmath.h
--- a/include/petscmath.h Wed Jun 28 17:38:54 2006 -0400
+++ b/include/petscmath.h Fri Jun 30 11:28:20 2006 +0200
@@ -27,9 +27,9 @@ extern MPI_Datatype PETSC_DLLEXPORT MPI
#define PetscExpPassiveScalar(a) PetscExpScalar()
#if defined(PETSC_USE_COMPLEX)
-
-/*
- PETSc now only supports std::complex
+#if defined(PETSC_CLANGUAGE_CXX)
+/*
+ C++ support of complex numbers: Original support
*/
#include <complex>
@@ -52,6 +52,34 @@ extern MPI_Datatype PETSC_DLLEXPORT MPI
#define PetscCosScalar(a) std::cos(a)
typedef std::complex<double> PetscScalar;
+#else
+#include <complex.h>
+
+/*
+ C support of complex numbers: Warning it needs a
+ C90 compliant compiler to work...
+ */
+
+extern MPI_Datatype PETSC_DLLEXPORT MPIU_COMPLEX;
+#define MPIU_SCALAR MPIU_COMPLEX
+#if defined(PETSC_USE_MAT_SINGLE)
+#define MPIU_MATSCALAR ??Notdone
+#else
+#define MPIU_MATSCALAR MPIU_COMPLEX
+#endif
+
+#define PetscRealPart(a) creal(a)
+#define PetscImaginaryPart(a) cimag(a)
+#define PetscAbsScalar(a) cabs(a)
+#define PetscConj(a) conj(a)
+#define PetscSqrtScalar(a) csqrt(a)
+#define PetscPowScalar(a,b) cpow(a,b)
+#define PetscExpScalar(a) cexp(a)
+#define PetscSinScalar(a) csin(a)
+#define PetscCosScalar(a) ccos(a)
+
+typedef double complex PetscScalar;
+#endif
/* Compiling for real numbers only */
#else
diff -r cb4bd6829f52 python/PETSc/utilities/languages.py
--- a/python/PETSc/utilities/languages.py Wed Jun 28 17:38:54 2006 -0400
+++ b/python/PETSc/utilities/languages.py Fri Jun 30 11:28:20 2006 +0200
@@ -69,8 +69,8 @@ class Configure(config.base.Configure):
self.clanguage = self.framework.argDB['with-clanguage'].upper().replace('+','x').replace('X','x')
if not self.clanguage in ['C', 'Cxx']:
raise RuntimeError('Invalid C language specified: '+str(self.clanguage))
- if self.scalartype == 'complex':
- self.clanguage = 'Cxx'
+# if self.scalartype == 'complex':
+# self.clanguage = 'Cxx'
if self.clanguage == 'C' and not self.framework.argDB['with-c++-support'] and not self.packagesHaveCxx():
self.framework.argDB['with-cxx'] = '0'
self.framework.logPrint('Turning off C++ support')
diff -r cb4bd6829f52 src/mat/impls/aij/mpi/mpiaij.c
--- a/src/mat/impls/aij/mpi/mpiaij.c Wed Jun 28 17:38:54 2006 -0400
+++ b/src/mat/impls/aij/mpi/mpiaij.c Fri Jun 30 11:28:20 2006 +0200
@@ -2285,7 +2285,7 @@ EXTERN_C_BEGIN
EXTERN_C_BEGIN
#undef __FUNCT__
#define __FUNCT__ "MatMPIAIJSetPreallocationCSR_MPIAIJ"
-PetscErrorCode PETSCMAT_DLLEXPORT MatMPIAIJSetPreallocationCSR_MPIAIJ(Mat B,const PetscInt I[],const PetscInt J[],const PetscScalar v[])
+PetscErrorCode PETSCMAT_DLLEXPORT MatMPIAIJSetPreallocationCSR_MPIAIJ(Mat B,const PetscInt Ii[],const PetscInt J[],const PetscScalar v[])
{
PetscInt m,cstart, cend,j,nnz,i,d;
PetscInt *d_nnz,*o_nnz,nnz_max = 0,rstart,ii;
@@ -2294,7 +2294,7 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatMPI
PetscErrorCode ierr;
PetscFunctionBegin;
- if (I[0]) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"I[0] must be 0 it is %D",I[0]);
+ if (Ii[0]) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Ii[0] must be 0 it is %D",Ii[0]);
B->rmap.bs = B->cmap.bs = 1;
ierr = PetscMapInitialize(B->comm,&B->rmap);CHKERRQ(ierr);
@@ -2308,8 +2308,8 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatMPI
o_nnz = d_nnz + m;
for (i=0; i<m; i++) {
- nnz = I[i+1]- I[i];
- JJ = J + I[i];
+ nnz = Ii[i+1]- Ii[i];
+ JJ = J + Ii[i];
nnz_max = PetscMax(nnz_max,nnz);
if (nnz < 0) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,"Local row %D has a negative %D number of columns",i,nnz);
for (j=0; j<nnz; j++) {
@@ -2336,8 +2336,8 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatMPI
ierr = MatSetOption(B,MAT_COLUMNS_SORTED);CHKERRQ(ierr);
for (i=0; i<m; i++) {
ii = i + rstart;
- nnz = I[i+1]- I[i];
- ierr = MatSetValues_MPIAIJ(B,1,&ii,nnz,J+I[i],values+(v ? I[i] : 0),INSERT_VALUES);CHKERRQ(ierr);
+ nnz = Ii[i+1]- Ii[i];
+ ierr = MatSetValues_MPIAIJ(B,1,&ii,nnz,J+Ii[i],values+(v ? Ii[i] : 0),INSERT_VALUES);CHKERRQ(ierr);
}
ierr = MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
@@ -2880,7 +2880,7 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatMer
PetscErrorCode PETSCMAT_DLLEXPORT MatMerge(MPI_Comm comm,Mat inmat,PetscInt n,MatReuse scall,Mat *outmat)
{
PetscErrorCode ierr;
- PetscInt m,N,i,rstart,nnz,I,*dnz,*onz;
+ PetscInt m,N,i,rstart,nnz,Ii,*dnz,*onz;
PetscInt *indx;
PetscScalar *values;
@@ -2915,8 +2915,8 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatMer
for (i=0;i<m;i++) {
ierr = MatGetRow_SeqAIJ(inmat,i,&nnz,&indx,&values);CHKERRQ(ierr);
- I = i + rstart;
- ierr = MatSetValues(*outmat,1,&I,nnz,indx,values,INSERT_VALUES);CHKERRQ(ierr);
+ Ii = i + rstart;
+ ierr = MatSetValues(*outmat,1,&Ii,nnz,indx,values,INSERT_VALUES);CHKERRQ(ierr);
ierr = MatRestoreRow_SeqAIJ(inmat,i,&nnz,&indx,&values);CHKERRQ(ierr);
}
ierr = MatDestroy(inmat);CHKERRQ(ierr);
diff -r cb4bd6829f52 src/mat/impls/aij/seq/aij.c
--- a/src/mat/impls/aij/seq/aij.c Wed Jun 28 17:38:54 2006 -0400
+++ b/src/mat/impls/aij/seq/aij.c Fri Jun 30 11:28:20 2006 +0200
@@ -2787,7 +2787,7 @@ EXTERN_C_BEGIN
EXTERN_C_BEGIN
#undef __FUNCT__
#define __FUNCT__ "MatSeqAIJSetPreallocationCSR_SeqAIJ"
-PetscErrorCode PETSCMAT_DLLEXPORT MatSeqAIJSetPreallocationCSR_SeqAIJ(Mat B,const PetscInt I[],const PetscInt J[],const PetscScalar v[])
+PetscErrorCode PETSCMAT_DLLEXPORT MatSeqAIJSetPreallocationCSR_SeqAIJ(Mat B,const PetscInt Ii[],const PetscInt J[],const PetscScalar v[])
{
PetscInt i;
PetscInt m,n;
@@ -2799,12 +2799,12 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatSeq
PetscFunctionBegin;
ierr = MatGetSize(B, &m, &n);CHKERRQ(ierr);
- if (I[0]) {
- SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "I[0] must be 0 it is %D", I[0]);
+ if (Ii[0]) {
+ SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Ii[0] must be 0 it is %D", Ii[0]);
}
ierr = PetscMalloc((m+1) * sizeof(PetscInt), &nnz);CHKERRQ(ierr);
for(i = 0; i < m; i++) {
- nz = I[i+1]- I[i];
+ nz = Ii[i+1]- Ii[i];
nz_max = PetscMax(nz_max, nz);
if (nz < 0) {
SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE, "Local row %D has a negative number of columns %D", i, nnz);
@@ -2824,8 +2824,8 @@ PetscErrorCode PETSCMAT_DLLEXPORT MatSeq
ierr = MatSetOption(B,MAT_COLUMNS_SORTED);CHKERRQ(ierr);
for(i = 0; i < m; i++) {
- nz = I[i+1] - I[i];
- ierr = MatSetValues_SeqAIJ(B, 1, &i, nz, J+I[i], values + (v ? I[i] : 0), INSERT_VALUES);CHKERRQ(ierr);
+ nz = Ii[i+1] - Ii[i];
+ ierr = MatSetValues_SeqAIJ(B, 1, &i, nz, J+Ii[i], values + (v ? Ii[i] : 0), INSERT_VALUES);CHKERRQ(ierr);
}
ierr = MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
diff -r cb4bd6829f52 src/mat/impls/baij/mpi/mpibaij.c
--- a/src/mat/impls/baij/mpi/mpibaij.c Wed Jun 28 17:38:54 2006 -0400
+++ b/src/mat/impls/baij/mpi/mpibaij.c Fri Jun 30 11:28:20 2006 +0200
@@ -2103,7 +2103,7 @@ EXTERN_C_END
#undef __FUNCT__
#define __FUNCT__ "MatMPIBAIJSetPreallocationCSR_MPIBAIJ"
-PetscErrorCode MatMPIBAIJSetPreallocationCSR_MPIBAIJ(Mat B,PetscInt bs,const PetscInt I[],const PetscInt J[],const PetscScalar v[])
+PetscErrorCode MatMPIBAIJSetPreallocationCSR_MPIBAIJ(Mat B,PetscInt bs,const PetscInt Ii[],const PetscInt J[],const PetscScalar v[])
{
Mat_MPIBAIJ *baij = (Mat_MPIBAIJ*)B->data;
PetscInt m = B->rmap.n/bs,cstart = baij->cstartbs, cend = baij->cendbs,j,nnz,i,d;
@@ -2114,14 +2114,14 @@ PetscErrorCode MatMPIBAIJSetPreallocatio
PetscFunctionBegin;
#if defined(PETSC_OPT_g)
- if (I[0]) SETERRQ1(PETSC_ERR_ARG_RANGE,"I[0] must be 0 it is %D",I[0]);
+ if (Ii[0]) SETERRQ1(PETSC_ERR_ARG_RANGE,"Ii[0] must be 0 it is %D",Ii[0]);
#endif
ierr = PetscMalloc((2*m+1)*sizeof(PetscInt),&d_nnz);CHKERRQ(ierr);
o_nnz = d_nnz + m;
for (i=0; i<m; i++) {
- nnz = I[i+1]- I[i];
- JJ = J + I[i];
+ nnz = Ii[i+1]- Ii[i];
+ JJ = J + Ii[i];
nnz_max = PetscMax(nnz_max,nnz);
#if defined(PETSC_OPT_g)
if (nnz < 0) SETERRQ1(PETSC_ERR_ARG_RANGE,"Local row %D has a negative %D number of columns",i,nnz);
@@ -2150,8 +2150,8 @@ PetscErrorCode MatMPIBAIJSetPreallocatio
ierr = MatSetOption(B,MAT_COLUMNS_SORTED);CHKERRQ(ierr);
for (i=0; i<m; i++) {
ii = i + rstart;
- nnz = I[i+1]- I[i];
- ierr = MatSetValuesBlocked_MPIBAIJ(B,1,&ii,nnz,J+I[i],values+(v ? I[i] : 0),INSERT_VALUES);CHKERRQ(ierr);
+ nnz = Ii[i+1]- Ii[i];
+ ierr = MatSetValuesBlocked_MPIBAIJ(B,1,&ii,nnz,J+Ii[i],values+(v ? Ii[i] : 0),INSERT_VALUES);CHKERRQ(ierr);
}
ierr = MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
diff -r cb4bd6829f52 src/sys/objects/pinit.c
--- a/src/sys/objects/pinit.c Wed Jun 28 17:38:54 2006 -0400
+++ b/src/sys/objects/pinit.c Fri Jun 30 11:28:20 2006 +0200
@@ -449,9 +449,15 @@ PetscErrorCode PETSC_DLLEXPORT PetscInit
are not called; at least on IRIX.
*/
{
+#ifdef PETSC_CLANGUAGE_CXX
PetscScalar ic(0.0,1.0);
PETSC_i = ic;
- }
+#else
+ PetscScalar ic;
+ ic = 1.I;
+ PETSC_i = ic;
+ }
+#endif
ierr = MPI_Type_contiguous(2,MPIU_REAL,&MPIU_COMPLEX);CHKERRQ(ierr);
ierr = MPI_Type_commit(&MPIU_COMPLEX);CHKERRQ(ierr);
ierr = MPI_Op_create(PetscSum_Local,1,&PetscSum_Op);CHKERRQ(ierr);
diff -r cb4bd6829f52 src/sys/utils/sorti.c
--- a/src/sys/utils/sorti.c Wed Jun 28 17:38:54 2006 -0400
+++ b/src/sys/utils/sorti.c Fri Jun 30 11:28:20 2006 +0200
@@ -137,7 +137,7 @@ static PetscErrorCode PetscSortIntWithAr
.seealso: PetscSortReal(), PetscSortIntPermutation(), PetscSortInt()
@*/
-PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithArray(PetscInt n,PetscInt i[],PetscInt I[])
+PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithArray(PetscInt n,PetscInt i[],PetscInt Ii[])
{
PetscErrorCode ierr;
PetscInt j,k,tmp,ik;
@@ -148,13 +148,13 @@ PetscErrorCode PETSC_DLLEXPORT PetscSort
ik = i[k];
for (j=k+1; j<n; j++) {
if (ik > i[j]) {
- SWAP2(i[k],i[j],I[k],I[j],tmp);
- ik = i[k];
- }
- }
- }
- } else {
- ierr = PetscSortIntWithArray_Private(i,I,n-1);CHKERRQ(ierr);
+ SWAP2(i[k],i[j],Ii[k],Ii[j],tmp);
+ ik = i[k];
+ }
+ }
+ }
+ } else {
+ ierr = PetscSortIntWithArray_Private(i,Ii,n-1);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
@@ -211,7 +211,7 @@ static PetscErrorCode PetscSortIntWithSc
.seealso: PetscSortReal(), PetscSortIntPermutation(), PetscSortInt(), PetscSortIntWithArray()
@*/
-PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithScalarArray(PetscInt n,PetscInt i[],PetscScalar I[])
+PetscErrorCode PETSC_DLLEXPORT PetscSortIntWithScalarArray(PetscInt n,PetscInt i[],PetscScalar Ii[])
{
PetscErrorCode ierr;
PetscInt j,k,tmp,ik;
@@ -223,15 +223,15 @@ PetscErrorCode PETSC_DLLEXPORT PetscSort
ik = i[k];
for (j=k+1; j<n; j++) {
if (ik > i[j]) {
- SWAP2IntScalar(i[k],i[j],I[k],I[j],tmp,stmp);
- ik = i[k];
- }
- }
- }
- } else {
- ierr = PetscSortIntWithScalarArray_Private(i,I,n-1);CHKERRQ(ierr);
- }
- PetscFunctionReturn(0);
-}
-
-
+ SWAP2IntScalar(i[k],i[j],Ii[k],Ii[j],tmp,stmp);
+ ik = i[k];
+ }
+ }
+ }
+ } else {
+ ierr = PetscSortIntWithScalarArray_Private(i,Ii,n-1);CHKERRQ(ierr);
+ }
+ PetscFunctionReturn(0);
+}
+
+