source: issm/trunk-jpl/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp@ 12011

Last change on this file since 12011 was 12011, checked in by Eric.Larour, 13 years ago

Preliminary commit of new issm version, where serial code is starting to be stripped away. Will not run before some major debugging is done

File size: 6.5 KB
RevLine 
[4139]1/*!\file DoubleMatExternalResult.c
2 * \brief: implementation of the DoubleMatExternalResult object
3 */
4
5/*header files: */
6/*{{{1*/
7#ifdef HAVE_CONFIG_H
[9320]8 #include <config.h>
[4139]9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
[9320]13#include <stdio.h>
[4139]14#include <string.h>
15#include "../objects.h"
16#include "../../EnumDefinitions/EnumDefinitions.h"
17#include "../../shared/shared.h"
[4236]18#include "../../Container/Container.h"
[4139]19#include "../../include/include.h"
20/*}}}*/
21
[4248]22/*DoubleMatExternalResult constructors and destructor*/
[4139]23/*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(){{{1*/
24DoubleMatExternalResult::DoubleMatExternalResult(){
25 return;
26}
27/*}}}*/
[4143]28/*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int enum_type,IssmDoubleMat values,int M,int N,int in_step,double in_time){{{1*/
[4139]29DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int in_enum_type,double* in_values, int in_M,int in_N,int in_step,double in_time){
30
31 id=in_id;
32 enum_type=in_enum_type;
33 M=in_M;
34 N=in_N;
35
[4191]36 /*Copy result in values*/
[4195]37 if(M*N){
38 values=(double*)xmalloc(M*N*sizeof(double));
39 memcpy(values,in_values,M*N*sizeof(double));
40 }
41 else values=NULL;
[4139]42
43 step=in_step;
44 time=in_time;
45}
46/*}}}*/
47/*FUNCTION DoubleMatExternalResult::~DoubleMatExternalResult(){{{1*/
48DoubleMatExternalResult::~DoubleMatExternalResult(){
[4195]49
50 xfree((void**)&this->values);
[4139]51 return;
52}
53/*}}}*/
54
[4248]55/*Object virtual functions definitions:*/
56/*FUNCTION DoubleMatExternalResult::Echo {{{1*/
57void DoubleMatExternalResult::Echo(void){
[4139]58
[4248]59 printf("DoubleMatExternalResult:\n");
[8224]60 printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
[4248]61 printf(" step: %i\n",this->step);
62 printf(" time: %g\n",this->time);
63 printf(" matrix size: %i-%i\n",this->M,this->N);
64
[4139]65}
66/*}}}*/
67/*FUNCTION DoubleMatExternalResult::DeepEcho{{{1*/
68void DoubleMatExternalResult::DeepEcho(void){
69
[4201]70 int i,j;
[4139]71
72 printf("DoubleMatExternalResult:\n");
73 printf(" id: %i\n",this->id);
[8224]74 printf(" enum: %i (%s)\n",this->enum_type,EnumToStringx(this->enum_type));
[4139]75 printf(" step: %i\n",this->step);
76 printf(" time: %g\n",this->time);
[4201]77 printf(" matrix size: %i-%i\n",this->M,this->N);
78 for (i=0;i<this->M;i++){
79 printf(" [ ");
80 for (j=0;j<this->N;j++){
81 printf(" %12.6g ",this->values[i*this->N+j]);
82 }
83 printf(" ]\n");
84 }
85 printf("\n");
86
[4139]87}
88/*}}}*/
[4248]89/*FUNCTION DoubleMatExternalResult::Id{{{1*/
90int DoubleMatExternalResult::Id(void){ return -1; }
[4139]91/*}}}*/
[4248]92/*FUNCTION DoubleMatExternalResult::MyRank{{{1*/
93int DoubleMatExternalResult::MyRank(void){
94 extern int my_rank;
95 return my_rank;
[4139]96}
97/*}}}*/
[11936]98#ifdef _SERIAL_
[4139]99/*FUNCTION DoubleMatExternalResult::Marshall{{{1*/
100void DoubleMatExternalResult::Marshall(char** pmarshalled_dataset){
101
102 char* marshalled_dataset=NULL;
103 int enum_value=0;
104
105 /*recover marshalled_dataset: */
106 marshalled_dataset=*pmarshalled_dataset;
107
108 /*get enum value of DoubleMatExternalResult: */
109 enum_value=DoubleMatExternalResultEnum;
110
111 /*marshall enum: */
112 memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
113
114 /*marshall DoubleMatExternalResult data: */
115 memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
116 memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
117 memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
118 memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
119 memcpy(marshalled_dataset,values,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
120 memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
121 memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
122
123 *pmarshalled_dataset=marshalled_dataset;
124}
125/*}}}*/
126/*FUNCTION DoubleMatExternalResult::MarshallSize{{{1*/
127int DoubleMatExternalResult::MarshallSize(){
128
129 return sizeof(M)
130 +sizeof(N)
131 +M*N*sizeof(double)
132 +sizeof(id)
133 +sizeof(enum_type)
134 +sizeof(step)
135 +sizeof(time)
136 +sizeof(int); //sizeof(int) for enum value
137}
138/*}}}*/
[4248]139/*FUNCTION DoubleMatExternalResult::Demarshall{{{1*/
140void DoubleMatExternalResult::Demarshall(char** pmarshalled_dataset){
141
142 char* marshalled_dataset=NULL;
143 int i;
144
145 /*recover marshalled_dataset: */
146 marshalled_dataset=*pmarshalled_dataset;
147
148 /*this time, no need to get enum type, the pointer directly points to the beginning of the
149 *object data (thanks to DataSet::Demarshall):*/
150 memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
151 memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
152
153 /*data: */
154 memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
155 memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
156 values=(double*)xmalloc(M*N*sizeof(double));
157 memcpy(values,marshalled_dataset,M*N*sizeof(double));marshalled_dataset+=M*N*sizeof(double);
158 memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
159 memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
160
161 /*return: */
162 *pmarshalled_dataset=marshalled_dataset;
163 return;
[4139]164}
165/*}}}*/
[9777]166#endif
[9883]167/*FUNCTION DoubleMatExternalResult::ObjectEnum{{{1*/
168int DoubleMatExternalResult::ObjectEnum(void){
[4139]169
[4248]170 return DoubleMatExternalResultEnum;
171
172}
173/*}}}*/
174/*FUNCTION DoubleMatExternalResult::copy{{{1*/
175Object* DoubleMatExternalResult::copy() {
176
177 return new DoubleMatExternalResult(this->id,this->enum_type,this->values,this->M,this->N,this->step,this->time);
178
179}
180/*}}}*/
181
182/*DoubleMatExternalResult management: */
[4546]183/*FUNCTION DoubleMatExternalResult::WriteData{{{1*/
[6389]184void DoubleMatExternalResult::WriteData(FILE* fid,bool io_gather){
[4139]185
186 int length;
187 int type;
[4201]188 int rows,cols;
[4139]189 char *name = NULL;
190 extern int my_rank;
191
[6389]192 if(io_gather){
193 /*we are gathering the data on cpu 0, don't write on other cpus: */
194 if(my_rank) return;
195 }
[4139]196
197 /*First write enum: */
[11202]198 EnumToStringx(&name,this->enum_type);
[4139]199 length=(strlen(name)+1)*sizeof(char);
200 fwrite(&length,sizeof(int),1,fid);
201 fwrite(name,length,1,fid);
[11205]202 xfree((void**)&name);
[4139]203
204 /*Now write time and step: */
205 fwrite(&time,sizeof(double),1,fid);
206 fwrite(&step,sizeof(int),1,fid);
207
208 /*writing a double array, type is 3:*/
209 type=3;
210 fwrite(&type,sizeof(int),1,fid);
[4201]211 rows=this->M;
212 fwrite(&rows,sizeof(int),1,fid);
213 cols=this->N;
214 fwrite(&cols,sizeof(int),1,fid);
215 fwrite(this->values,cols*rows*sizeof(double),1,fid);
[4139]216
217}
218/*}}}1*/
[4546]219/*FUNCTION DoubleMatExternalResult::GetResultName{{{1*/
[11202]220void DoubleMatExternalResult::GetResultName(char** pname){
221 EnumToStringx(pname,this->enum_type);
[4166]222}
223/*}}}*/
[4546]224/*FUNCTION DoubleMatExternalResult::GetStep{{{1*/
[4182]225int DoubleMatExternalResult::GetStep(void){
226
227 return this->step;
228}
229/*}}}*/
Note: See TracBrowser for help on using the repository browser.