int main(void) { int rvalue; FILE *fp1, *fp2; char *buffer, *bufStart; int fd11, fd12, fd13; int fd21, fd22, fd23; int i,j, randNum, randFd; fileInfo_t finfo; // ---------------------- Dimiourgia twn fileName1 kai fileName2 ---------------------- // ---------------------- Dimiourgia tou fileName1 ---------------------- printf("\n--------------\n"); printf("CREATING FILES\n"); printf("--------------\n\n"); // Elegxos an yparxei to fileName1 printf("Checking if file %s exists...\n\n", fileName1); if (HDF_ExistsFile(fileName1) == TRUE) { printf("Checkpoint 1:\n"); printf("HDF_ExistsFile returned TRUE!\n\n"); } // Dimiourgia tou arxeiou fileName1 printf("Creating file %s...\n\n", fileName1); if ( (rvalue = HDF_CreateFile(fileName1)) != BFE_OK) { printf("Checkpoint 2:\n"); printf("HDF_CreateFile() returned %d!\n\n", rvalue); } // Anoigma tou arxeiou fileName1 printf("Opening file %s...\n\n", fileName1); if ((rvalue = HDF_OpenFile(fileName1, &fp1)) != BFE_OK) { printf("Checkpoint 3:\n"); printf("HDF_OpenFile() returned %d, should have returned 0!\n\n",rvalue); } // Dimiourgia epikefalidas tou arxeiou sti mnimi buffer = malloc(sizeof(char) * BF_BLOCK_SIZE); bufStart = buffer; memset(buffer, 0, BF_BLOCK_SIZE); // Antigrafi epikefalidas sto block 0 tou arxeiou printf("Writing file header to disk...\n\n"); if ((rvalue = HDF_WriteBlock(0, buffer, fp1)) != BFE_OK) { printf("Checkpoint 4:"); printf("HDF_WriteBlock() returned %d!\n\n",rvalue); } // Kleisimo tou arxeiou fileName1 printf("Closing file %s\n\n", fileName1); if ((rvalue = HDF_CloseFile(fp1)) != BFE_OK) { printf("Checkpoint 5:\n"); printf("HDF_CloseFile() returned %d!\n\n", rvalue); } // ---------------------- Dimiourgia tou fileName2 ---------------------- // Elegxos an yparxei to fileName2 printf("Checking if file %s exists...\n\n", fileName2); if (HDF_ExistsFile(fileName2) == TRUE) { printf("Checkpoint 6:\n"); printf("HDF_ExistsFile returned TRUE!\n\n"); } // Dimiourgia tou arxeiou fileName2 printf("Creating file %s...\n\n", fileName2); if ( (rvalue=HDF_CreateFile(fileName2)) != BFE_OK) { printf("Checkpoint 7:\n"); printf("HDF_CreateFile() returned %d!\n\n", rvalue); } // Anoigma tou arxeiou fileName2 printf("Opening file %s...\n\n", fileName2); if ((rvalue = HDF_OpenFile(fileName2, &fp2)) != BFE_OK) { printf("Checkpoint 8:\n"); printf("HDF_OpenFile() returned %d, should have returned 0!\n\n",rvalue); } // Antigrafi epikefalidas sto block 0 tou arxeiou printf("Writing file header to disk...\n\n"); if ((rvalue = HDF_WriteBlock(0, buffer, fp2)) != BFE_OK) { printf("Checkpoint 9:"); printf("HDF_WriteBlock() returned %d!\n\n",rvalue); } // Kleisimo tou arxeiou fileName2 printf("Closing file %s\n\n", fileName2); if ((rvalue = HDF_CloseFile(fp2)) != BFE_OK) { printf("Checkpoint 10:\n"); printf("HDF_CloseFile() returned %d!\n\n", rvalue); } // ---------------------- FMM epipedo ---------------------- printf("------------------------------------\n"); printf("OPENING AND PROCESSING FILES\n"); printf("------------------------------------\n\n"); FMM_Init(); BMM_Init(); // 1o anoigma tou fileName1 printf("Opening file %s (1)...\n\n", fileName1); if ((fd11 = FMM_Open(fileName1)) < 0) { printf("Checkpoint 11:\n"); printf("FMM_Open() returned %d!\n\n", fd11); } // 2o anoigma tou fileName1 printf("Opening file %s (2)...\n\n", fileName1); if ((fd12 = FMM_Open(fileName1)) < 0) { printf("Checkpoint 12:\n"); printf("FMM_Open() returned %d!\n\n", fd12); } // 3o anoigma tou fileName1 printf("Opening file %s (3)...\n\n", fileName1); if ((fd13 = FMM_Open(fileName1)) < 0) { printf("Checkpoint 13:\n"); printf("FMM_Open() returned %d!\n\n", fd12); } // 1o anoigma tou fileName2 printf("Opening file %s (1)...\n\n", fileName2); if ((fd21 = FMM_Open(fileName2)) < 0) { printf("Checkpoint 14:\n"); printf("FMM_Open() returned %d!\n\n", fd21); } // 2o anoigma tou fileName2 printf("Opening file %s (2)...\n\n", fileName2); if ((fd22 = FMM_Open(fileName2)) < 0) { printf("Checkpoint 15:\n"); printf("FMM_Open() returned %d!\n\n", fd21); } // 3o anoigma tou fileName2 printf("Opening file %s (3)...\n\n", fileName2); if ((fd23 = FMM_Open(fileName2)) < 0) { printf("Checkpoint 16:\n"); printf("FMM_Open() returned %d!\n\n", fd21); } // Ftiakse BLOCKS blocks gia kathe ena apo ta files for (i=0;i<BLOCKS;i++){ randNum = rand()%3; if (randNum==1) randFd = fd13; else if (randNum==2) randFd = fd11; else randFd = fd12; finfo.fd = randFd; if ((rvalue = FMM_GetFileInfoByFD(&finfo)) < 0) { printf("Checkpoint 17:\n"); printf("FMM_GetFileInfoByFD() returned %d!\n\n", rvalue); } if ((rvalue = BMM_AllocBlock(finfo,i,&buffer)) < 0) { printf("Checkpoint 18:\n"); printf("BMM_AllocBlock() returned %d!\n\n", rvalue); } if ((rvalue = FMM_HEAD_Set(fd11, i, TRUE)) < 0) { printf("Checkpoint 19:\n"); printf("FMM_HEAD_Set() returned %d!\n\n", rvalue); } // Tropopoiisi tou block pou "efere" i BMM_AllocBlock j=(300-i)*(300-i); memcpy(buffer,&j,sizeof(int)); if ((rvalue = BMM_UnpinBlock(finfo,i,TRUE)) < 0) { printf("Checkpoint 20:\n"); printf("BMM_UnpinBlock() returned %d!\n\n", rvalue); } randNum = rand()%3; if (randNum==1) randFd = fd22; else if (randNum==2) randFd = fd21; else randFd = fd23; finfo.fd = randFd; if ((rvalue = FMM_GetFileInfoByFD(&finfo)) < 0) { printf("Checkpoint 21:\n"); printf("FMM_GetFileInfoByFD() returned %d!\n\n", rvalue); } if ((rvalue = BMM_AllocBlock(finfo,i,&buffer)) < 0) { printf("Checkpoint 22:\n"); printf("BMM_AllocBlock() returned %d!\n\n", rvalue); } if ((rvalue = FMM_HEAD_Set(fd21, i, TRUE)) < 0) { printf("Checkpoint 23:\n"); printf("FMM_HEAD_Set() returned %d!\n\n", rvalue); } // Tropopoiisi tou block pou "efere" i BMM_AllocBlock memcpy(buffer,&i,sizeof(int)); if ((rvalue = BMM_UnpinBlock(finfo,i,TRUE)) < 0) { printf("Checkpoint 24:\n"); printf("BMM_UnpinBlock() returned %d!\n\n", rvalue); } } finfo.fd = fd11; if ((rvalue = FMM_GetFileInfoByFD(&finfo)) < 0) { printf("Checkpoint 25:\n"); printf("FMM_GetFileInfoByFD() returned %d!\n\n", rvalue); } if ((rvalue = BMM_Flush(finfo)) < 0) { printf("Checkpoint 26:\n"); printf("BMM_Flush() returned %d!\n\n", rvalue); } finfo.fd = fd21; if ((rvalue = FMM_GetFileInfoByFD(&finfo)) < 0) { printf("Checkpoint 27:\n"); printf("FMM_GetFileInfoByFD() returned %d!\n\n", rvalue); } if ((rvalue = BMM_Flush(finfo)) < 0) { printf("Checkpoint 28:\n"); printf("BMM_Flush() returned %d!\n\n", rvalue); } printf("-------------\n"); printf("CLOSING FILES\n"); printf("-------------\n\n"); // Kleisimo 1ou anoigmatos tou fileName1 printf("Closing file %s (1)...\n\n", fileName1); if ((rvalue = FMM_Close(fd11)) != BFE_OK) { printf("Checkpoint 29:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } // Kleisimo 2ou anoigmatos tou fileName1 printf("Closing file %s (2)...\n\n", fileName1); if ((rvalue = FMM_Close(fd12)) != BFE_OK) { printf("Checkpoint 31:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } // Kleisimo 3ou anoigmatos tou fileName1 printf("Closing file %s (3)...\n\n", fileName1); if ((rvalue = FMM_Close(fd13)) != BFE_OK) { printf("Checkpoint 31:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } // Kleisimo 1ou anoigmatos tou fileName2 printf("Closing file %s (1)...\n\n", fileName2); if ((rvalue = FMM_Close(fd21)) != BFE_OK) { printf("Checkpoint 32:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } // Kleisimo 2ou anoigmatos tou fileName2 printf("Closing file %s (2)...\n\n", fileName2); if ((rvalue = FMM_Close(fd22)) != BFE_OK) { printf("Checkpoint 33:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } // Kleisimo 3ou anoigmatos tou fileName2 printf("Closing file %s (3)...\n\n", fileName2); if ((rvalue = FMM_Close(fd23)) != BFE_OK) { printf("Checkpoint 34:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } free(bufStart); return 0; }
/* Initialize parts of this level */ void BF_Init() { FMM_Init(); BMM_Init(); BF_Errno=BFE_OK; }
int main(void) { int rvalue; FILE *fp; char *buffer; int fd; fileInfo_t finfo; char athlete[ATHLETE_SIZE]; int offset; int blockNumInFile1; int blockNumInHeader1; int blockNumInFile2; int blockNumInHeader2; int firstValid; int secondValid; // ---------------------- HDF epipedo ---------------------- // Elegxos an yparxei to fileName printf("\nChecking if file %s exists...\n\n", fileName); if (HDF_ExistsFile(fileName) == TRUE) { printf("Checkpoint 1:\n"); printf("HDF_ExistsFile returned TRUE!\n\n"); } // Dimiourgia tou arxeiou fileName printf("Creating file %s...\n\n", fileName); if ( (rvalue=HDF_CreateFile(fileName)) != BFE_OK) { printf("Checkpoint 2:\n"); printf("HDF_CreateFile() returned %d!\n\n", rvalue); } // Anoigma tou arxeiou fileName printf("Opening file %s...\n\n", fileName); if ((rvalue = HDF_OpenFile(fileName,&fp)) != BFE_OK) { printf("Checkpoint 3:\n"); printf("HDF_OpenFile() returned %d, should have returned 0!\n\n",rvalue); } // Dimiourgia epikefalidas tou arxeiou sti mnimi buffer = malloc(sizeof(char) * BF_BLOCK_SIZE); memset(buffer, 0, BF_BLOCK_SIZE); // Antigrafi epikefalidas sto block 0 tou arxeiou printf("Writing file header to disk...\n\n"); if ((rvalue = HDF_WriteBlock(0, buffer, fp)) != BFE_OK) { printf("Checkpoint 4:"); printf("HDF_WriteBlock() returned %d!\n\n",rvalue); } // Kleisimo tou arxeiou fileName printf("Closing file %s\n\n", fileName); if ((rvalue = HDF_CloseFile(fp)) != BFE_OK) { printf("Checkpoint 5:\n"); printf("HDF_CloseFile() returned %d!\n\n", rvalue); } // ---------------------- FMM epipedo ---------------------- FMM_Init(); // Anoigma tou arxeiou printf("Opening file %s...\n\n", fileName); if ((fd = FMM_Open(fileName)) < 0) { printf("Checkpoint 6:\n"); printf("FMM_Open() returned %d!\n\n", fd); } // Elegxos an i thesi fd tou pinaka anoixtwn arxeiwn einai pleon egkyri kataxwrisi arxeiou printf("Checking for validity of position %d of open files array...\n\n", fd); if (FMM_IsValid(fd) != TRUE) { printf("Checkpoint 7:\n"); printf("FMM_IsValid() returned FALSE!\n\n"); } // Anaktisi pliroforias gia to arxeio me vasi to onoma strcpy(finfo.filename, fileName); printf("Retrieving file information by name...\n\n"); if ((rvalue = FMM_GetFileInfoByName(&finfo)) != BFE_OK) { printf("Checkpoint 8:\n"); printf("FMM_GetFileInfoByName() returned %d!\n\n", rvalue); } printFileInfo(&finfo); // Anaktisi pliroforias gia to arxeio me vasi to fd finfo.fd = fd; printf("Retrieving file information by file descriptor...\n\n"); if ((rvalue = FMM_GetFileInfoByFD(&finfo)) != BFE_OK) { printf("Checkpoint 9:\n"); printf("FMM_GetFileInfoByFD() returned %d!\n\n", rvalue); } printFileInfo(&finfo); // Dimiourgia enos neou block sti mnimi memset(buffer, 0, BF_BLOCK_SIZE); offset = 0; strcpy(athlete, "Periklis Iakovakis"); memcpy(buffer + offset, athlete, ATHLETE_SIZE); offset += ATHLETE_SIZE; strcpy(athlete, "Pyrros Dimas"); memcpy(buffer + offset, athlete, ATHLETE_SIZE); offset += ATHLETE_SIZE; strcpy(athlete, "Helena Isinbayeva"); memcpy(buffer + offset, athlete, ATHLETE_SIZE); offset += ATHLETE_SIZE; strcpy(athlete, "Blanka Vlasic"); memcpy(buffer + offset, athlete, ATHLETE_SIZE); // Grapsimo aytou tou block sto arxeio sti thesi blockNumInFile fp = finfo.fp; blockNumInFile1 = 5; printf("Writing block to disk...\n\n"); if ((rvalue = HDF_WriteBlock(blockNumInFile1, buffer, fp)) != BFE_OK) { printf("Checkpoint 10:"); printf("HDF_WriteBlock() returned %d!\n\n",rvalue); } // Enimerwsi tis epikefalidas tou arxeiou oti to block ayto einai pleon egkyro blockNumInHeader1 = blockNumInFile1 - 1; // PROSOXH SE AYTO!!! printf("Updating header...\n\n"); if ((rvalue = FMM_HEAD_Set(fd, blockNumInHeader1, TRUE)) != BFE_OK) { printf("Checkpoint 11:"); printf("FMM_HEAD_Set() returned %d!\n\n",rvalue); } // Elegxos an enimerwthike i epikefalida printf("Checking header...\n\n"); if (FMM_HEAD_IsValid(fd, blockNumInHeader1) == FALSE) { printf("Checkpoint 12:"); printf("FMM_HEAD_isValid() returned %d!\n\n",rvalue); } // Anaktisi tou prwtou egkyrou block tou arxeiou printf("Retrieving first valid block...\n\n"); if ((firstValid = FMM_HEAD_GetFirstBlock(fd)) == BFE_EOF) { printf("Checkpoint 13:"); printf("FMM_HEAD_GetFirstBlock returned %d!\n\n",rvalue); } printf("firstValid = %d, it should be equal to %d\n\n", firstValid, blockNumInHeader1); // Dimiourgia enos 2ou neou block sti mnimi memset(buffer, 0, BF_BLOCK_SIZE); offset = 0; strcpy(athlete, "Vasilis Spanoulis"); memcpy(buffer + offset, athlete, ATHLETE_SIZE); offset += ATHLETE_SIZE; strcpy(athlete, "Sofoklis Sxortsianitis"); memcpy(buffer + offset, athlete, ATHLETE_SIZE); // Grapsimo aytou tou block sto arxeio sti thesi blockNumInFile blockNumInFile2 = 3; printf("Writing block to disk...\n\n"); if ((rvalue = HDF_WriteBlock(blockNumInFile2, buffer, fp)) != BFE_OK) { printf("Checkpoint 14:"); printf("HDF_WriteBlock() returned %d!\n\n",rvalue); } // Enimerwsi tis epikefalidas tou arxeiou oti to block ayto einai pleon egkyro blockNumInHeader2 = blockNumInFile2 - 1; // PROSOXH SE AYTO!!! printf("Updating header...\n\n"); if ((rvalue = FMM_HEAD_Set(fd, blockNumInHeader2, TRUE)) != BFE_OK) { printf("Checkpoint 15:"); printf("FMM_HEAD_Set() returned %d!\n\n",rvalue); } // Anaktisi tou prwtou egkyrou block tou arxeiou printf("Retrieving first valid block...\n\n"); if ((firstValid = FMM_HEAD_GetFirstBlock(fd)) == BFE_EOF) { printf("Checkpoint 16:"); printf("FMM_HEAD_GetFirstBlock returned %d!\n\n",rvalue); } printf("firstValid = %d, it should be equal to %d\n\n", firstValid, blockNumInHeader2); // Anaktisi tou prwtou egkyrou block tou arxeiou meta apo to firstValid printf("Retrieving first valid block after block %d...\n\n", firstValid); if ((secondValid = FMM_HEAD_GetNextBlock(fd, firstValid)) == BFE_EOF) { printf("Checkpoint 17:"); printf("FMM_HEAD_GetFirstBlock returned %d!\n\n",rvalue); } printf("secondValid = %d, it should be equal to %d\n\n", secondValid, blockNumInHeader1); // Kleisimo arxeiou printf("Closing file %s...\n\n", fileName); if ((rvalue = FMM_Close(fd)) != BFE_OK) { printf("Checkpoint 19:\n"); printf("FMM_Close() returned %d!\n\n", rvalue); } free(buffer); return 0; }
int main(int argc,char **args){ PetscErrorCode ierr; PetscInitialize(&argc,&args,0,help); MPI_Comm comm=MPI_COMM_WORLD; PetscMPIInt rank,size; ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); // ------------------------------------------------------------------- PetscOptionsGetInt (NULL, "-vtk_order",&VTK_ORDER ,NULL); PetscOptionsGetInt (NULL, "-dof",&INPUT_DOF ,NULL); PetscOptionsGetReal(NULL, "-scal",& SCAL_EXP ,NULL); PetscOptionsGetBool(NULL, "-periodic",& PERIODIC ,NULL); PetscOptionsGetBool(NULL, "-tree",& TREE_ONLY ,NULL); PetscOptionsGetInt (NULL, "-max_depth" ,&MAXDEPTH ,NULL); PetscOptionsGetInt (NULL, "-min_depth" ,&MINDEPTH ,NULL); PetscOptionsGetReal(NULL, "-ref_tol" ,& TOL ,NULL); PetscOptionsGetReal(NULL, "-gmres_tol" ,&GMRES_TOL ,NULL); PetscOptionsGetInt (NULL, "-fmm_q" ,& CHEB_DEG ,NULL); PetscOptionsGetInt (NULL, "-fmm_m" ,&MUL_ORDER ,NULL); PetscOptionsGetInt (NULL, "-gmres_iter",& MAX_ITER ,NULL); PetscOptionsGetReal(NULL, "-eta" ,& eta_ ,NULL); // ------------------------------------------------------------------- { /* ------------------------------------------------------------------- Compute the matrix and right-hand-side vector that define the linear system, Ax = b. ------------------------------------------------------------------- */ // Initialize FMM FMMData fmm_data; FMM_Init(comm, &fmm_data); std::cout << "Can you HERE me now" << std::endl; if(TREE_ONLY){ pvfmm::Profile::print(&comm); ierr = PetscFinalize(); return 0; } eval_function_at_nodes(&fmm_data, eta, fmm_data.eta); PetscInt m,n, M,N,l,L; m=fmm_data.m; // local rows n=fmm_data.n; // local columns M=fmm_data.M; // global rows N=fmm_data.N; // global columns l=fmm_data.l; // local values at cheb nodes in cubes (the above are coeff numbers) L=fmm_data.L; // global values at cheb nodes in cubes Vec pt_sources,eta_comp,phi_0,phi_0_val,eta_val,phi; { // Create vectors VecCreateMPI(comm,n,PETSC_DETERMINE,&pt_sources); VecCreateMPI(comm,l,PETSC_DETERMINE,&phi_0_val); // vec of values at each cube VecCreateMPI(comm,l,PETSC_DETERMINE,&eta_val); // vec of values at each cube VecCreateMPI(comm,m,PETSC_DETERMINE,&phi_0); // b=G[f] // vec of the cheb coeffs VecCreateMPI(comm,n,PETSC_DETERMINE,&eta_comp); // Ax=b VecCreateMPI(comm,m,PETSC_DETERMINE,&phi); } std::vector<PetscInt> idxs; std::vector<PetscScalar> eta_std_vec((int)L); idxs.reserve((int)L); //std::iota(idxs.begin(), idxs.end(), 0); for(int i=0;i<(int)L;i++){ idxs.push_back(i); eta_std_vec[i] = (PetscScalar)fmm_data.eta[i]; } ierr = VecSetValues(eta_val,L,idxs.data(),eta_std_vec.data(),INSERT_VALUES); CHKERRQ(ierr); // Seeing if the copy constructor works?? //FMM_Tree_t* eta_tree = fmm_data.tree; //std::cout << "here" << std::endl; //fmm_data.eta_tree->Write2File("results/eta_other",0); //PtWiseTreeMult(fmm_data,*fmm_data.eta_tree); //fmm_data.tree->Write2File("results/etatimespt_srces",0); VecAssemblyBegin(eta_val); VecAssemblyEnd(eta_val); //VecView(eta_val, PETSC_VIEWER_STDOUT_WORLD); fmm_data.eta_val = eta_val; pvfmm::Profile::Tic("Input_Vector_pt_sources",&comm,true); { // Create Input Vector. f tree2vec(fmm_data,pt_sources); fmm_data.tree->Write2File("results/pt_source",0); } pvfmm::Profile::Toc(); pvfmm::Profile::Tic("Input_Vector_phi_0",&comm,true); { // Compute phi_0(x) = \int G(x,y)fn_input(y)dy fmm_data.tree->SetupFMM(fmm_data.fmm_mat); fmm_data.tree->RunFMM(); fmm_data.tree->Copy_FMMOutput(); fmm_data.tree->Write2File("results/phi_0",0); tree2vec(fmm_data,phi_0); fmm_data.phi_0 = phi_0; eval_cheb_at_nodes(&fmm_data,phi_0_val); fmm_data.phi_0_vec = phi_0_val; } pvfmm::Profile::Toc(); pvfmm::Profile::Tic("FMMCreateShell",&comm,true); Mat A; { // Create Matrix. A FMMCreateShell(&fmm_data, &A); MatShellSetOperation(A,MATOP_MULT,(void(*)(void))mult); } pvfmm::Profile::Toc(); pvfmm::Profile::Tic("Phi",&comm,true); { // Compute phi(x) = phi_0(x) -\int G(x,y)eta(y)phi_0(y)dy CompPhiUsingBorn(phi, fmm_data); fmm_data.tree->Write2File("results/phi",0); // tree2vec(fmm_data,b); } pvfmm::Profile::Toc(); pvfmm::Profile::Tic("Right_hand_side",&comm,true); { // Compute phi_0(x) - phi(x) // After this block phi becomes the RHS ierr = VecAXPY(phi,-1,phi_0); CHKERRQ(ierr); vec2tree(phi,fmm_data); //fmm_data.tree->RunFMM(); //fmm_data.tree->Copy_FMMOutput(); fmm_data.tree->Write2File("results/rhs",0); // tree2vec(fmm_data,b); } pvfmm::Profile::Toc(); // Create solution vector pvfmm::Profile::Tic("Initial_Vector_eta_comp",&comm,true); ierr = VecDuplicate(pt_sources,&eta_comp);CHKERRQ(ierr); pvfmm::Profile::Toc(); // Create linear solver context pvfmm::Profile::Tic("KSPCreate",&comm,true); KSP ksp ; ierr = KSPCreate(PETSC_COMM_WORLD,&ksp );CHKERRQ(ierr); pvfmm::Profile::Toc(); // Set operators. Here the matrix that defines the linear system // also serves as the preconditioning matrix. pvfmm::Profile::Tic("KSPSetOperators",&comm,true); ierr = KSPSetOperators(ksp ,A ,A ,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); pvfmm::Profile::Toc(); // Set runtime options KSPSetType(ksp ,KSPGMRES); KSPSetNormType(ksp , KSP_NORM_UNPRECONDITIONED); KSPSetTolerances(ksp ,GMRES_TOL ,PETSC_DEFAULT,PETSC_DEFAULT,MAX_ITER ); //KSPGMRESSetRestart(ksp , MAX_ITER ); KSPGMRESSetRestart(ksp , 100 ); ierr = KSPSetFromOptions(ksp );CHKERRQ(ierr); // ------------------------------------------------------------------- // Solve the linear system // ------------------------------------------------------------------- pvfmm::Profile::Tic("KSPSolve",&comm,true); time_ksp=-omp_get_wtime(); ierr = KSPSolve(ksp,phi,eta_comp);CHKERRQ(ierr); MPI_Barrier(comm); time_ksp+=omp_get_wtime(); pvfmm::Profile::Toc(); // View info about the solver KSPView(ksp,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); // ------------------------------------------------------------------- // Check solution and clean up // ------------------------------------------------------------------- // Iterations PetscInt its; ierr = KSPGetIterationNumber(ksp,&its);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"Iterations %D\n",its);CHKERRQ(ierr); iter_ksp=its; { // Write output vec2tree(eta_comp, fmm_data); fmm_data.tree->Write2File("results/eta_comp",VTK_ORDER); } // Free work space. All PETSc objects should be destroyed when they // are no longer needed. ierr = KSPDestroy(&ksp);CHKERRQ(ierr); ierr = VecDestroy(&eta_comp);CHKERRQ(ierr); ierr = VecDestroy(&phi_0);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); // Delete fmm data FMMDestroy(&fmm_data); pvfmm::Profile::print(&comm); } ierr = PetscFinalize(); return 0; }