/[escript]/trunk/paso/src/AMG_Interpolation.cpp
ViewVC logotype

Diff of /trunk/paso/src/AMG_Interpolation.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4814 by caltinay, Fri Mar 28 04:31:02 2014 UTC revision 4816 by caltinay, Fri Mar 28 06:16:02 2014 UTC
# Line 14  Line 14 
14  *****************************************************************************/  *****************************************************************************/
15    
16    
17  /************************************************************************************/  /****************************************************************************/
18    
19  /* Paso: defines AMG Interpolation                            */  /* Paso: defines AMG Interpolation                            */
20    
21  /************************************************************************************/  /****************************************************************************/
22    
23  /* Author: l.gao@uq.edu.au                                    */  /* Author: l.gao@uq.edu.au                                    */
24    
25  /************************************************************************************/  /****************************************************************************/
26    
27  #include "Paso.h"  #include "Paso.h"
28  #include "SparseMatrix.h"  #include "SparseMatrix.h"
29  #include "PasoUtil.h"  #include "PasoUtil.h"
30  #include "Preconditioner.h"  #include "Preconditioner.h"
31    
32  /************************************************************************************  /****************************************************************************
33    
34      Methods necessary for AMG preconditioner      Methods necessary for AMG preconditioner
35    
# Line 38  Line 38 
38    
39      The coarsening operator A_C is defined by RAP where R=P^T.      The coarsening operator A_C is defined by RAP where R=P^T.
40    
41  *************************************************************************************/  *****************************************************************************/
42    
43  /* Extend system matrix B with extra two sparse matrices:  /* Extend system matrix B with extra two sparse matrices:
44      B_ext_main and B_ext_couple      B_ext_main and B_ext_couple
# Line 61  void Paso_Preconditioner_AMG_extendB(Pas Line 61  void Paso_Preconditioner_AMG_extendB(Pas
61  {  {
62      paso::Pattern *pattern_main=NULL, *pattern_couple=NULL;      paso::Pattern *pattern_main=NULL, *pattern_couple=NULL;
63    paso::Coupler *coupler=NULL;    paso::Coupler *coupler=NULL;
64    Paso_SharedComponents *send=NULL, *recv=NULL;    paso::SharedComponents_ptr send, recv;
65    double *cols=NULL, *send_buf=NULL, *ptr_val=NULL, *send_m=NULL, *send_c=NULL;    double *cols=NULL, *send_buf=NULL, *ptr_val=NULL, *send_m=NULL, *send_c=NULL;
66    index_t *global_id=NULL, *cols_array=NULL, *ptr_ptr=NULL, *ptr_idx=NULL;    index_t *global_id=NULL, *cols_array=NULL, *ptr_ptr=NULL, *ptr_idx=NULL;
67    index_t *ptr_main=NULL, *ptr_couple=NULL, *idx_main=NULL, *idx_couple=NULL;    index_t *ptr_main=NULL, *ptr_couple=NULL, *idx_main=NULL, *idx_couple=NULL;
# Line 443  void Paso_Preconditioner_AMG_CopyRemoteD Line 443  void Paso_Preconditioner_AMG_CopyRemoteD
443      index_t **p_ptr, index_t **p_idx, double **p_val,      index_t **p_ptr, index_t **p_idx, double **p_val,
444      index_t *global_id, index_t block_size)      index_t *global_id, index_t block_size)
445  {  {
446    Paso_SharedComponents *send=NULL, *recv=NULL;      paso::SharedComponents_ptr send, recv;
447    index_t send_neighbors, recv_neighbors, send_rows, recv_rows;    index_t send_neighbors, recv_neighbors, send_rows, recv_rows;
448    index_t i, j, p, m, n, size;    index_t i, j, p, m, n, size;
449    index_t *send_degree=NULL, *recv_ptr=NULL, *recv_idx=NULL;    index_t *send_degree=NULL, *recv_ptr=NULL, *recv_idx=NULL;
# Line 595  Paso_SystemMatrix* Paso_Preconditioner_A Line 595  Paso_SystemMatrix* Paso_Preconditioner_A
595     Paso_SystemMatrix *out=NULL;     Paso_SystemMatrix *out=NULL;
596     paso::SystemMatrixPattern *pattern=NULL;     paso::SystemMatrixPattern *pattern=NULL;
597     paso::Distribution_ptr input_dist, output_dist;     paso::Distribution_ptr input_dist, output_dist;
    Paso_SharedComponents *send =NULL, *recv=NULL;  
598     paso::Connector *col_connector=NULL, *row_connector=NULL;     paso::Connector *col_connector=NULL, *row_connector=NULL;
599     paso::Pattern *main_pattern=NULL;     paso::Pattern *main_pattern=NULL;
600     paso::Pattern *col_couple_pattern=NULL, *row_couple_pattern =NULL;     paso::Pattern *col_couple_pattern=NULL, *row_couple_pattern =NULL;
# Line 1746  Paso_SystemMatrix* Paso_Preconditioner_A Line 1745  Paso_SystemMatrix* Paso_Preconditioner_A
1745       num_neighbors ++;       num_neighbors ++;
1746       offsetInShared[num_neighbors] = i;       offsetInShared[num_neighbors] = i;
1747     }     }
1748     recv = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,  
1749              neighbor, shared, offsetInShared, 1, 0, mpi_info);     paso::SharedComponents_ptr recv(new paso::SharedComponents(
1750                   num_Pmain_cols, num_neighbors, neighbor, shared,
1751                   offsetInShared, 1, 0, mpi_info));
1752    
1753     #ifdef ESYS_MPI     #ifdef ESYS_MPI
1754     MPI_Alltoall(recv_len, 1, MPI_INT, send_len, 1, MPI_INT, mpi_info->comm);     MPI_Alltoall(recv_len, 1, MPI_INT, send_len, 1, MPI_INT, mpi_info->comm);
# Line 1801  Paso_SystemMatrix* Paso_Preconditioner_A Line 1802  Paso_SystemMatrix* Paso_Preconditioner_A
1802     offset = dist[rank];     offset = dist[rank];
1803     #pragma omp parallel for schedule(static) private(i)     #pragma omp parallel for schedule(static) private(i)
1804     for (i=0; i<j; i++) shared[i] = shared[i] - offset;     for (i=0; i<j; i++) shared[i] = shared[i] - offset;
1805     send = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,  
1806              neighbor, shared, offsetInShared, 1, 0, mpi_info);     paso::SharedComponents_ptr send(new paso::SharedComponents(
1807                   num_Pmain_cols, num_neighbors, neighbor, shared,
1808                   offsetInShared, 1, 0, mpi_info));
1809    
1810     col_connector = paso::Connector_alloc(send, recv);     col_connector = paso::Connector_alloc(send, recv);
1811     delete[] shared;     delete[] shared;
    Paso_SharedComponents_free(recv);  
    Paso_SharedComponents_free(send);  
1812    
1813     /* now, create row distribution (output_distri) and col     /* now, create row distribution (output_distri) and col
1814        distribution (input_distribution) */        distribution (input_distribution) */
# Line 1876  Paso_SystemMatrix* Paso_Preconditioner_A Line 1877  Paso_SystemMatrix* Paso_Preconditioner_A
1877      offsetInShared[num_neighbors] = k;      offsetInShared[num_neighbors] = k;
1878       }       }
1879     }     }
1880     send = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,     send.reset(new paso::SharedComponents(num_Pmain_cols, num_neighbors,
1881                          neighbor, shared, offsetInShared, 1, 0, mpi_info);                 neighbor, shared, offsetInShared, 1, 0, mpi_info));
1882    
1883     /* send/recv number of rows will be sent from current proc     /* send/recv number of rows will be sent from current proc
1884        recover info for the receiver of row_connector from the sender */        recover info for the receiver of row_connector from the sender */
# Line 1903  Paso_SystemMatrix* Paso_Preconditioner_A Line 1904  Paso_SystemMatrix* Paso_Preconditioner_A
1904     for (i=0; i<k; i++) {     for (i=0; i<k; i++) {
1905       shared[i] = i + num_Pmain_cols;       shared[i] = i + num_Pmain_cols;
1906     }     }
1907     recv = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,     recv.reset(new paso::SharedComponents(num_Pmain_cols, num_neighbors,
1908                          neighbor, shared, offsetInShared, 1, 0, mpi_info);                 neighbor, shared, offsetInShared, 1, 0, mpi_info));
1909     row_connector = paso::Connector_alloc(send, recv);     row_connector = paso::Connector_alloc(send, recv);
1910     delete[] shared;     delete[] shared;
    Paso_SharedComponents_free(recv);  
    Paso_SharedComponents_free(send);  
