Rev 2913 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2913 | fmk | 1 | /* This file is part of MUMPS VERSION 4.7.3 |
| 2 | This Version was built on Fri May 4 15:54:01 2007 |
||
| 3 | |||
| 4 | */ |
||
| 5 | /* $Id: c_example.c,v 1.1 2007-06-01 17:18:17 fmk Exp $ */ |
||
| 6 | /* Example program using the C interface to the |
||
| 7 | * double precision version of MUMPS, dmumps_c. |
||
| 8 | * We solve the system A x = RHS with |
||
| 9 | * A = diag(1 2) and RHS = [1 4]^T |
||
| 10 | * Solution is [1 2]^T */ |
||
| 11 | #include <stdio.h> |
||
| 12 | #include <mpi.h> |
||
| 13 | #include <dmumps_c.h> |
||
| 14 | #define JOB_INIT -1 |
||
| 15 | #define JOB_END -2 |
||
| 16 | #define USE_COMM_WORLD -987654 |
||
| 17 | |||
| 18 | #if defined(MAIN_COMP) |
||
| 19 | /* |
||
| 20 | * Some Fortran compilers (COMPAQ fort) define main inside |
||
| 21 | * their runtime library while a Fortran program translates |
||
| 22 | * to MAIN_ or MAIN__ which is then called from "main". This |
||
| 23 | * is annoying because MAIN__ has no arguments and we must |
||
| 24 | * define argc/argv arbitrarily !! |
||
| 25 | */ |
||
| 26 | int MAIN__(); |
||
| 27 | int MAIN_() |
||
| 28 | { |
||
| 29 | return MAIN__(); |
||
| 30 | } |
||
| 31 | |||
| 32 | int MAIN__() |
||
| 33 | { |
||
| 34 | int argc=1; |
||
| 35 | char * name = "c_example"; |
||
| 36 | char ** argv ; |
||
| 37 | #else |
||
| 38 | int main(int argc, char ** argv) |
||
| 39 | { |
||
| 40 | #endif |
||
| 41 | DMUMPS_STRUC_C id; |
||
| 42 | |||
| 43 | int n = 6; |
||
| 44 | int nz = 21; |
||
| 45 | int irnL[] = {1,2,3,4,5,6,2,3,4,5,6,3,4,5,6,4,5,6,5,6,6}; |
||
| 46 | int jcnL[] = {1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,6}; |
||
| 47 | int irnS[] = {1,2,3,2,3,3}; |
||
| 48 | int jcnS[] = {1,1,1,2,2,3}; |
||
| 49 | |||
| 50 | int *irn = irnL; |
||
| 51 | int *jcn = jcnL; |
||
| 52 | |||
| 53 | double a[21]; |
||
| 54 | double rhs[6]; |
||
| 55 | |||
| 56 | int myid, ierr, numP; |
||
| 57 | #if defined(MAIN_COMP) |
||
| 58 | argv = &name; |
||
| 59 | #endif |
||
| 60 | ierr = MPI_Init(&argc, &argv); |
||
| 61 | ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid); |
||
| 62 | ierr = MPI_Comm_size(MPI_COMM_WORLD, &numP); |
||
| 63 | |||
| 64 | double nump = numP * 1.0; |
||
| 65 | |||
| 66 | /* Define A and rhs */ |
||
| 67 | rhs[0]=2.0;rhs[1]=2.0;rhs[2]=2.0;rhs[3]=2.0;rhs[4]=2.0;rhs[5]=2.0; |
||
| 68 | |||
| 69 | a[0]=4169.95/nump; |
||
| 70 | a[1]=0.0; |
||
| 71 | a[2]=10075.0/nump; |
||
| 72 | a[3]=-4030; |
||
| 73 | a[4]=0.0; |
||
| 74 | a[5]=0.0; |
||
| 75 | a[6]=10084.0/nump; |
||
| 76 | a[7]=-1612.0/nump; |
||
| 77 | a[8]=0.0; |
||
| 78 | a[9]=-8.9556; |
||
| 79 | a[10]=-1612; |
||
| 80 | a[11]=1354080.0/nump; |
||
| 81 | a[12]=0.0; |
||
| 82 | a[13]=1612.0; |
||
| 83 | a[14]=193440.0; |
||
| 84 | a[15]=4169.93; |
||
| 85 | a[16]=0.0; |
||
| 86 | a[17]=10075; |
||
| 87 | a[18]=10084; |
||
| 88 | a[19]=1612; |
||
| 89 | a[20]=1354000; |
||
| 90 | |||
| 91 | if (myid != 0) { |
||
| 92 | nz = 6; |
||
| 93 | |||
| 94 | a[0]=4169.95/nump; |
||
| 95 | a[1]=0.0; |
||
| 96 | a[2]=10075.0/nump; |
||
| 97 | |||
| 98 | a[3]=10084.0/nump; |
||
| 99 | a[4]=-1612.0/nump; |
||
| 100 | |||
| 101 | a[5]=1354080.0/nump; |
||
| 102 | |||
| 103 | irn = irnS; |
||
| 104 | jcn = jcnS; |
||
| 105 | } |
||
| 106 | |||
| 107 | #define ICNTL(I) icntl[(I)-1] /* macro s.t. indices match documentation */ |
||
| 108 | |||
| 109 | /* Initialize a MUMPS instance. Use MPI_COMM_WORLD */ |
||
| 110 | id.job=JOB_INIT; id.par=1; id.sym=2; id.comm_fortran=USE_COMM_WORLD; |
||
| 111 | |||
| 112 | /* parallel solver; distributed i/p matrix A */ |
||
| 113 | id.ICNTL(5)=0; id.ICNTL(18)=3; |
||
| 114 | dmumps_c(&id); |
||
| 115 | |||
| 116 | /* Define the problem on the host */ |
||
| 117 | /* |
||
| 118 | id.n = n; id.nz =nz; id.irn=irn; id.jcn=jcn; |
||
| 119 | id.a = a; id.rhs = rhs; |
||
| 120 | */ |
||
| 121 | |||
| 122 | /* parallel solver; distributed i/p matrix A */ |
||
| 123 | |||
| 124 | id.ICNTL(5)=0; id.ICNTL(18)=3; |
||
| 125 | |||
| 126 | id.n = n; id.nz_loc =nz; id.irn_loc=irn; id.jcn_loc=jcn; |
||
| 127 | id.a_loc = a; id.rhs = rhs; |
||
| 128 | |||
| 129 | /* No outputs */ |
||
| 130 | id.ICNTL(1)=-1; id.ICNTL(2)=-1; id.ICNTL(3)=-1; id.ICNTL(4)=0; |
||
| 131 | |||
| 132 | id.job=1; |
||
| 133 | dmumps_c(&id); |
||
| 134 | |||
| 135 | |||
| 136 | id.job=5; |
||
| 137 | dmumps_c(&id); |
||
| 138 | |||
| 139 | if (myid == 0) { |
||
| 140 | printf("Solution is : (%8.6e %8.6e %8.6e %8.6e %8.6e %8.6e \n", rhs[0],rhs[1], rhs[2], rhs[3], rhs[4], rhs[5]); |
||
| 141 | } |
||
| 142 | |||
| 143 | rhs[0]=2.0;rhs[1]=2.0;rhs[2]=2.0;rhs[3]=1.0;rhs[4]=1.0;rhs[5]=1.0; |
||
| 144 | |||
| 145 | |||
| 146 | id.job=3; |
||
| 147 | dmumps_c(&id); |
||
| 148 | |||
| 149 | /* Terminate instance */ |
||
| 150 | id.job=JOB_END; |
||
| 151 | dmumps_c(&id); |
||
| 152 | |||
| 153 | if (myid == 0) { |
||
| 154 | printf("Solution is : (%8.6e %8.6e %8.6e %8.6e %8.6e %8.6e \n", rhs[0],rhs[1], rhs[2], rhs[3], rhs[4], rhs[5]); |
||
| 155 | } |
||
| 156 | |||
| 157 | ierr = MPI_Finalize(); |
||
| 158 | return 0; |
||
| 159 | } |
||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 |