Skip to content

Commit 335c9a0

Browse files
committed
fix mcxlab crash due to racing in multi-thread, close #60
1 parent 139bad8 commit 335c9a0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/mcx_utils.h

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include "float.h"
3434
#include "nifti1.h"
3535

36+
#ifdef _OPENMP ///< use multi-threading for running simulation on multiple GPUs
37+
#include <omp.h>
38+
#endif
39+
3640
#define EPS FLT_EPSILON /**< round-off limit */
3741
#define VERY_BIG (1.f/FLT_EPSILON) /**< a big number */
3842

@@ -260,7 +264,11 @@ extern "C"
260264
#endif
261265

262266
#ifdef MCX_CONTAINER
267+
#ifdef _OPENMP
268+
#define MCX_FPRINTF(fp,...) {if(omp_get_thread_num()==0) mexPrintf(__VA_ARGS__);}
269+
#else
263270
#define MCX_FPRINTF(fp,...) mexPrintf(__VA_ARGS__)
271+
#endif
264272
#else
265273
#define MCX_FPRINTF(fp,...) fprintf(fp,__VA_ARGS__)
266274
#endif

0 commit comments

Comments
 (0)