Newer
Older
Kurt A. O'Hearn
committed
switch ( side )
{
case LEFT:
switch ( control->cm_solver_pre_app_type )
{
case TRI_SOLVE_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
Kurt A. O'Hearn
committed
dual_jacobi_app( workspace->Hdia_inv, y, x, system->n );
Kurt A. O'Hearn
committed
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve( workspace->L, y, x, workspace->L->n, LOWER );
// break;
case SAI_PC:
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, H->NT, x );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, system->n, x );
Kurt A. O'Hearn
committed
#endif
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_LEVEL_SCHED_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
Kurt A. O'Hearn
committed
dual_jacobi_app( workspace->Hdia_inv, y, x, system->n );
Kurt A. O'Hearn
committed
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->L, y, x, workspace->L->n, LOWER, fresh_pre );
// break;
case SAI_PC:
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, H->NT, x );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, system->n, x );
Kurt A. O'Hearn
committed
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
#endif
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_GC_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// for ( i = 0; i < workspace->H->n; ++i )
// {
// workspace->y_p[i] = y[i];
// }
//
// permute_vector( workspace, workspace->y_p, workspace->H->n, FALSE, LOWER );
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->L, workspace->y_p, x, workspace->L->n, LOWER, fresh_pre );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case JACOBI_ITER_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// // construct D^{-1}_L
// if ( fresh_pre == TRUE )
// {
// for ( i = 0; i < workspace->L->n; ++i )
// {
// si = workspace->L->start[i + 1] - 1;
// workspace->Dinv_L[i] = 1.0 / workspace->L->val[si];
// }
// }
//
// jacobi_iter( workspace, workspace->L, workspace->Dinv_L,
// y, x, LOWER, control->cm_solver_pre_app_jacobi_iters );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case RIGHT:
switch ( control->cm_solver_pre_app_type )
{
case TRI_SOLVE_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
if ( x != y )
{
Kurt A. O'Hearn
committed
Vector_Copy_rvec2( x, y, system->n );
Kurt A. O'Hearn
committed
}
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve( workspace->U, y, x, workspace->U->n, UPPER );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_LEVEL_SCHED_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
if ( x != y )
{
Kurt A. O'Hearn
committed
Vector_Copy_rvec2( x, y, system->n );
Kurt A. O'Hearn
committed
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
}
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->U, y, x, workspace->U->n, UPPER, fresh_pre );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_GC_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->U, y, x, workspace->U->n, UPPER, fresh_pre );
// permute_vector( workspace, x, workspace->H->n, TRUE, UPPER );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case JACOBI_ITER_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// if ( fresh_pre == TRUE )
// {
// for ( i = 0; i < workspace->U->n; ++i )
// {
// si = workspace->U->start[i];
// workspace->Dinv_U[i] = 1.0 / workspace->U->val[si];
// }
// }
//
// jacobi_iter( workspace, workspace->U, workspace->Dinv_U,
// y, x, UPPER, control->cm_solver_pre_app_jacobi_iters );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
}
}
}
Kurt A. O'Hearn
committed
/* Apply left-sided preconditioning while solving M^{-1}Ax = M^{-1}b
*
* system:
* workspace: data struct containing matrices and vectors, stored in CSR
* control: data struct containing parameters
* data: struct containing timing simulation data (including performance data)
* y: vector to which to apply preconditioning,
* specific to internals of iterative solver being used
* x (output): preconditioned vector
* fresh_pre: parameter indicating if this is a newly computed (fresh) preconditioner
* side: used in determining how to apply preconditioner if the preconditioner is
* factorized as M = M_{1}M_{2} (e.g., incomplete LU, A \approx LU)
*
* Assumptions:
* Matrices have non-zero diagonals
* Each row of a matrix has at least one non-zero (i.e., no rows with all zeros) */
static void apply_preconditioner( reax_system const * const system,
storage const * const workspace, control_params const * const control,
simulation_data * const data, mpi_datatypes * const mpi_data,
real const * const y, real * const x, int fresh_pre, int side )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
// int i, si;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
/* no preconditioning */
Kurt A. O'Hearn
committed
if ( control->cm_solver_pre_comp_type == NONE_PC )
{
Kurt A. O'Hearn
committed
if ( x != y )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
Vector_Copy( x, y, system->n );
Kurt A. O'Hearn
committed
}
}
Kurt A. O'Hearn
committed
else
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
switch ( side )
{
case LEFT:
switch ( control->cm_solver_pre_app_type )
{
case TRI_SOLVE_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
jacobi_app( workspace->Hdia_inv, y, x, system->n );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve( workspace->L, y, x, workspace->L->n, LOWER );
// break;
case SAI_PC:
Kurt A. O'Hearn
committed
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, H->NT, x );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, system->n, x );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_LEVEL_SCHED_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
jacobi_app( workspace->Hdia_inv, y, x, system->n );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->L, y, x, workspace->L->n, LOWER, fresh_pre );
// break;
case SAI_PC:
#if defined(NEUTRAL_TERRITORY)
Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, H->NT, x );
#else
Sparse_MatVec( system, control, data, mpi_data, &workspace->H_app_inv,
y, system->n, x );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_GC_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// for ( i = 0; i < workspace->H->n; ++i )
// {
// workspace->y_p[i] = y[i];
// }
//
// permute_vector( workspace, workspace->y_p, workspace->H->n, FALSE, LOWER );
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->L, workspace->y_p, x, workspace->L->n, LOWER, fresh_pre );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case JACOBI_ITER_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// // construct D^{-1}_L
// if ( fresh_pre == TRUE )
// {
// for ( i = 0; i < workspace->L->n; ++i )
// {
// si = workspace->L->start[i + 1] - 1;
// workspace->Dinv_L[i] = 1.0 / workspace->L->val[si];
// }
// }
//
// jacobi_iter( workspace, workspace->L, workspace->Dinv_L,
// y, x, LOWER, control->cm_solver_pre_app_jacobi_iters );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
}
break;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
case RIGHT:
switch ( control->cm_solver_pre_app_type )
{
case TRI_SOLVE_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
if ( x != y )
{
Vector_Copy( x, y, system->n );
}
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve( workspace->U, y, x, workspace->U->n, UPPER );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_LEVEL_SCHED_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
if ( x != y )
{
Vector_Copy( x, y, system->n );
}
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->U, y, x, workspace->U->n, UPPER, fresh_pre );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case TRI_SOLVE_GC_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// tri_solve_level_sched( (static_storage *) workspace,
// workspace->U, y, x, workspace->U->n, UPPER, fresh_pre );
// permute_vector( workspace, x, workspace->H->n, TRUE, UPPER );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
case JACOBI_ITER_PA:
switch ( control->cm_solver_pre_comp_type )
{
case JACOBI_PC:
case SAI_PC:
fprintf( stderr, "Unsupported preconditioner computation/application method combination. Terminating...\n" );
exit( INVALID_INPUT );
break;
// case ICHOLT_PC:
// case ILUT_PC:
// case ILUTP_PC:
// if ( fresh_pre == TRUE )
// {
// for ( i = 0; i < workspace->U->n; ++i )
// {
// si = workspace->U->start[i];
// workspace->Dinv_U[i] = 1.0 / workspace->U->val[si];
// }
// }
//
// jacobi_iter( workspace, workspace->U, workspace->Dinv_U,
// y, x, UPPER, control->cm_solver_pre_app_jacobi_iters );
// break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
}
break;
default:
fprintf( stderr, "Unrecognized preconditioner application method. Terminating...\n" );
exit( INVALID_INPUT );
break;
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
}
break;
}
}
}
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
/* Steepest Descent
* This function performs dual iteration for QEq (2 simultaneous solves)
* */
int dual_SDM( reax_system const * const system, control_params const * const control,
simulation_data * const data, storage * const workspace,
sparse_matrix * const H, rvec2 * const b, real tol,
rvec2 * const x, mpi_datatypes * const mpi_data, int fresh_pre )
{
int i, j, ret;
rvec2 tmp, alpha, bnorm, sig;
real redux[4];
#if defined(LOG_PERFORMANCE)
real time;
#endif
#if defined(NEUTRAL_TERRITORY)
Dual_Sparse_MatVec( system, control, data, mpi_data, H, x,
H->NT, workspace->q2 );
#else
Dual_Sparse_MatVec( system, control, data, mpi_data, H, x,
system->N, workspace->q2 );
#endif
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
#endif
Vector_Sum_rvec2( workspace->r2, 1.0, 1.0, b,
-1.0, -1.0, workspace->q2, system->n );
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r2,
workspace->q2, fresh_pre, LEFT );
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q2,
workspace->d2, fresh_pre, RIGHT );
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
#endif
Dot_local_rvec2( b, b, system->n, &redux[0], &redux[1] );
Dot_local_rvec2( workspace->r2, workspace->d2, system->n, &redux[2], &redux[3] );
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 4, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
bnorm[0] = SQRT( redux[0] );
bnorm[1] = SQRT( redux[1] );
sig[0] = redux[2];
sig[1] = redux[3];
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
#endif
for ( i = 0; i < control->cm_solver_max_iters; ++i )
{
if ( SQRT(sig[0]) / bnorm[0] <= tol || SQRT(sig[1]) / bnorm[1] <= tol )
{
break;
}
#if defined(NEUTRAL_TERRITORY)
Dual_Sparse_MatVec( system, control, data, mpi_data, H, workspace->d2,
H->NT, workspace->q2 );
#else
Dual_Sparse_MatVec( system, control, data, mpi_data, H, workspace->d2,
system->N, workspace->q2 );
#endif
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
#endif
Dot_local_rvec2( workspace->r2, workspace->d2, system->n, &redux[0], &redux[1] );
Dot_local_rvec2( workspace->d2, workspace->q2, system->n, &redux[2], &redux[3] );
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 4, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
#endif
sig[0] = redux[0];
sig[1] = redux[1];
tmp[0] = redux[2];
tmp[1] = redux[3];
alpha[0] = sig[0] / tmp[0];
alpha[1] = sig[1] / tmp[1];
Vector_Add_rvec2( x, alpha[0], alpha[1], workspace->d2, system->n );
Vector_Add_rvec2( workspace->r2,
-1.0 * alpha[0], -1.0 * alpha[1], workspace->q2, system->n );
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r2,
workspace->q2, FALSE, LEFT );
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q2,
workspace->d2, FALSE, RIGHT );
}
/* continue to solve the system that has not converged yet */
if ( sig[0] / bnorm[0] > tol )
{
Vector_Copy_From_rvec2( workspace->s, workspace->x, 0, system->n );
i += SDM( system, control, data, workspace,
H, workspace->b_s, tol, workspace->s, mpi_data, FALSE );
Vector_Copy_To_rvec2( workspace->x, workspace->s, 0, system->n );
}
else if ( sig[1] / bnorm[1] > tol )
{
Vector_Copy_From_rvec2( workspace->t, workspace->x, 1, system->n );
i += SDM( system, control, data, workspace,
H, workspace->b_t, tol, workspace->t, mpi_data, FALSE );
Vector_Copy_To_rvec2( workspace->x, workspace->t, 1, system->n );
}
if ( i >= control->cm_solver_max_iters && system->my_rank == MASTER_NODE )
{
fprintf( stderr, "[WARNING] SDM convergence failed (%d iters)\n", i );
fprintf( stderr, " [INFO] Rel. residual error (s solve): %f\n", SQRT(sig[0]) / bnorm[0] );
fprintf( stderr, " [INFO] Rel. residual error (t solve): %f\n", SQRT(sig[1]) / bnorm[1] );
return i;
}
return i;
}
Kurt A. O'Hearn
committed
/* Steepest Descent */
int SDM( reax_system const * const system, control_params const * const control,
simulation_data * const data, storage * const workspace,
sparse_matrix * const H, real * const b, real tol,
real * const x, mpi_datatypes * const mpi_data, int fresh_pre )
{
int i, j, ret;
real tmp, alpha, bnorm, sig;
real redux[2];
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
real time;
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Sparse_MatVec( system, control, data, mpi_data, H, x,
H->NT, workspace->q );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
Sparse_MatVec( system, control, data, mpi_data, H, x,
system->N, workspace->q );
#endif
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
#endif
Vector_Sum( workspace->r, 1.0, b, -1.0, workspace->q, system->n );
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r,
workspace->q, fresh_pre, LEFT );
apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q,
workspace->d, fresh_pre, RIGHT );
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
redux[0] = Dot_local( b, b, system->n );
redux[1] = Dot_local( workspace->r, workspace->d, system->n );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 2, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
bnorm = SQRT( redux[0] );
sig = redux[1];
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
#endif
for ( i = 0; i < control->cm_solver_max_iters && SQRT(sig) / bnorm > tol; ++i )
{
#if defined(NEUTRAL_TERRITORY)
Sparse_MatVec( system, control, data, mpi_data, H, workspace->d,
H->NT, workspace->q );
#else
Sparse_MatVec( system, control, data, mpi_data, H, workspace->d,
system->N, workspace->q );
#endif
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
redux[0] = Dot_local( workspace->r, workspace->d, system->n );
redux[1] = Dot_local( workspace->d, workspace->q, system->n );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 2, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
#endif
Kurt A. O'Hearn
committed
sig = redux[0];
tmp = redux[1];
alpha = sig / tmp;
Vector_Add( x, alpha, workspace->d, system->n );
Kurt A. O'Hearn
committed
Vector_Add( workspace->r, -1.0 * alpha, workspace->q, system->n );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r,
workspace->q, FALSE, LEFT );
apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q,
workspace->d, FALSE, RIGHT );
Kurt A. O'Hearn
committed
}
if ( i >= control->cm_solver_max_iters && system->my_rank == MASTER_NODE )
{
fprintf( stderr, "[WARNING] SDM convergence failed (%d iters)\n", i );
fprintf( stderr, " [INFO] Rel. residual error: %f\n", SQRT(sig) / bnorm );
return i;
}
return i;
}
/* Dual iteration of the Preconditioned Conjugate Gradient Method
* for QEq (2 simultaneous solves) */
Kurt A. O'Hearn
committed
int dual_CG( reax_system const * const system, control_params const * const control,
simulation_data * const data,
storage * const workspace, sparse_matrix * const H, rvec2 * const b,
Kurt A. O'Hearn
committed
real tol, rvec2 * const x, mpi_datatypes * const mpi_data, int fresh_pre )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
int i, j, ret;
Kurt A. O'Hearn
committed
rvec2 tmp, alpha, beta, r_norm, b_norm, sig_old, sig_new;
Kurt A. O'Hearn
committed
real redux[6];
#if defined(LOG_PERFORMANCE)
real time;
#endif
Kurt A. O'Hearn
committed
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, H, x,
H->NT, workspace->q2 );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, H, x,
system->N, workspace->q2 );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
Vector_Sum_rvec2( workspace->r2, 1.0, 1.0, b, -1.0, -1.0, workspace->q2, system->n );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r2,
workspace->q2, fresh_pre, LEFT );
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q2,
workspace->d2, fresh_pre, RIGHT );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
for ( j = 0; j < 6; ++j )
{
Kurt A. O'Hearn
committed
redux[j] = 0.0;
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
Dot_local_rvec2( workspace->r2, workspace->d2, system->n, &redux[0], &redux[1] );
Dot_local_rvec2( workspace->d2, workspace->d2, system->n, &redux[2], &redux[3] );
Dot_local_rvec2( b, b, system->n, &redux[4], &redux[5] );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 6, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
Kurt A. O'Hearn
committed
sig_new[0] = redux[0];
sig_new[1] = redux[1];
Kurt A. O'Hearn
committed
r_norm[0] = SQRT( redux[2] );
r_norm[1] = SQRT( redux[3] );
b_norm[0] = SQRT( redux[4] );
b_norm[1] = SQRT( redux[5] );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
#endif
Kurt A. O'Hearn
committed
for ( i = 0; i < control->cm_solver_max_iters; ++i )
{
Kurt A. O'Hearn
committed
if ( r_norm[0] / b_norm[0] <= tol || r_norm[1] / b_norm[1] <= tol )
Kurt A. O'Hearn
committed
{
break;
}
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, H, workspace->d2,
H->NT, workspace->q2 );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
Dual_Sparse_MatVec( system, control, data, mpi_data, H, workspace->d2,
system->N, workspace->q2 );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
redux[0] = 0.0;
redux[1] = 0.0;
Kurt A. O'Hearn
committed
Dot_local_rvec2( workspace->d2, workspace->q2, system->n, &redux[0], &redux[1] );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
ret = MPI_Allreduce( &redux, &tmp, 2, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
alpha[0] = sig_new[0] / tmp[0];
alpha[1] = sig_new[1] / tmp[1];
Vector_Add_rvec2( x, alpha[0], alpha[1], workspace->d2, system->n );
Vector_Add_rvec2( workspace->r2, -1.0 * alpha[0], -1.0 * alpha[1],
workspace->q2, system->n );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r2,
workspace->q2, FALSE, LEFT );
dual_apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q2,
workspace->p2, FALSE, RIGHT );
#if defined(LOG_PERFORMANCE)
time = Get_Time( );
#endif
Kurt A. O'Hearn
committed
redux[0] = 0.0;
redux[1] = 0.0;
redux[2] = 0.0;
redux[3] = 0.0;
Kurt A. O'Hearn
committed
Dot_local_rvec2( workspace->r2, workspace->p2, system->n, &redux[0], &redux[1] );
Dot_local_rvec2( workspace->p2, workspace->p2, system->n, &redux[2], &redux[3] );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 4, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_allreduce );
#endif
Kurt A. O'Hearn
committed
sig_old[0] = sig_new[0];
sig_old[1] = sig_new[1];
sig_new[0] = redux[0];
sig_new[1] = redux[1];
Kurt A. O'Hearn
committed
r_norm[0] = SQRT( redux[2] );
r_norm[1] = SQRT( redux[3] );
Kurt A. O'Hearn
committed
beta[0] = sig_new[0] / sig_old[0];
beta[1] = sig_new[1] / sig_old[1];
Kurt A. O'Hearn
committed
Vector_Sum_rvec2( workspace->d2, 1.0, 1.0, workspace->p2, beta[0], beta[1],
workspace->d2, system->n );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
}
/* continue to solve the system that has not converged yet */
Kurt A. O'Hearn
committed
if ( r_norm[0] / b_norm[0] > tol )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
Vector_Copy_From_rvec2( workspace->s, workspace->x, 0, system->n );
Kurt A. O'Hearn
committed
i += CG( system, control, data, workspace,
Kurt A. O'Hearn
committed
H, workspace->b_s, tol, workspace->s, mpi_data, FALSE );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
Vector_Copy_To_rvec2( workspace->x, workspace->s, 0, system->n );
Kurt A. O'Hearn
committed
}
Kurt A. O'Hearn
committed
else if ( r_norm[1] / b_norm[1] > tol )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
Vector_Copy_From_rvec2( workspace->t, workspace->x, 1, system->n );
Kurt A. O'Hearn
committed
i += CG( system, control, data, workspace,
Kurt A. O'Hearn
committed
H, workspace->b_t, tol, workspace->t, mpi_data, FALSE );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
Vector_Copy_To_rvec2( workspace->x, workspace->t, 1, system->n );
Kurt A. O'Hearn
committed
}
if ( i >= control->cm_solver_max_iters && system->my_rank == MASTER_NODE )
{
fprintf( stderr, "[WARNING] CG convergence failed!\n" );
return i;
}
return i;
}
/* Preconditioned Conjugate Gradient Method */
int CG( reax_system const * const system, control_params const * const control,
simulation_data * const data,
storage * const workspace, sparse_matrix * const H, real * const b,
Kurt A. O'Hearn
committed
real tol, real * const x, mpi_datatypes * const mpi_data, int fresh_pre )
Kurt A. O'Hearn
committed
{
Kurt A. O'Hearn
committed
int i, j, ret;
Kurt A. O'Hearn
committed
real tmp, alpha, beta, r_norm, b_norm;
Kurt A. O'Hearn
committed
real sig_old, sig_new;
Kurt A. O'Hearn
committed
real redux[3];
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
real time;
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
#if defined(NEUTRAL_TERRITORY)
Kurt A. O'Hearn
committed
Sparse_MatVec( system, control, data, mpi_data, H, x,
H->NT, workspace->q );
Kurt A. O'Hearn
committed
#else
Kurt A. O'Hearn
committed
Sparse_MatVec( system, control, data, mpi_data, H, x,
system->N, workspace->q );
Kurt A. O'Hearn
committed
#endif
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
Vector_Sum( workspace->r, 1.0, b, -1.0, workspace->q, system->n );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
apply_preconditioner( system, workspace, control, data, mpi_data, workspace->r,
workspace->q, fresh_pre, LEFT );
apply_preconditioner( system, workspace, control, data, mpi_data, workspace->q,
workspace->d, fresh_pre, RIGHT );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Kurt A. O'Hearn
committed
time = Get_Time( );
Kurt A. O'Hearn
committed
#endif
Kurt A. O'Hearn
committed
redux[0] = Dot_local( workspace->r, workspace->d, system->n );
Kurt A. O'Hearn
committed
redux[1] = Dot_local( workspace->d, workspace->d, system->n );
Kurt A. O'Hearn
committed
redux[2] = Dot_local( b, b, system->n );
Kurt A. O'Hearn
committed
#if defined(LOG_PERFORMANCE)
Update_Timing_Info( &time, &data->timing.cm_solver_vector_ops );
#endif
Kurt A. O'Hearn
committed
ret = MPI_Allreduce( MPI_IN_PLACE, redux, 3, MPI_DOUBLE,
MPI_SUM, MPI_COMM_WORLD );
Check_MPI_Error( ret, __FILE__, __LINE__ );
Kurt A. O'Hearn
committed
Kurt A. O'Hearn
committed
sig_new = redux[0];
Kurt A. O'Hearn
committed
r_norm = SQRT( redux[1] );
b_norm = SQRT( redux[2] );