Skip to content

Commit 0db33ff

Browse files
committed
Initial multithreaded version.
1 parent 8015279 commit 0db33ff

File tree

6 files changed

+1157
-0
lines changed

6 files changed

+1157
-0
lines changed

pthreads/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Makefile for Jacobi iteration on an adaptive quadtree, pthreads version
3+
#
4+
# Jim Teresco, CSIS-335, Siena College, Fall 2021
5+
#
6+
CFILES = quadtree.c quadtree_solver.c com_abort.c
7+
OFILES = $(CFILES:.c=.o)
8+
CC=gcc
9+
CFLAGS=-g
10+
11+
quadtree_solver: $(OFILES)
12+
$(CC) $(CFLAGS) -o quadtree_solver $(OFILES) -lm -lpthread
13+
14+
quadtree.o: quadtree.h macros.h
15+
quadtree_solver.o: quadtree.h
16+
17+
clean::
18+
/bin/rm -f quadtree_solver $(OFILES)

pthreads/com_abort.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
com_abort.c, based on version from
3+
4+
Parallel Communications Library
5+
6+
Jim Teresco
7+
8+
Rensselaer Polytechnic Institute
9+
Department of Computer Science
10+
Scientific Computation Research Center
11+
12+
Adapted from PMDB, JDT, Wed Nov 22 15:36:53 EST 1995
13+
14+
Last change:
15+
Mon Nov 27 15:08:24 EST 1995
16+
17+
$Id$
18+
$Log: com_abort.c,v $
19+
Revision 1.1 2006/03/06 05:28:23 terescoj
20+
First prelim version
21+
22+
Revision 1.1.1.1 2002/06/15 01:04:29 terescoj
23+
CVSing scorec util library
24+
25+
Revision 1.2 2000/08/14 19:02:23 oklaas
26+
update to latest version of com
27+
28+
Revision 1.1.1.1 1996/12/18 14:53:28 jteresco
29+
initial sources
30+
31+
*/
32+
33+
#include <stdio.h>
34+
#include <stdlib.h>
35+
36+
void com_abort(char *function, char *msg) {
37+
38+
if (function || msg) {
39+
fflush(stdout);
40+
fprintf(stderr,"ABORT in %s!\n",function);
41+
if (msg)
42+
fprintf(stderr," ErrMsg: %s\n",msg);
43+
}
44+
abort();
45+
}

pthreads/macros.h

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
macros.h
3+
4+
Based on util_macros originally written by
5+
6+
Louis Ziantz
7+
Jim Teresco
8+
9+
Rensselaer Polytechnic Institute
10+
Department of Computer Science
11+
Scientific Computation Research Center
12+
13+
Macros which are generally useful.
14+
15+
Created:
16+
Wed Nov 29 17:05:11 EST 1995
17+
18+
Last change:
19+
Mon Jan 22 13:02:18 EST 1996
20+
21+
$Id$
22+
23+
Modification History
24+
07/16/1998 Added in FIELD_SET and OUTPUT_IN_ORDER from pmdb
25+
*/
26+
27+
#ifndef __H_MACROS
28+
#define __H_MACROS
29+
30+
#include <stdlib.h>
31+
#include <stdio.h>
32+
#include <errno.h>
33+
34+
#ifndef FALSE
35+
#define FALSE 0
36+
#endif
37+
#ifndef TRUE
38+
#define TRUE 1
39+
#endif
40+
41+
extern void com_abort(char *, char *);
42+
43+
#define SAFE_MALLOC(v,type,size) \
44+
{ v = (type) malloc(size) ; \
45+
if ( v == NULL) { \
46+
fflush(stdout); \
47+
fprintf(stderr,"in file %s, line %d, failed to allocate %ld bytes",\
48+
__FILE__,__LINE__,size); \
49+
com_abort(NULL,NULL); \
50+
} \
51+
}
52+
53+
#define SAFE_REALLOC(v,type,size) \
54+
{ v = (type) realloc(v,size) ; \
55+
if ( v == NULL) { \
56+
fflush(stdout); \
57+
fprintf(stderr,"in file %s, line %d, failed to reallocate %ld bytes",\
58+
__FILE__,__LINE__,size); \
59+
com_abort(NULL,NULL); \
60+
} \
61+
}
62+
63+
#define GRACEFULLY_OPEN(fp, filename, mode) { \
64+
fp = fopen(filename,mode) ; \
65+
if ( fp == NULL ) { \
66+
char msg[FILENAME_MAX+25]; \
67+
sprintf(msg, "Could not open file %s.\n", filename); \
68+
perror(" fopen"); \
69+
com_abort("GRACEFULLY_OPEN", msg); \
70+
} \
71+
}
72+
73+
#define FILE_EXISTS(fp,filename) \
74+
( ((fp = fopen(filename,"r")) != NULL) \
75+
? (! fclose(fp)) /* TRUE */ : FALSE)
76+
77+
/*
78+
* Macro for checking return from fprintf
79+
*
80+
* Should only be used if routine doesn't need to clean up before
81+
* returning. Calling routine should decare "int ret=0;" and do a
82+
* "return(ret)" at the end. This should not be used in main, as it
83+
* will result in the program terminating and returning 0 on failure.
84+
*
85+
*/
86+
87+
#define SAFE_FPRINTF if (ret==EOF) return(0); else ret=fprintf
88+
89+
/*
90+
* Macro for checking return from fclose
91+
*
92+
* Should only be used if routine doesn't need to clean up before
93+
* returning. Calling routine must return an int, 0 for failure.
94+
* It is the caller's repsonsibility to abort if necessary.
95+
*
96+
*/
97+
98+
99+
#define SAFE_FCLOSE(fp, fname) \
100+
if (fclose(fp)) { \
101+
fprintf(stderr,"error closing file %s\n",fname); \
102+
perror(" fclose"); \
103+
return(0); \
104+
}
105+
106+
#define GRACEFULLY_CLOSE(fp, fname) \
107+
if (fclose(fp)) { \
108+
char msg[FILENAME_MAX+25]; \
109+
sprintf(msg,"Error closing file %s\n",fname); \
110+
perror(" fclose"); \
111+
com_abort("GRACEFULLY_CLOSE", msg); \
112+
}
113+
114+
#define ASSERT(cond) \
115+
if (!(cond)) { \
116+
fflush(stdout); \
117+
fprintf(stderr,"ASSERT failed in file %s at line %d\n", \
118+
__FILE__,__LINE__); \
119+
com_abort(NULL,NULL); \
120+
}
121+
122+
#define FAIL \
123+
fflush(stdout); \
124+
fprintf(stderr,"FAIL in file %s at line %d\n", \
125+
__FILE__,__LINE__); \
126+
com_abort(NULL,NULL)
127+
128+
/* do not add anything below this line! */
129+
#endif /* __H_MACROS */

0 commit comments

Comments
 (0)