Skip to content

Commit 7d87caf

Browse files
jedbrownJed Brown jed@59A2.org
authored andcommitted
Working build on Cetus, had to replace realloc with malloc+memset, don't know why
$ make main-mpi LIBCPATH=$HOME/bgqsys/lib $ qsub -t 5 --cwd /gpfs/veas-fs0/jedbrown -n 1024 --mode c64 /home/jedbrown/collfs/main-mpi 0 NumProcs 65536 Min 2.17616@57053 Max 2.17648@31166 Ratio 1.00015 Ave 2.17631
1 parent 9908749 commit 7d87caf

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ CFLAGS = -std=c99 -fPIC -Wall -Wextra ${CFLAGS_DEBUG} -D_LARGEFILE64_SOURCE
88
CFLAGS_DEBUG = -g3 -DDEBUG=1
99
LIBCPATH ?= /lib
1010
LIBDL ?= -ldl
11+
LDSO ?= ld-2.12.2.so
1112
#LDFLAGS = -Wl,-Bdynamic -Wl,-rpath,/home/aron/sys/lib -L/home/aron/sys/lib ${LIBDL}
1213
#LDFLAGS = -dynamic -Wl,-Bdynamic -Wl,-rpath,/home/aron/bgpsys/lib -L/home/aron/bgpsys/lib ${LIBDL}
13-
LDFLAGS = -dynamic -Wl,-Bdynamic -Wl,-rpath,${LIBCPATH} -L${LIBCPATH} ${LIBDL}
14+
LDFLAGS = -dynamic -Wl,-Bdynamic -Wl,-rpath,${LIBCPATH} -L${LIBCPATH} ${LIBDL} ${LIBCPATH}/${LDSO} -Wl,-rpath,${PWD} -Wl,--dynamic-linker=${LIBCPATH}/ld-2.12.2.so -Wl,-rpath,/bgsys/drivers/V1R1M0/ppc64/comm/sys/lib
1415
LIBDL = -ldl
1516
COLLFS_SRC_C = collfs.c
1617
COLLFS_SRC_O = $(COLLFS_SRC_C:.c=.o)

