@@ -31,29 +31,38 @@ int Sampler::initCSV(const char *name)
3131int Sampler::writeHistory (int curr_iter) {
3232 FILE* f = fopen (filename," at" );
3333 for (int i = startIter; i< curr_iter; i++){
34- for (size_t j = 0 ; j < spoints.size (); j++) {
35- if (mpi_rank == spoints[j].rank ) {
36- vector_t tmp_loc;
37- tmp_loc.x = spoints[j].location .dx ;
38- tmp_loc.y = spoints[j].location .dy ;
39- tmp_loc.z = spoints[j].location .dz ;
40- fprintf (f," %d" ,i);
41- csvWriteElement (f,tmp_loc);
42- for (const auto & quantity : model->quantities ) {
43- if (quant->in (quantity.name )) {
44- real_t tmp;
45- int comp = 1 ;
46- if (quantity.isVector ) comp = 3 ;
47- CudaMemcpy (&tmp,&gpu_buffer[(location[quantity.name ] + (i - startIter)*size + totalIter*j*size)],sizeof (real_t )*comp,CudaMemcpyDeviceToHost);
48- csvWriteElement (f,tmp);
34+ for (size_t j = 0 ; j < spoints.size (); j++) {
35+ if (mpi_rank == spoints[j].rank ) {
36+ vector_t tmp_loc;
37+ tmp_loc.x = spoints[j].location .dx ;
38+ tmp_loc.y = spoints[j].location .dy ;
39+ tmp_loc.z = spoints[j].location .dz ;
40+ fprintf (f," %d" ,i);
41+ csvWriteElement (f,tmp_loc);
42+ for (const auto & quantity : model->quantities ) {
43+ if (quant->in (quantity.name )) {
44+ if (quantity.isVector ) {
45+ real_t *tmp = (real_t *)malloc (3 *sizeof (real_t ));
46+ CudaMemcpy (tmp,&gpu_buffer[(location[quantity.name ] + (i - startIter)*size + totalIter*j*size)],sizeof (real_t )*3 ,CudaMemcpyDeviceToHost);
47+ vector_t val;
48+ val.x = tmp[0 ];
49+ val.y = tmp[1 ];
50+ val.z = tmp[2 ];
51+ csvWriteElement (f, val);
52+ free (tmp);
53+ } else {
54+ real_t tmp;
55+ CudaMemcpy (&tmp,&gpu_buffer[(location[quantity.name ] + (i - startIter)*size + totalIter*j*size)],sizeof (real_t ),CudaMemcpyDeviceToHost);
56+ csvWriteElement (f, tmp);
57+ }
58+ }
59+ }
60+ fprintf (f," \n " );
4961 }
5062 }
51- fprintf (f," \n " );
52- }
53- }
54- }
55- fclose (f);
56- return 0 ;
63+ }
64+ fclose (f);
65+ return 0 ;
5766 }
5867
5968int Sampler::Allocate (name_set* nquantities,int start,int iter) {
0 commit comments