1911    
1912     /* send/recv pattern->ptr for rowCoupleBlock */     /* send/recv pattern->ptr for rowCoupleBlock */
1913     num_RAPext_rows = offsetInShared[num_neighbors];     num_RAPext_rows = offsetInShared[num_neighbors];
# Line 2041  Paso_SystemMatrix* Paso_Preconditioner_A Line 2040  Paso_SystemMatrix* Paso_Preconditioner_A
2040     Paso_SystemMatrix *out=NULL;     Paso_SystemMatrix *out=NULL;
2041     paso::SystemMatrixPattern *pattern=NULL;     paso::SystemMatrixPattern *pattern=NULL;
2042     paso::Distribution_ptr input_dist, output_dist;     paso::Distribution_ptr input_dist, output_dist;
2043     Paso_SharedComponents *send =NULL, *recv=NULL;     paso::SharedComponents_ptr send, recv;
2044     paso::Connector *col_connector=NULL, *row_connector=NULL;     paso::Connector *col_connector=NULL, *row_connector=NULL;
2045     paso::Pattern *main_pattern=NULL;     paso::Pattern *main_pattern=NULL;
2046     paso::Pattern *col_couple_pattern=NULL, *row_couple_pattern =NULL;     paso::Pattern *col_couple_pattern=NULL, *row_couple_pattern =NULL;
# Line 3171  Paso_SystemMatrix* Paso_Preconditioner_A Line 3170  Paso_SystemMatrix* Paso_Preconditioner_A
3170       num_neighbors ++;       num_neighbors ++;
3171       offsetInShared[num_neighbors] = i;       offsetInShared[num_neighbors] = i;
3172     }     }
3173     recv = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,     recv.reset(new paso::SharedComponents(num_Pmain_cols, num_neighbors,
3174              neighbor, shared, offsetInShared, 1, 0, mpi_info);                 neighbor, shared, offsetInShared, 1, 0, mpi_info));
3175    
3176     #ifdef ESYS_MPI     #ifdef ESYS_MPI
3177     MPI_Alltoall(recv_len, 1, MPI_INT, send_len, 1, MPI_INT, mpi_info->comm);     MPI_Alltoall(recv_len, 1, MPI_INT, send_len, 1, MPI_INT, mpi_info->comm);
# Line 3225  Paso_SystemMatrix* Paso_Preconditioner_A Line 3224  Paso_SystemMatrix* Paso_Preconditioner_A
3224     j = offsetInShared[num_neighbors];     j = offsetInShared[num_neighbors];
3225     offset = dist[rank];     offset = dist[rank];
3226     for (i=0; i<j; i++) shared[i] = shared[i] - offset;     for (i=0; i<j; i++) shared[i] = shared[i] - offset;
3227     send = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,     send.reset(new paso::SharedComponents(num_Pmain_cols, num_neighbors,
3228              neighbor, shared, offsetInShared, 1, 0, mpi_info);                 neighbor, shared, offsetInShared, 1, 0, mpi_info));
3229    
3230     col_connector = paso::Connector_alloc(send, recv);     col_connector = paso::Connector_alloc(send, recv);
3231     delete[] shared;     delete[] shared;
    Paso_SharedComponents_free(recv);  
    Paso_SharedComponents_free(send);  