collfs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,20 @@ static void *collfs_mmap(void *addr, size_t len, int prot, int flags, int fildes
404404
if (len > link->totallen) {
405405
if (link->refct==1) { // no clients have mmaped this file, safe to remap/realloc
406406
size_t totallen;
407-
debug_printf(2, "reallocating to size %zd on offset %lld", len, (long long) off);
407+
debug_printf(2, "reallocating to size %zd (was %zd) on offset %lld", len, link->totallen, (long long) off);
408408
totallen = extend_to_page(len);
409409
MPI_Comm_rank(CommStack->comm, &rank);
410410
if (!rank) {
411411
((collfs_munmap_fp) unwrap.munmap)(link->mem,link->totallen);
412412
mem = ((collfs_mmap_fp) unwrap.mmap)(addr, totallen, prot, flags, link->fd, off);
413413
} else {
414-
mem = realloc(link->mem, totallen);
414+
mem = malloc(totallen);
415+
debug_printf(2, "Allocated %zd bytes", totallen);
416+
memcpy(mem,link->mem,link->totallen);
417+
debug_printf(2, "Copied %zd bytes", link->totallen);
418+
free(link->mem);
419+
link->mem = 0;
420+
// mem = realloc(link->mem, totallen);
415421
}
416422
gotmem = !!mem;
417423
MPI_Allreduce(MPI_IN_PLACE, &gotmem, 1, MPI_INT, MPI_LAND, CommStack->comm);

main-mpi.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
#include "collfs.h"
1010
#include "errmacros.h"
1111

12-
int run_tests(const char *soname)
12+
int run_tests(int verbosity,const char *soname)
1313
{
1414
void *handle;
1515
int err, rank;
16-
int (*func)(void);
16+
int (*func)(int);
1717

1818
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1919

20-
printf("[%d] & attempting to open %s\n", rank, soname);
20+
if (verbosity > 0) printf("[%d] & attempting to open %s\n", rank, soname);
2121
handle = dlopen(soname,RTLD_GLOBAL | RTLD_LAZY);
2222
if (!handle) ERR("failed to dlopen(\"%s\",RTLD_GLOBAL | RTLD_LAZY) due to: %s", soname, dlerror());
2323

24-
printf("[%d] & looking for thefunc in handle %p\n", rank, handle);
24+
if (verbosity > 0) printf("[%d] & looking for thefunc in handle %p\n", rank, handle);
2525
func = dlsym(handle,"thefunc");
2626
if (!func) ERR("dlsym could not find symbol \"thefunc\" due to: %s", dlerror());
2727

28-
printf("[%d] & found thefunc at address %p\n", rank, func);
29-
err = (*func)();CHK(err);
28+
if (verbosity > 0) printf("[%d] & found thefunc at address %p\n", rank, func);
29+
err = (*func)(verbosity);CHK(err);
3030

3131
err = dlclose(handle);
3232
if (err) ERR("dlclose failed due to: %s", dlerror());
@@ -35,18 +35,38 @@ int run_tests(const char *soname)
3535

3636
int main(int argc, char *argv[])
3737
{
38-
int err;
38+
int err,verbosity,rank,size;
39+
double tstart,tend,elapsed;
3940
char path[MAXPATHLEN];
4041

4142
MPI_Init(&argc,&argv);
42-
collfs_initialize(2, NULL);
43+
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
44+
MPI_Comm_size(MPI_COMM_WORLD,&size);
45+
if (argc == 2) {
46+
verbosity = atoi(argv[1]);
47+
}
48+
collfs_initialize(verbosity, NULL);
4349

4450
if (!getcwd(path,sizeof path)) ERR("getcwd failed");
4551
strcat(path,"/libminimal_thefunc.so");
4652

53+
tstart = MPI_Wtime();
4754
collfs_comm_push(MPI_COMM_WORLD);
48-
err = run_tests(path);CHK(err);
55+
err = run_tests(verbosity,path);CHK(err);
4956
collfs_comm_pop();
57+
tend = MPI_Wtime();
58+
elapsed = tend - tstart;
59+
if (verbosity > 1) printf("[%d] elapsed = %g\n",rank,elapsed);
60+
{
61+
struct {double time; int rank; } loc,gmax,gmin;
62+
double gsum;
63+
loc.time = elapsed;
64+
loc.rank = rank;
65+
MPI_Reduce(&loc,&gmax,1,MPI_DOUBLE_INT,MPI_MAXLOC,0,MPI_COMM_WORLD);
66+
MPI_Reduce(&loc,&gmin,1,MPI_DOUBLE_INT,MPI_MINLOC,0,MPI_COMM_WORLD);
67+
MPI_Reduce(&elapsed,&gsum,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);
68+
if (!rank) printf("NumProcs %d Min %g@%d Max %g@%d Ratio %g Ave %g\n",size,gmin.time,gmin.rank,gmax.time,gmax.rank,gmax.time/gmin.time,gsum/size);
69+
}
5070

5171
collfs_finalize();
5272
MPI_Finalize();

thefunc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include <fcntl.h>
55
#include <stdio.h>
66

7-
int thefunc(void) {
8-
return printf("called %s\n", __func__) <= 0;
7+
int thefunc(int verbosity) {
8+
if (verbosity >= 0) return printf("called %s\n", __func__) <= 0;
9+
return 0;
910
}
1011

1112
int thetest_fxstat64(const char *path) {

thefunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _thefunc_h
22
#define _thefunc_h
33

4-
int thefunc(void);
4+
int thefunc(int);
55
int thetest(const char *path);
66

77
#endif

0 commit comments

Comments
 (0)