212 const int nitot,
const int njtot,
const int nktot,
const int nbcompo,
const int component)
227 for (
int dir = 0; dir < 3 ; dir++)
231 int& n = (dir==0)?ni:((dir==1)?nj:nk);
237 for (
int k = 0; k < nk; k++)
238 for (
int j = 0; j < nj; j++)
239 for (
int i = 0; i < ni; i++)
240 sendtmp[(k*nj+j)*ni+i] = (_OUT_TYPE_)input(i,j,k);
251 envoyer(sendtmp, 0, 0);
260 for (
int kproc = 0; kproc < mapping.
dimension(2); kproc++)
262 for (
int jproc = 0; jproc < mapping.
dimension(1); jproc++)
264 for (
int iproc = 0; iproc < mapping.
dimension(0); iproc++)
266 const int numproc = mapping(iproc, jproc, kproc);
267 int imin2, jmin2, kmin2, ni2, nj2, nk2;
280 recevoir(imin2,numproc,0);
281 recevoir(ni2,numproc,0);
282 recevoir(jmin2,numproc,0);
283 recevoir(nj2,numproc,0);
284 recevoir(kmin2,numproc,0);
285 recevoir(nk2,numproc,0);
286 recevoir(recv_tmp, numproc,0);
289 for (
int k = 0; k < nk2; k++)
290 for (
int j = 0; j < nj2; j++)
291 for (
int i = 0; i < ni2; i++)
292 output[(((k+kmin2)*njtot+(j+jmin2))*nitot+i+imin2)*nbcompo + component] = recv_tmp[(k*nj2+j)*ni2+i];
304 const int nitot,
const int njtot,
const int nktot,
const int nbcompo,
const int component)
309 int ni = output.
ni();
310 int nj = output.
nj();
311 int nk = output.
nk();
331 for (
int kproc = 0; kproc < mapping.
dimension(2); kproc++)
333 for (
int jproc = 0; jproc < mapping.
dimension(1); jproc++)
335 for (
int iproc = 0; iproc < mapping.
dimension(0); iproc++)
337 const int numproc = mapping(iproc, jproc, kproc);
338 int imin2, jmin2, kmin2, ni2, nj2, nk2;
350 recevoir(imin2,numproc,0);
351 recevoir(ni2,numproc,0);
352 recevoir(jmin2,numproc,0);
353 recevoir(nj2,numproc,0);
354 recevoir(kmin2,numproc,0);
355 recevoir(nk2,numproc,0);
359 for (
int k = 0; k < nk2; k++)
360 for (
int j = 0; j < nj2; j++)
361 for (
int i = 0; i < ni2; i++)
362 send_tmp[(k*nj2+j)*ni2+i] = input[(((k+kmin2)*njtot+(j+jmin2))*nitot+i+imin2)*nbcompo + component];
365 envoyer(send_tmp, numproc, 0);
377 recevoir(recv_tmp, 0, 0);
379 for (
int k = 0; k < nk; k++)
380 for (
int j = 0; j < nj; j++)
381 for (
int i = 0; i < ni; i++)
382 output(i,j,k) = (_TYPE_)recv_tmp[(k*nj+j)*ni+i];
448 const int file_ni_tot,
const int file_nj_tot,
const int file_nk_tot,
452 const int nb_components = ((&vy == &vx) && (&vz == &vx)) ? 1 : 3;
454 constexpr Size_t INT64_OFFSET = 6;
456 constexpr Size_t INT64_OFFSET = 0;
471 ArrOfInt writing_processes(nb_writing_processes);
472 int my_writing_process_index = -1;
473 for (
int i = 0; i < nb_writing_processes; i++)
475 writing_processes[i] =
Process::nproc() * i / nb_writing_processes;
477 my_writing_process_index = i;
481 const Size_t total_data_bytes = (Size_t) file_nk_tot * file_nj_tot * file_ni_tot * nb_components *
sizeof(_OUT_TYPE_);
483 FILE *file_pointer = 0;
489 if (my_writing_process_index == 0)
492 file_pointer = fopen(filename,
"w");
493 if (!file_pointer || errno)
495 Cerr <<
"Error opening file " << filename <<
": fopen(filename,w) failed" << finl;
499 const char i64[] =
"INT64";
500 fwrite(i64,
sizeof(
char), INT64_OFFSET, file_pointer);
505 fseek(file_pointer, total_data_bytes + INT64_OFFSET -
sizeof(Size_t), SEEK_SET);
508 Cerr <<
"Error seeking at file offset " << (int)(total_data_bytes>>32) <<
"GB in file " << filename << finl;
512 fwrite(&total_data_bytes,
sizeof(Size_t), 1, file_pointer);
515 Cerr <<
"Error writing at file offset " << (int)(total_data_bytes>>32) <<
"GB in file " << filename << finl;
522 if (my_writing_process_index > 0)
525 file_pointer = fopen(filename,
"r+");
526 if (!file_pointer || errno)
528 Cerr <<
"Error opening file " << filename <<
": fopen(filename,r+) failed on writing process " << my_writing_process_index << finl;
536 ArrOfInt send_pe_list(writing_processes.
size_array());
539 for (
int i = 0; i < writing_processes.
size_array(); i++)
540 if (i != my_writing_process_index)
545 if (my_writing_process_index >= 0)
555 int total_number_of_blocks = (int)((total_data_bytes + block_size - 1) / block_size);
560 if (my_writing_process_index >= 0)
561 recv_tmp.
resize_array((
int)(block_size /
sizeof(_OUT_TYPE_)));
565 for (
int i_block_proc0 = 0; i_block_proc0 < total_number_of_blocks; i_block_proc0 += nb_writing_processes)
573 for (
int iwrite_process = 0; iwrite_process < nb_writing_processes; iwrite_process++)
575 Sortie& send_buffer = schema_comm.
send_buffer(writing_processes[iwrite_process]);
577 Size_t offset_start_of_block = (Size_t) block_size * (i_block_proc0 + iwrite_process);
578 Size_t offset_end_of_block = offset_start_of_block + block_size;
579 if (offset_end_of_block > total_data_bytes)
580 offset_end_of_block = total_data_bytes;
581 if (offset_start_of_block >= offset_end_of_block)
588 const int kmax = std::max(vx.
nk(), std::max(vy.
nk(), vz.
nk()));
589 const int jmax = std::max(vx.
nj(), std::max(vy.
nj(), vz.
nj()));
590 const int imax = std::max(vx.
ni(), std::max(vy.
ni(), vz.
ni()));
591 for (
int k = 0; k < kmax; k++)
593 for (
int j = 0; j < jmax; j++)
597 Size_t offset_segment_start = (Size_t) (k + splitting.
get_offset_local(DIRECTION_K)) * file_nj_tot;
598 offset_segment_start = (offset_segment_start + j + splitting.
get_offset_local(DIRECTION_J)) * file_ni_tot;
600 offset_segment_start *= nb_components *
sizeof(_OUT_TYPE_);
601 Size_t offset_segment_end = offset_segment_start + imax * nb_components *
sizeof(_OUT_TYPE_);
604 const Size_t offset_intersection_start = (offset_start_of_block < offset_segment_start) ? offset_segment_start : offset_start_of_block;
605 const Size_t offset_intersection_end = (offset_end_of_block < offset_segment_end) ? offset_end_of_block : offset_segment_end;
608 if (offset_intersection_end > offset_intersection_start)
615 for (
int i_component = 0; i_component < nb_components; i_component++)
619 if (k < src_field.
nk() && j < src_field.
nj())
621 const int max_this_compo = src_field.
ni();
622 for (
int i = 0; i < max_this_compo; i++)
624 tmp[i * nb_components + i_component] = (_OUT_TYPE_)src_field(i, j, k);
629 const int start_index_within_block = (int) (offset_intersection_start - offset_start_of_block);
630 const int start_index_within_tmp = (int) (offset_intersection_start - offset_segment_start);
632 const int data_length = (int) (offset_intersection_end - offset_intersection_start);
633 send_buffer << start_index_within_block << data_length;
634 const int sz = (int)
sizeof(_OUT_TYPE_);
635 send_buffer.
put(tmp.
addr() + start_index_within_tmp/sz,
645 if (my_writing_process_index >= 0)
649 const Size_t offset = (Size_t) block_size * (i_block_proc0 + my_writing_process_index);
651 Size_t this_block_size = block_size;
652 if (total_data_bytes - offset < this_block_size)
653 this_block_size = total_data_bytes - offset;
655 for (
int i_source_process = 0; i_source_process < nproc; i_source_process++)
660 int start_index_within_block;
661 recv_buffer >> start_index_within_block;
662 if (recv_buffer.
eof())
665 recv_buffer >> data_length;
669 if (start_index_within_block < 0 || data_length < 1 || start_index_within_block + data_length > this_block_size)
671 Cerr <<
"Internal error in writing ijk lata file: start_index_within_block and data_length are invalid" << finl;
674 if (start_index_within_block + data_length > recv_tmp.
size_array() * (
int)
sizeof(_OUT_TYPE_))
676 Cerr <<
"Internal error in writing ijk lata file: index out of bound" << finl;
679 const int sz = (int)
sizeof(_OUT_TYPE_);
680 recv_buffer.
get(recv_tmp.
addr() + start_index_within_block/sz,
687 fseek(file_pointer, offset + INT64_OFFSET, SEEK_SET);
690 Cerr <<
"Error seeking at file offset " << (int)(offset>>32) <<
"GB in file " << filename << finl;
693 fwrite((
const char*)recv_tmp.
addr(), this_block_size , 1, file_pointer);
696 Cerr <<
"Error writing at file offset " << (int)(offset>>32) <<
"GB in file " << filename << finl;
705 fclose(file_pointer);
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
int get_offset_local(int direction) const
Returns the local offset in requested direction.
int get_nb_elem_local(int direction) const
Returns the number of elements owned by this processor in the given direction.
bool get_periodic_flag(int direction) const
Method returns true if periodic in this direction.
int get_nprocessor_per_direction(int direction) const
Returns the number of slices in the given direction.
int get_nb_items_local(Localisation loc, int direction) const
Returns the number of local items (on this processor) for the given localisation in the requested dir...
void get_processor_mapping(IntTab &mapping) const
Fills an array containing the mapping of processors.
int get_nb_items_global(Localisation loc, int direction) const
Returns the number of local items (on this processor) for the given localisation in the requested dir...
int get_local_slice_index(int direction) const
Returns the position of the local subdomain in the requested direction.