Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunks #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ AC_CHECK_HEADERS([stdint.h],
)

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday])
# AC_FUNC_MALLOC disabled to ensure that cross-compilation works and autoconf does
# not attempt to substitute 'rpl_malloc'
##AC_FUNC_MALLOC
AC_CHECK_FUNCS([malloc realloc calloc gettimeofday])

AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([include/Makefile])
Expand Down
1 change: 1 addition & 0 deletions src/internal_LemonSetup.ih
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct
int ndims;
int localVol;
int totalVol;
int nranks;

int *starts;
int *localDims;
Expand Down
3 changes: 2 additions & 1 deletion src/internal_setupIOTypes.static
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static void lemonSetupIOTypes(LemonSetup *setup, MPI_Comm cartesian, MPI_Offset

/* Gathering of the required MPI data from the cartesian communicator. */
MPI_Cartdim_get(cartesian, &setup->ndims);
MPI_Comm_size(cartesian, &setup->nranks);

setup->starts = (int*)malloc(setup->ndims * sizeof(int));
setup->localDims = (int*)malloc(setup->ndims * sizeof(int));
Expand Down Expand Up @@ -72,4 +73,4 @@ static void lemonSetupIOTypes(LemonSetup *setup, MPI_Comm cartesian, MPI_Offset
MPI_Type_create_subarray(setup->ndims, setup->mappedDims, setup->localDims, setup->starts,
MPI_ORDER_C, setup->etype, &setup->ftype);
MPI_Type_commit(&setup->ftype);
}
}
36 changes: 26 additions & 10 deletions src/reader_latticeParallelMapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <config.h>
#include <lemon.h>
#include <stdio.h>
#include <limits.h>

#include "internal_LemonSetup.ih"
#include "internal_clearReaderState.static"
Expand All @@ -45,18 +46,33 @@ int lemonReadLatticeParallelMapped(LemonReader *reader, void *data, MPI_Offset s
return error;

lemonSetupIOTypes(&setup, reader->cartesian, siteSize, latticeDims, mapping);

/* Install the data organization we worked out above on the file as a view.
We keep the individual file pointers synchronized explicitly, so assume they are here. */
MPI_File_set_view(*reader->fp, reader->off + reader->pos, setup.etype, setup.ftype, "native", MPI_INFO_NULL);
We keep the individual file pointers synchronized explicitly, so assume they are here. */
MPI_File_set_view(*reader->fp, reader->off + reader->pos,
setup.etype, setup.ftype, "native", MPI_INFO_NULL);

/* Blast away! */
MPI_File_read_at_all(*reader->fp, reader->pos, data, setup.localVol, setup.etype, &status);
MPI_Barrier(reader->cartesian);
long int bytes = (long int)setup.localVol * (long int)siteSize;
long int buffer_offset = 0;
while( bytes > 0 ){
int chunk = bytes > (long int)INT_MAX ? (INT_MAX/siteSize)*siteSize : bytes;
bytes -= (long int)chunk;

/* Synchronize the file pointer */
MPI_Get_count(&status, MPI_BYTE, &read);
reader->pos += setup.totalVol * siteSize;
/* Blast away! */
MPI_File_read_at_all(*reader->fp, reader->pos, &data[buffer_offset], chunk/siteSize, setup.etype, &status);
MPI_Barrier(reader->cartesian);

/* Synchronize the file pointer */
MPI_Get_count(&status, MPI_BYTE, &read);
buffer_offset += (long int)read;
if (read != chunk)
{
fprintf(stderr, "[LEMON] Node %d reports in lemonReadLatticeParallel:\n"
" Could not read the required amount of data.\n", reader->my_rank);
return LEMON_ERR_READ;
}
reader->pos += (long int)chunk * (long int)setup.nranks;
}

/* We want to leave the file in a well-defined state, so we reset the view to a default. */
/* We don't want to reread any data, so we maximize the file pointer globally. */
Expand All @@ -66,7 +82,7 @@ int lemonReadLatticeParallelMapped(LemonReader *reader, void *data, MPI_Offset s
lemonFreeIOTypes(&setup);

/* Doing a data read should never get us to EOF, only header scanning -- any shortfall is an error */
if (read != siteSize * setup.localVol)
if (buffer_offset != (long int)siteSize * (long int)setup.localVol)
{
fprintf(stderr, "[LEMON] Node %d reports in lemonReadLatticeParallel:\n"
" Could not read the required amount of data.\n", reader->my_rank);
Expand Down
37 changes: 24 additions & 13 deletions src/writer_latticeParallelMapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <config.h>
#include <lemon.h>
#include <stdio.h>
#include <limits.h>

#include "internal_LemonSetup.ih"
#include "internal_clearWriterState.static"
Expand All @@ -50,13 +51,31 @@ int lemonWriteLatticeParallelMapped(LemonWriter *writer, void *data, MPI_Offset
MPI_Barrier(writer->cartesian);
MPI_File_set_view(*writer->fp, writer->off + writer->pos, setup.etype, setup.ftype, "native", MPI_INFO_NULL);

/* Blast away! */
MPI_File_write_at_all(*writer->fp, writer->pos, data, setup.localVol, setup.etype, &status);
MPI_File_sync(*writer->fp);
long int bytes = (long int)setup.localVol * (long int)siteSize;
long int buffer_offset = 0;

MPI_Barrier(writer->cartesian);
while( bytes > 0 ){
int chunk = bytes > (long int)INT_MAX ? (INT_MAX/siteSize)*siteSize : bytes;
bytes -= (long int)chunk;

/* Blast away! */
MPI_File_write_at_all(*writer->fp, writer->pos, &data[buffer_offset], chunk/siteSize, setup.etype, &status);
MPI_File_sync(*writer->fp);

MPI_Barrier(writer->cartesian);

writer->pos += (long int)chunk * (long int)setup.nranks;

MPI_Get_count(&status, MPI_BYTE, &written);

writer->pos += setup.totalVol * siteSize;
buffer_offset += (long int)written;
if (written != chunk)
{
fprintf(stderr, "[LEMON] Node %d reports in lemonWriteLatticeParallel:\n"
" Could not write the required amount of data.\n", writer->my_rank);
return LEMON_ERR_WRITE;
}
}

/* We should reset the shared file pointer, in an MPI_BYTE based view... */
MPI_Barrier(writer->cartesian);
Expand All @@ -65,13 +84,5 @@ int lemonWriteLatticeParallelMapped(LemonWriter *writer, void *data, MPI_Offset
/* Free up the resources we claimed for this operation. */
lemonFreeIOTypes(&setup);

MPI_Get_count(&status, MPI_BYTE, &written);
if (written != siteSize * setup.localVol)
{
fprintf(stderr, "[LEMON] Node %d reports in lemonWriteLatticeParallel:\n"
" Could not write the required amount of data.\n", writer->my_rank);
return LEMON_ERR_WRITE;
}

return LEMON_SUCCESS;
}