Line | |
---|
1 | /*!\file SplitSolutionVectorx
|
---|
2 | */
|
---|
3 |
|
---|
4 | #include "./SplitSolutionVectorx.h"
|
---|
5 |
|
---|
6 | void SplitSolutionVectorx(Vec u_g,int numberofnodes,int numberofdofs, ...){
|
---|
7 |
|
---|
8 | /*http://www.dreamincode.net/forums/topic/79104-variadic-functions-or-how-printf-works */
|
---|
9 |
|
---|
10 | /*Intermediary*/
|
---|
11 | va_list outputlist;
|
---|
12 | double* u_g_serial=NULL;
|
---|
13 | double** pvector;
|
---|
14 | int i,count;
|
---|
15 |
|
---|
16 | /*Serialize vector and allocate once for all*/
|
---|
17 | VecToMPISerial(&u_g_serial,u_g);
|
---|
18 |
|
---|
19 | /* va_start() takes the arg list type we just declared, as well
|
---|
20 | as the last argument in this function's definition, ie. 'int numberofdofs'*/
|
---|
21 | va_start(outputlist,numberofdofs);
|
---|
22 |
|
---|
23 | /*Loop over the arguments*/
|
---|
24 | count=0;
|
---|
25 | while (count<numberofdofs){
|
---|
26 | /* va_arg() takes the arg list from above, and the type
|
---|
27 | the argument is supposed to be and then (hopefully) returns it*/
|
---|
28 | pvector=va_arg(outputlist,double**);
|
---|
29 |
|
---|
30 | //continue if the pointer is NULL (output not requested)
|
---|
31 | if (pvector==NULL) continue;
|
---|
32 |
|
---|
33 | /*Dynamically allocate single dof vector*/
|
---|
34 | double* vector=NULL;
|
---|
35 | vector=(double*)xmalloc(numberofnodes*sizeof(double));
|
---|
36 |
|
---|
37 | /*Fill vector*/
|
---|
38 | for (i=0;i<numberofnodes;i++) vector[i]=u_g_serial[i*numberofdofs+count];
|
---|
39 |
|
---|
40 | /*Assign vector*/
|
---|
41 | *pvector=vector;
|
---|
42 |
|
---|
43 | /*update counter*/
|
---|
44 | count++;
|
---|
45 | }
|
---|
46 | va_end (outputlist);
|
---|
47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.