35{
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175 char * Xptr = NULL, top;
176 Int Xcol, Xi, Xii, Xj, Xjj, Xld, Xnp, Xnq, Xrow, ctxt, dst, dist,
177 info, k, mycol, mydist, myrow, npcol, nprow, src, size;
178 double Xtmp, scale, ssq, temp1, temp2;
180
181
182
184 double work[4];
185
186
187
188
190#ifndef NO_ARGCHK
191
192
193
195 if( !( info = ( ( nprow == -1 ) ? -( 601 +
CTXT_ ) : 0 ) ) )
196 PB_Cchkvec( ctxt,
"PDZNRM2",
"X", *N, 1, Xi, Xj, Xd, *INCX, 6, &info );
197 if( info ) {
PB_Cabort( ctxt,
"PDZNRM2", info );
return; }
198#endif
199
200
201
203
204
205
206 if( *N == 0 ) return;
207
208
209
210#ifdef NO_ARGCHK
212#endif
213
214
215
216 PB_Cinfog2l( Xi, Xj, Xd, nprow, npcol, myrow, mycol, &Xii, &Xjj,
217 &Xrow, &Xcol );
218
219
220
221 if( ( *N == 1 ) && ( *INCX == 1 ) && ( Xd[
M_] == 1 ) )
222 {
223
224
225
226 if( ( ( myrow == Xrow ) || ( Xrow < 0 ) ) &&
227 ( ( mycol == Xcol ) || ( Xcol < 0 ) ) )
228 {
232 Xptr =
Mptr( ((
char *) X), Xii, Xjj, Xd[
LLD_], type->
size );
235 {
237 if( scale < temp1 )
238 {
239 temp2 = scale / temp1;
240 ssq =
ONE + ssq * ( temp2 * temp2 );
241 scale = temp1;
242 }
243 else
244 {
245 temp2 = temp1 / scale;
246 ssq = ssq + ( temp2 * temp2 );
247 }
248 }
251 {
253 if( scale < temp1 )
254 {
255 temp2 = scale / temp1;
256 ssq =
ONE + ssq * ( temp2 * temp2 );
257 scale = temp1;
258 }
259 else
260 {
261 temp2 = temp1 / scale;
262 ssq = ssq + ( temp2 * temp2 );
263 }
264 }
265
266
267
269 }
270 return;
271 }
272 else if( *INCX == Xd[
M_] )
273 {
274
275
276
277 if( ( myrow == Xrow ) || ( Xrow < 0 ) )
278 {
279
280
281
284
285
286
288 if( Xnq > 0 )
289 {
292 Xptr =
Mptr( ((
char *) X), Xii, Xjj, Xld, size );
293
294 for( k = 0; k < Xnq; k++ )
295 {
298 {
300 if( scale < temp1 )
301 {
302 temp2 = scale / temp1;
303 ssq =
ONE + ssq * ( temp2 * temp2 );
304 scale = temp1;
305 }
306 else
307 {
308 temp2 = temp1 / scale;
309 ssq = ssq + ( temp2 * temp2 );
310 }
311 }
314 {
316 if( scale < temp1 )
317 {
318 temp2 = scale / temp1;
319 ssq =
ONE + ssq * ( temp2 * temp2 );
320 scale = temp1;
321 }
322 else
323 {
324 temp2 = temp1 / scale;
325 ssq = ssq + ( temp2 * temp2 );
326 }
327 }
328 Xptr += Xld * size;
329 }
330 }
331
332
333
334 if( ( npcol >= 2 ) && ( Xcol >= 0 ) )
335 {
336
337
338
339
340 work[0] = scale;
341 work[1] = ssq;
342
343 mydist = mycol;
344 k = 1;
345l_10:
346 if( mydist & 1 )
347 {
348 dist = k * ( mydist - 1 );
350 Cdgesd2d( ctxt, 2, 1, ((
char*) work), 2, myrow, dst );
351 goto l_20;
352 }
353 else
354 {
355 dist = mycol + k;
357
358 if( mycol < src )
359 {
360 Cdgerv2d( ctxt, 2, 1, ((
char*)&work[2]), 2, myrow, src );
361 if( work[0] >= work[2] )
362 {
363 if( work[0] !=
ZERO )
364 {
365 temp1 = work[2] / work[0];
366 work[1] = work[1] + ( temp1 * temp1 ) * work[3];
367 }
368 }
369 else
370 {
371 temp1 = work[0] / work[2];
372 work[1] = work[3] + ( temp1 * temp1 ) * work[1];
373 work[0] = work[2];
374 }
375 }
376 mydist >>= 1;
377 }
378 k <<= 1;
379
380 if( k < npcol ) goto l_10;
381l_20:
382
383
384
385
387 if( mycol == 0 )
388 {
389 Cdgebs2d( ctxt,
ROW, &top, 2, 1, ((
char*)work), 2 );
390 }
391 else
392 {
394 myrow, 0 );
395 }
396
397
398
399 dasqrtb_( &work[0], &work[1], NORM2 );
400 }
401 else
402 {
403
404
405
407 }
408 }
409 return;
410 }
411 else
412 {
413
414
415
416 if( ( mycol == Xcol ) || ( Xcol < 0 ) )
417 {
418
419
420
423
424
425
427 if( Xnp > 0 )
428 {
430 Xptr =
Mptr( ((
char *) X), Xii, Xjj, Xd[
LLD_], size );
431
432 for( k = 0; k < Xnp; k++ )
433 {
436 {
438 if( scale < temp1 )
439 {
440 temp2 = scale / temp1;
441 ssq =
ONE + ssq * ( temp2 * temp2 );
442 scale = temp1;
443 }
444 else
445 {
446 temp2 = temp1 / scale;
447 ssq = ssq + ( temp2 * temp2 );
448 }
449 }
452 {
454 if( scale < temp1 )
455 {
456 temp2 = scale / temp1;
457 ssq =
ONE + ssq * ( temp2 * temp2 );
458 scale = temp1;
459 }
460 else
461 {
462 temp2 = temp1 / scale;
463 ssq = ssq + ( temp2 * temp2 );
464 }
465 }
466 Xptr += size;
467 }
468 }
469
470
471
472 if( ( nprow >= 2 ) && ( Xrow >= 0 ) )
473 {
474
475
476
477
478 work[0] = scale;
479 work[1] = ssq;
480
481 mydist = myrow;
482 k = 1;
483l_30:
484 if( mydist & 1 )
485 {
486 dist = k * ( mydist - 1 );
488 Cdgesd2d( ctxt, 2, 1, ((
char*)work), 2, dst, mycol );
489 goto l_40;
490 }
491 else
492 {
493 dist = myrow + k;
495
496 if( myrow < src )
497 {
498 Cdgerv2d( ctxt, 2, 1, ((
char*)&work[2]), 2, src, mycol );
499 if( work[0] >= work[2] )
500 {
501 if( work[0] !=
ZERO )
502 {
503 temp1 = work[2] / work[0];
504 work[1] = work[1] + ( temp1 * temp1 ) * work[3];
505 }
506 }
507 else
508 {
509 temp1 = work[0] / work[2];
510 work[1] = work[3] + ( temp1 * temp1 ) * work[1];
511 work[0] = work[2];
512 }
513 }
514 mydist >>= 1;
515 }
516 k <<= 1;
517
518 if( k < nprow ) goto l_30;
519l_40:
520
521
522
523
525 if( myrow == 0 )
526 {
528 }
529 else
530 {
532 0, mycol );
533 }
534
535
536
537 dasqrtb_( &work[0], &work[1], NORM2 );
538 }
539 else
540 {
541
542
543
545 }
546 }
547 return;
548 }
549
550
551
552}