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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1089 - (show annotations)
Thu Apr 12 22:41:39 2007 UTC (12 years, 4 months ago) by gross
File MIME type: text/plain
File size: 4653 byte(s)
a missing file
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_makeHops : sets the hop vector to hand over to Pattern object` */
17
18 /**************************************************************/
19
20 /* Copyrights by ACcESS Australia 2003, 2004,2005, 2006, 2007 */
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 void Paso_SystemMatrixPattern_makeHops(int type,
33 Paso_Distribution* distribution,
34 index_t* ptr,
35 index_t* index,
36 dim_t* numHops,
37 index_t **hop) {
38 dim_t i, p, j, d, *mask=NULL, *mask_g=NULL, r;
39 register dim_t itmp;
40 Paso_MPIInfo* mpi_info=distribution->mpi_info;
41 dim_t s=mpi_info->size;
42 dim_t myProc=mpi_info->rank;
43 dim_t myN=distribution->myNumComponents;
44 *numHops=0;
45 *hop=MEMALLOC(s,index_t);
46 if (Paso_checkPtr(*hop)) return;
47 if (s < 2) {
48 *numHops=1;
49 *hop[0]=1;
50 } else {
51 #ifdef PASO_MPI
52 mask=TMPMEMALLOC(s,index_t);
53 mask_g=TMPMEMALLOC(s,index_t);
54 if (Paso_checkPtr(mask) || Paso_checkPtr(mask_g)) {
55 MEMFREE(*hop);
56 } else {
57 for (i=0;i<s;++i) {
58 mask[i]=0;
59 (*hop)[i]=0;
60 }
61 mask[0]=1;
62 if (type & PATTERN_FORMAT_OFFSET1) {
63 #pragma omp parallel private(p,i,j,itmp,r)
64 {
65 for (p=0; p<s; ++p) {
66 r=0;
67 #pragma omp for schedule(static)
68 for (i=0;i<myN;++i) {
69 for (j=ptr[i]; j<ptr[i+1]; ++j) {
70 itmp=index[j];
71 if ( (distribution->first_component[p]<itmp) &&
72 (itmp<=distribution->first_component[p+1]) ) {
73 r=1;
74 break;
75 }
76 }
77 }
78 #pragma omp critical
79 {
80 mask[PASO_MPI_mod(p-myProc,s)]=MAX(mask[PASO_MPI_mod(p-myProc,s)],r);
81 }
82 }
83 }
84 } else {
85 #pragma omp parallel private(p,i,j,itmp,r)
86 {
87 for (p=0; p<s; ++p) {
88 r=0;
89 #pragma omp for schedule(static)
90 for (i=0;i<myN;++i) {
91 for (j=ptr[i]; j<ptr[i+1]; ++j) {
92 itmp=index[j];
93 if ( (distribution->first_component[p]<=itmp) &&
94 (itmp<distribution->first_component[p+1]) ) {
95 r=1;
96 break;
97 }
98 }
99 }
100 #pragma omp critical
101 {
102 mask[PASO_MPI_mod(p-myProc,s)]=MAX(mask[PASO_MPI_mod(p-myProc,s)],r);
103 }
104 }
105 }
106 }
107 /* make global*/
108 MPI_Allreduce(mask, mask_g, s, MPI_INT, MPI_MAX, mpi_info->comm);
109 /* get the hops now */
110 *numHops=1;
111 (*hop)[0]=1;
112 for (d=1; d<s; ++d) {
113 if (mask_g[d]==1) {
114 (*hop)[*numHops]=1;
115 (*numHops)++;
116 } else {
117 (*hop)[*numHops-1]++;
118 }
119 }
120 { int q;
121 printf("ksteube: %d hops :", *numHops);
122 for (q=0;q<*numHops;++q) printf(" %d",(*hop)[q]);
123 printf("\n");
124 }
125 }
126 TMPMEMFREE(mask);
127 TMPMEMFREE(mask_g);
128 #else
129 *numHops=1;
130 (*hop)[0]=1;
131 #endif
132 }
133 }

  ViewVC Help
Powered by ViewVC 1.1.26