/[escript]/trunk-mpi-branch/paso/src/SystemMatrixPattern.c
ViewVC logotype

Contents of /trunk-mpi-branch/paso/src/SystemMatrixPattern.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1016 - (show annotations)
Thu Mar 8 06:31:28 2007 UTC (13 years, 11 months ago) by gross
File MIME type: text/plain
File size: 6576 byte(s)
MPI version compiles and starts to run now. 
Important:

   * the mpi library needs to be shared.
   * the path needs to be added to LD_LIBRARY path.

The program stucks in the matrix assemblage.


1 /* $Id$ */
2
3 /*
4 ********************************************************************************
5 * Copyright 2006 by ACcESS MNRF *
6 * *
7 * http://www.access.edu.au *
8 * Primary Business: Queensland, Australia *
9 * Licensed under the Open Software License version 3.0 *
10 * http://www.opensource.org/licenses/osl-3.0.php *
11 ********************************************************************************
12 */
13
14 /**************************************************************/
15
16 /* Paso: SystemMatrixPatternPattern */
17
18 /**************************************************************/
19
20 /* Copyrights by ACcESS Australia 2003, 2004,2005 */
21 /* Author: gross@access.edu.au */
22
23 /**************************************************************/
24
25 #include "Paso.h"
26 #include "SystemMatrixPattern.h"
27
28 /**************************************************************/
29
30 /* allocates a SystemMatrixPattern */
31
32 Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type,
33 Paso_Distribution* output_distribution,
34 Paso_Distribution* input_distribution,
35 index_t* ptr,
36 index_t* index) {
37 Paso_SystemMatrixPattern*out;
38 Paso_MPIInfo* mpi_info=output_distribution->mpi_info;
39 index_t index_offset=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);
40 index_t loc_min_index,loc_max_index,min_index=index_offset,max_index=index_offset-1;
41 dim_t i;
42 Paso_resetError();
43
44 if (input_distribution->mpi_info != output_distribution->mpi_info) {
45 Paso_setError(VALUE_ERROR,"row and column distribution must base on the same communicator.");
46 return NULL;
47 }
48
49 if (type & PATTERN_FORMAT_SYM) {
50 Paso_setError(TYPE_ERROR,"symmetric matrix pattern is not supported yet");
51 return NULL;
52 }
53 dim_t myNumOutput=output_distribution->myNumComponents;
54 #pragma omp parallel private(loc_min_index,loc_max_index,i)
55 {
56 loc_min_index=index_offset;
57 loc_max_index=index_offset-1;
58 if (type & PATTERN_FORMAT_OFFSET1) {
59 #pragma omp for schedule(static)
60 for (i=0;i<myNumOutput;++i) {
61 if (ptr[i]<ptr[i+1]) {
62 #ifdef USE_QSORTG
63 qsortG(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
64 #else
65 qsort(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
66 #endif
67 loc_min_index=MIN(loc_min_index,index[ptr[i]-1]);
68 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-2]);
69 }
70 }
71 } else {
72 #pragma omp for schedule(static)
73 for (i=0;i<myNumOutput;++i) {
74 if (ptr[i]<ptr[i+1]) {
75 #ifdef USE_QSORTG
76 qsortG(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
77 #else
78 qsort(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
79 #endif
80 loc_min_index=MIN(loc_min_index,index[ptr[i]]);
81 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-1]);
82 }
83 }
84 }
85 #pragma omp critical
86 {
87 min_index=MIN(loc_min_index,min_index);
88 max_index=MAX(loc_max_index,max_index);
89 }
90 }
91 #ifdef Paso_MPI
92 loc_min_index=min_index;
93 loc_max_index=max_index;
94 MPI_Reduce (&loc_max_index,&max_index,1,PASO_MPI_INT,MPI_MAX,mpi_info->comm)
95 MPI_Reduce (&loc_min_index,&min_index,1,PASO_MPI_INT,MPI_MIN,mpi_info->comm)
96 #endif
97 if (min_index<index_offset) {
98 Paso_setError(TYPE_ERROR,"Pattern index out of index offset range.");
99 return NULL;
100 }
101 if (min_index<input_distribution->firstComponent) {
102 Paso_setError(TYPE_ERROR,"Minimum pattern index out of input distribution range.");
103 return NULL;
104 }
105 if (input_distribution->firstComponent+input_distribution->numComponents <= max_index) {
106 Paso_setError(TYPE_ERROR,"Maximum pattern index out of input distribution range.");
107 return NULL;
108 }
109
110 out=MEMALLOC(1,Paso_SystemMatrixPattern);
111 if (Paso_checkPtr(out)) return NULL;
112 out->type=type;
113 out->reference_counter=1;
114 out->myNumOutput=myNumOutput;
115 out->numOutput=output_distribution->numComponents;
116 out->myNumInput=input_distribution->myNumComponents;
117 out->numInput=input_distribution->numComponents;
118
119 out->myLen=ptr[myNumOutput]-ptr[0];
120
121 out->ptr=ptr;
122 out->index=index;
123 out->input_distribution=Paso_Distribution_getReference(input_distribution);
124 out->output_distribution=Paso_Distribution_getReference(output_distribution);
125 out->mpi_info = Paso_MPIInfo_getReference(mpi_info);
126 printf("ksteube Paso_SystemMatrixPattern_alloc cpu=%d myNumOutput=%d\n", mpi_info->rank, myNumOutput);
127 #ifdef Paso_TRACE
128 printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n");
129 #endif
130 return out;
131 }
132
133 /* returns a reference to in */
134
135 Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_reference(Paso_SystemMatrixPattern* in) {
136 if (in!=NULL) {
137 ++(in->reference_counter);
138 }
139 return in;
140 }
141
142 /* deallocates a SystemMatrixPattern: */
143
144 void Paso_SystemMatrixPattern_dealloc(Paso_SystemMatrixPattern* in) {
145 if (in!=NULL) {
146 in->reference_counter--;
147 if (in->reference_counter<=0) {
148 Paso_Distribution_free(in->output_distribution);
149 Paso_Distribution_free(in->input_distribution);
150 Paso_MPIInfo_dealloc(in->mpi_info);
151 MEMFREE(in->ptr);
152 MEMFREE(in->index);
153 MEMFREE(in);
154 #ifdef Paso_TRACE
155 printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been deallocated.\n");
156 #endif
157 }
158 }
159 }
160 /* *************************************************************/
161
162 /* some routines which help to get the matrix pattern from elements: */
163
164 /* this routine is used by qsort called in Paso_SystemMatrixPattern_alloc */
165
166 int Paso_comparIndex(const void *index1,const void *index2){
167 index_t Iindex1,Iindex2;
168 Iindex1=*(index_t*)index1;
169 Iindex2=*(index_t*)index2;
170 if (Iindex1<Iindex2) {
171 return -1;
172 } else {
173 if (Iindex1>Iindex2) {
174 return 1;
175 } else {
176 return 0;
177 }
178 }
179 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26