Ejemplo n.º 1
0
Bool Stream_AppendFile_WithPrependedPath( Stream* stream, char* prependedPath, char* filename ) {
   Bool result;

   /* Check to make sure output path is emtpy */ 
   if( Stg_StringIsEmpty( prependedPath ) )
      result = Stream_AppendFile( stream, filename );
   else {
      char* prependedFilename;

      Stg_asprintf( &prependedFilename, "%s/%s", prependedPath, filename );
      result = Stream_AppendFile( stream, prependedFilename );
      Memory_Free( prependedFilename );
   }

   return result;
}
SizeT BinaryStream_WriteAllProcessors( Name filename, void *data, SizeT elem_size, SizeT num_elems, MPI_Comm comm ) {
    Stream*    stream = Journal_Register( BinaryStream_Type, BinaryStream_Type );
    MPI_Status status;
    int        rank;
    int        nproc;
    int        confirmation = 0;
    const int         FINISHED_WRITING_TAG = 100;
    MPI_Comm_rank( comm, &rank );
    MPI_Comm_size( comm, &nproc );

    /* wait for go-ahead from process ranked lower than me, to avoid competition writing to file */
    if ( rank != 0 ) {
        MPI_Recv( &confirmation, 1, MPI_INT, rank - 1, FINISHED_WRITING_TAG, comm, &status );
    }
    /* open the file */
    if ( rank == 0 ) {
        Stream_RedirectFile( stream, filename );
    }
    else {
        Stream_AppendFile( stream, filename );
    }

    /* write the data */
    Stream_Write( stream, data, elem_size, num_elems );

    /* close the file */
    Stream_CloseFile( stream);
    /* send go-ahead from process ranked lower than me, to avoid competition writing to file */
    if ( rank != nproc - 1 ) {
        MPI_Ssend( &confirmation, 1, MPI_INT, rank + 1, FINISHED_WRITING_TAG, comm );
    }

    return (SizeT) NULL;
}