3232    
3233     /* now, create row distribution (output_distri) and col     /* now, create row distribution (output_distri) and col
3234        distribution (input_distribution) */        distribution (input_distribution) */
# Line 3299  Paso_SystemMatrix* Paso_Preconditioner_A Line 3296  Paso_SystemMatrix* Paso_Preconditioner_A
3296      offsetInShared[num_neighbors] = k;      offsetInShared[num_neighbors] = k;
3297       }       }
3298     }     }
3299     send = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,     send.reset(new paso::SharedComponents(num_Pmain_cols, num_neighbors,
3300                          neighbor, shared, offsetInShared, 1, 0, mpi_info);                 neighbor, shared, offsetInShared, 1, 0, mpi_info));
3301    
3302     /* send/recv number of rows will be sent from current proc     /* send/recv number of rows will be sent from current proc
3303        recover info for the receiver of row_connector from the sender */        recover info for the receiver of row_connector from the sender */
# Line 3325  Paso_SystemMatrix* Paso_Preconditioner_A Line 3322  Paso_SystemMatrix* Paso_Preconditioner_A
3322     for (i=0; i<k; i++) {     for (i=0; i<k; i++) {
3323       shared[i] = i + num_Pmain_cols;       shared[i] = i + num_Pmain_cols;
3324     }     }
3325     recv = Paso_SharedComponents_alloc(num_Pmain_cols, num_neighbors,     recv.reset(new paso::SharedComponents(num_Pmain_cols, num_neighbors,
3326                          neighbor, shared, offsetInShared, 1, 0, mpi_info);                 neighbor, shared, offsetInShared, 1, 0, mpi_info));
3327     row_connector = paso::Connector_alloc(send, recv);     row_connector = paso::Connector_alloc(send, recv);
3328     delete[] shared;     delete[] shared;
    Paso_SharedComponents_free(recv);  
    Paso_SharedComponents_free(send);  
3329    
3330     /* send/recv pattern->ptr for rowCoupleBlock */     /* send/recv pattern->ptr for rowCoupleBlock */
3331     num_RAPext_rows = offsetInShared[num_neighbors];     num_RAPext_rows = offsetInShared[num_neighbors];

Legend:
Removed from v.4814  
changed lines
  Added in v.4816

  ViewVC Help
Powered by ViewVC 1.1.26