-
Notifications
You must be signed in to change notification settings - Fork 1
/
enzo.mpi.c
36 lines (33 loc) · 917 Bytes
/
enzo.mpi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <assert.h>
#include <stdio.h>
#include "debug.h"
#include "parallel.mpi.h"
DECLARE_CHANNEL(enzo);
void
exec(const char* fn, const void* buf, size_t n)
{
TRACE(enzo, "write %p to %s: %zu bytes", buf, fn, n);
char fname[256];
FILE* fp;
for(size_t i=0; i < 64; ++i) {
snprintf(fname, 256, "%zu-xvel.%zu", i, rank());
/* try to create the file, but with O_EXCL: i.e. it *must* be created.
* if it actually creates it, we're done. if it fails, keep spinning (up
* to 64 times) as per the loop. */
fp = fopen(fname, "wex");
if(fp) { break; }
}
if(fp == NULL) { return; } /* fuck it, Dude. ... Let's go bowling. */
assert(fp);
if(fwrite(buf, 1, n, fp) != n) {
WARN(enzo, "short write writing %zu-byte field %s!", n, fn);
}
if(fclose(fp) != 0) {
ERR(enzo, "error closing '%s'!", fn);
}
}
void
finish(const char* fn)
{
TRACE(enzo, "done with %s", fn);
}