--- trunk/esys2/finley/src/finleyC/IndexList.c 2005/07/08 04:08:13 123 +++ trunk/finley/src/IndexList.c 2008/08/22 04:20:30 1722 @@ -1,66 +1,129 @@ -/* \$Id\$ */ -/**************************************************************/ +/* \$Id\$ */ -/* Finley: Converting an element list into a matrix shape */ +/******************************************************* + * + * Copyright 2003-2007 by ACceSS MNRF + * Copyright 2007 by University of Queensland + * + * http://esscc.uq.edu.au + * Primary Business: Queensland, Australia + * Licensed under the Open Software License version 3.0 + * http://www.opensource.org/licenses/osl-3.0.php + * + *******************************************************/ /**************************************************************/ -/* Copyrights by ACcESS Australia 2003,2004 */ -/* Author: gross@access.edu.au */ +/* Finley: Converting an element list into a matrix shape */ /**************************************************************/ -#include "Finley.h" -#include "ElementFile.h" -#include "System.h" #include "IndexList.h" +/* Translate from distributed/local array indices to global indices */ + /**************************************************************/ /* inserts the contributions from the element matrices of elements into the row index col. If symmetric is set, only the upper triangle of the matrix is stored. */ void Finley_IndexList_insertElements(Finley_IndexList* index_list, Finley_ElementFile* elements, - bool_t reduce_row_order, index_t* row_Label, - bool_t reduce_col_order, index_t* col_Label) { - index_t color; - dim_t e,kr,kc,NN_row,NN_col,i,icol,irow; - + bool_t reduce_row_order, index_t* row_map, + bool_t reduce_col_order, index_t* col_map) { + /* index_list is an array of linked lists. Each entry is a row (DOF) and contains the indices to the non-zero columns */ + index_t color, *id=NULL; + dim_t e,kr,kc,NN_row,NN_col,i,icol,irow, NN, *row_node=NULL,*col_node=NULL; if (elements!=NULL) { - dim_t NN=elements->ReferenceElement->Type->numNodes; - index_t id[NN],*row_node,*col_node; - for (i=0;iReferenceElement->Type->linearNodes; - NN_col=elements->LinearReferenceElement->Type->numNodes; - } else { - col_node=id; - NN_col=elements->ReferenceElement->Type->numNodes; + NN=elements->numNodes; + id=TMPMEMALLOC(NN, index_t); + if (! Finley_checkPtr(id) ) { + for (i=0;iReferenceElement->Type->linearNodes; + NN_col=elements->LinearReferenceElement->Type->numNodes; + } else { + col_node=id; + NN_col=elements->ReferenceElement->Type->numNodes; + } + if (reduce_row_order) { + row_node=elements->ReferenceElement->Type->linearNodes; + NN_row=elements->LinearReferenceElement->Type->numNodes; + } else { + row_node=id; + NN_row=elements->ReferenceElement->Type->numNodes; + } + for (color=elements->minColor;color<=elements->maxColor;color++) { + #pragma omp for private(e,irow,kr,kc,icol) schedule(static) + for (e=0;enumElements;e++) { + if (elements->Color[e]==color) { + for (kr=0;krNodes[INDEX2(row_node[kr],e,NN)]]; + for (kc=0;kcNodes[INDEX2(col_node[kc],e,NN)]]; + Finley_IndexList_insertIndex(&(index_list[irow]),icol); + } + } + } + } + } + TMPMEMFREE(id); } - if (reduce_row_order) { - row_node=elements->ReferenceElement->Type->linearNodes; - NN_row=elements->LinearReferenceElement->Type->numNodes; - } else { - row_node=id; - NN_row=elements->ReferenceElement->Type->numNodes; + } + return; +} + +void Finley_IndexList_insertElementsWithRowRange(Finley_IndexList* index_list, index_t firstRow, index_t lastRow, + Finley_ElementFile* elements, index_t* row_map, index_t* col_map) +{ + index_t color; + dim_t e,kr,kc,icol,irow, NN; + if (elements!=NULL) { + NN=elements->numNodes; + for (color=elements->minColor;color<=elements->maxColor;color++) { + #pragma omp for private(e,irow,kr,kc,icol) schedule(static) + for (e=0;enumElements;e++) { + if (elements->Color[e]==color) { + for (kr=0;krNodes[INDEX2(kr,e,NN)]]; + if ((firstRow<=irow) && (irow < lastRow)) { + irow-=firstRow; + for (kc=0;kcNodes[INDEX2(kc,e,NN)]]; + Finley_IndexList_insertIndex(&(index_list[irow]),icol); + } + } + } + } + } } + } +} +void Finley_IndexList_insertElementsWithRowRangeNoMainDiagonal(Finley_IndexList* index_list, index_t firstRow, index_t lastRow, + Finley_ElementFile* elements, index_t* row_map, index_t* col_map) +{ + index_t color; + dim_t e,kr,kc,icol,irow, NN,irow_loc; + if (elements!=NULL) { + NN=elements->numNodes; for (color=elements->minColor;color<=elements->maxColor;color++) { - #pragma omp for private(e,irow,kr,kc,icol) schedule(static) - for (e=0;enumElements;e++) { - if (elements->Color[e]==color) { - for (kr=0;krNodes[INDEX2(row_node[kr],e,NN)]]; - for (kc=0;kcNodes[INDEX2(col_node[kc],e,NN)]]; - Finley_IndexList_insertIndex(&(index_list[irow]),icol); + #pragma omp for private(e,irow,kr,kc,icol,irow_loc) schedule(static) + for (e=0;enumElements;e++) { + if (elements->Color[e]==color) { + for (kr=0;krNodes[INDEX2(kr,e,NN)]]; + if ((firstRow<=irow) && (irow < lastRow)) { + irow_loc=irow-firstRow; + for (kc=0;kcNodes[INDEX2(kc,e,NN)]]; + if (icol != irow) Finley_IndexList_insertIndex(&(index_list[irow_loc]),icol); + } + } } - } - } - } - } + } + } + } } - return; } /* inserts row index row into the Finley_IndexList in if it does not exist */ @@ -90,21 +153,37 @@ /* counts the number of row indices in the Finley_IndexList in */ -dim_t Finley_IndexList_count(Finley_IndexList* in) { +dim_t Finley_IndexList_count(Finley_IndexList* in, index_t range_min,index_t range_max) { + dim_t i; + dim_t out=0; + register index_t itmp; if (in==NULL) { return 0; } else { - return (in->n)+Finley_IndexList_count(in->extension); + for (i=0;in;i++) { + itmp=in->index[i]; + if ((itmp>=range_min) && (range_max>itmp)) ++out; + } + return out+Finley_IndexList_count(in->extension, range_min,range_max); } } /* count the number of row indices in the Finley_IndexList in */ -void Finley_IndexList_toArray(Finley_IndexList* in, index_t* array) { - dim_t i; +void Finley_IndexList_toArray(Finley_IndexList* in, index_t* array, index_t range_min,index_t range_max, index_t index_offset) { + dim_t i, ptr; + register index_t itmp; if (in!=NULL) { - for (i=0;in;i++) array[i]=in->index[i]+INDEX_OFFSET; - Finley_IndexList_toArray(in->extension,&(array[in->n])); + ptr=0; + for (i=0;in;i++) { + itmp=in->index[i]; + if ((itmp>=range_min) && (range_max>itmp)) { + array[ptr]=itmp+index_offset; + ptr++; + } + + } + Finley_IndexList_toArray(in->extension,&(array[ptr]), range_min, range_max, index_offset); } } @@ -117,19 +196,43 @@ } } -/* - * \$Log\$ - * Revision 1.5 2005/07/08 04:07:51 jgs - * Merge of development branch back to main trunk on 2005-07-08 - * - * Revision 1.4 2004/12/15 07:08:32 jgs - * *** empty log message *** - * Revision 1.1.1.1.2.3 2005/06/29 02:34:50 gross - * some changes towards 64 integers in finley - * - * Revision 1.1.1.1.2.2 2004/11/24 01:37:13 gross - * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now - * - * - * - */ +/* creates a Paso_pattern from a range of indices */ +Paso_Pattern* Finley_IndexList_createPattern(dim_t n0, dim_t n,Finley_IndexList* index_list,index_t range_min,index_t range_max,index_t index_offset) +{ + dim_t *ptr=NULL; + register dim_t s,i,itmp; + index_t *index=NULL; + Paso_Pattern* out=NULL; + + ptr=MEMALLOC(n+1-n0,index_t); + if (! Finley_checkPtr(ptr) ) { + /* get the number of connections per row */ + #pragma omp parallel for schedule(static) private(i) + for(i=n0;i