Essays
Topics
Writing Tool
Machine Learning AI
ChatGPT
US History
Presidents of the United States
Joseph Robinette Biden
Donald Trump
Barack Obama
US States
States Ranked by Size & Population
States Ranked by Date
IPL
>
Electrical Engineering
>
2023.pdf
2023
.pdf
School
The University of Hong Kong
*
*We aren't endorsed by this school
Course
ELEC 3543
Subject
Electrical Engineering
Date
Dec 20, 2024
Pages
8
Uploaded by PresidentCoyote3454
THE
UNIVERSITY
OF
HONG
KONG
Bachelor
of
Engineering
Department
of
Electrical
&
Electronic
Engineering
ELEC3543
Advanced
Systems
Programming
Examination
Date:
13
December
2023
__
Time:
—2:30pm-5:30pm___
Answer
ALL
questions.
Use
of
Electronic
Calculators:
“Only
approved
calculators
as
announced
by
the
Examinations
Secretary
can
be
used
in
this
examination.
It
is
candidates’
responsibility
to
ensure
that
their
calculator
operates
satisfactorily,
and
candidates
must
record
the
name
and
type
of
the
calculator
used
on
the
front
page
of
the
examination
script.”
EEE/ELEC3543/
2023
Dec
page
1
of
8
Question
1.
(36
marks)
(a)
The
following
Python
program
is
a
slightly
modified
version
of
the
sample
program
as
discussed
in
the
Mod-3
notes
to
create
an
object
of
the
qm_molecule
class
as
extended
from
the
atom
class,
and
then
display
the
involved
objects.
Class
atom(object):
def
init
(self,atno,x,y,z):
self.atno
=
atno
self.position
=
(x,y,z)
def
repr
(self):
a
#
A
missing
statement
here
!
#
Define
the
extended
qm
molecule
class
#
and
also
the
addbasis
method
here
vestesees
.
#
A
few
missing
statements
here
!
atom(6,
O.1,
1.1,
2.3)
V
atom(8,
-1.2,
2.4,
3.7)
Z
atom(ll,
0.5,
1.3,
1.9)
gqml
=
qm
molecule(-1,
0.66,
2.7,
1.99)
gml.atomlist
=
[x,
y,
2]
qml.addbasis()
print
(x)
print
(y)
print
(z)
|
(
xX
print
(qm1)
print
(qml.basis)
Inside
the
addbasis
method,
each
atom
object
of
the
atomlist
will
be
added
into
the
basis
list
that
is
initialized
as
an
empty
list
in
the
beginning.
Clearly
state
ALL
the
missing
statements
ONLY
to
complete
the
above
Python
program
so
that
the
following
output
will
be
produced.
$
python3
Ola.py
6
0.1000
J1.1000
2.3000
8
-1.2000
2.4000
3.7000
11
0.5000
1.3000
1.9000
-1
0.6600
2.7000
1.9900
[6
0.1000
1.1000
2.3000,8
-1.2000
2.4000
3.7000,11
0.5000
1.3000
1.9000]
(12
marks)
(b)
The
above
program
output
by
executing
“OJa.py”
is
re-directed
to
a
text
file
named
“QM
_
Molecules.log”
under
the
current
directory.
With
the
following
program
fragment
on
socket
programming
in
Python,
EEE/ELEC3543/
2023
Dec
|
page
2
of
8
#
A
Simple
TCP
Client/Server
Program
import
socket
HOST
PORT
'127.0.0.1'
#
The
client/server's
IP
address
65332
#
The
port
used
by
client/server
#
Some
Missing
statements
here
!
a
student
enrolled
in
ELEC
3543
successfully
implements
both
TCP
client
and
server
programs
in
Python
in
which
the
TCP
client
program
reads
each
line
from
the
“OM
Molecules.log”
under
the
current
directory,
and
sends
the
line
via
its
constructed
TCP
socket
to
the
local
TCP
server.
On
the
other
hand,
the
local
TCP
server
program
receives
each
text
line
sent
by
the
TCP
client
program
via
the
TCP
socket,
and
then
display
the
received
text
line
on
the
standard
output.
Based
on
the
above
program
fragment,
clearly
state
ALL
the
missing
statements
ONLY
to
complete
BOTH
TCP
client
and
server
programs
so
that
the
following
output
will
be
produced
on
the
same
host
machine.
$
python3
O1lb
Sock
Prog
TCP_Server.py
Connected
by
('127.0.0.1',
54662)
6
0.1000
1.1000
2.3000
8
-1.2000
2.4000
3.7000
Il
0.5000
1.3000
1.9000
-l
0.6600
2.7000
1.9900
[6
0.1000
1.1000
2.3000,8
-1.2000
2.4000
3.7000,
11
0.5000
1.3000
1.9000]
|
$
python3
Olb_
Sock_Prog
TCP_Client.py
(24
marks)
EEE/ELEC3543/
2023
Dec
page
3
of
8
Question
2.
(28
marks)
(a)
Concurrency
can
be
useful
to
handle
two
major
types
of
problems.
Clearly
define
each
type
of
the
problems
with
the
aid
of
a
diagram.
Besides,
explain
how
concurrency
may
help
in
each
case.
(10
marks)
(b)
Detail
the
reason(s)
why
the
latest
trends
of
network
services
is
implemented
by
multi-threading
rather
than
multi-processing.
(6
marks)
(c)
The
following
GPU
program
was
executed
on
the
Google
Colaboratory
(Colab)
platform.
from
numba
import
vectorize
import
numpy
as
npy
@vectorize(['float32(float32,
Float32)'],
target='cuda')
def
add_unifunc(i,
4):
reCurn
2
+
4
n
=
121200
a
=
npy.arange(n).astype(npy.float32)
b=3
*
a
S6timeit
add
unifunc(a,b)
Yet
the
Google
Colab
returns
with
an
error
message
as
“CudaSupportError:
Error
at
driver
init:”.
Clearly
explain
the
underlying
reason(s)
for
such
error,
and
suggest
one
possible
solution
to
fix
the
problem.
Besides,
using
the
“device
memory”
under
the
CUDA
programming
model
as
discussed
in
the
Mod-8
notes,
modify
the
above
GPU
program
to
enhance
its
time
performance.
Clearly
show
your
code
modifications
(i.e.
simply
highlighting
the
*code
changes*
without
copying
the
whole
program)
in
the
answer
book.
(12
marks)
EEE/ELEC3543/
2023
Dec
.
page
4
of
8
Question
3.
(36
marks)
—
A
Revision
on
Essential
Concepts
Carefully
read
each
of
the
following questions
and
write
down
the
most
appropriate
option
in
your
answer
book,
e.g.
1)
X;
2)
Y
where
X
and
Y
are
your
selected
options
for
the
corresponding
questions.
Each
question
carries
3
marks.
I
mark
will
be
deducted
for
any
wrong
answer
_or
multiple
options
provided
to
each
question.
No
mark
will
be
deducted
for
any
blank
answer.
1)
Which
of
the
following
should
be
specified
for
the
JIT
compilation
using
the
Numba
library
?
A.
whether
the
Python
function
is
array-oriented
or
not;
the
maximum
number
of
threads
to
manage
each
data
block;
the
targeted
GPU
model
like
RTX4090;
the
type
signatures
of
the
Python
function;
mo
f
Ff
whether
the
return
type
of
the
Python
function
is
array-oriented
or
not.
2)
What
is
the
expected
output
after
executing
the
following
Python
program
?
a
=
[6.34,
4,
'?']
c
=
(3.46,
8,
'3')
a.insert(2,
Cc)
print
(a)
c=d=a
d
+=
('foo',)
print
(c)
A.
[6.34,
4,
'?"',
(3.46,
8,
'3')]
[6.34,
4,
"?",
(3.46,
8,
"S3'),
"foo']
B.
(6.34,
4,
'?"',
(3.46,
8,
'3"))
(6.34,
4,
'?',
(3.46,
8,
'%S'),
'foo')
C.
[6.34,
4,
(3.46,
8,
'S'),
'?']
[6.34,
4,
(3.46,
8,
'S'),
'?',
'foo']
D.
[6.34,
4,
(3.46,
8,
'S'),
'?"]
(6.34,
4,
(3.46,
8,
'S'),
'?',
'foo')
E.
The
exception
TypeError
is
raised.
EEE/ELEC3543/
2023
Dec
.
page
5
of
8
3)
The
st_ctime
field
of
a
file
as
returned
by
calling
the
os.fstat(...)
function
will
only
be
changed
after
calling
A.
lseek(...);
read(...);
_write(...);
chown(...);
mo
oO
DW
open(...).
4)
How
many
times
will
the
output
line
of
“Inside
the
loop.”
be
displayed
after
executing
the
following
Python
program
?
for
a
in
range(2,
17,
2):
if
a>
9:
a
+=
2?
Continue
a=at+i
print
("Inside
the
loop.")
if
a
==
16:
break
print
("Outside
the
loop.")
3
times;
4
times;
5
times;
6
times;
moO
w
>
7
times.
5)
When
the
link
count
of
an
i-node
is
greater
than
0,
it
means
A.
the
i-node
is
shared
by
one
or
more
processes
under
the
Unix
system;
B.
the
i-node
is
a
symbolic
link;
C.
the
i-node
is
a
virtual
device
file
located
on
block-0
of
the
file-system;
D.
the
i-node
is
actually
a
directory
file;
E.
the
i-node
is
referenced
by
some
directory
of
the
file-system.
EEE/ELEC3543/
2023
Dec
page
6
of
8
6)
The
shared
memory
of
the
CUDA
programming
model
cannot
be
used
for
A.
buffering
output
from
threads
within
the
same
block
for
merging
before
writing
it
back
to
device
memory;
B.
caching
of
lookup
tables
to
be
andonily
accessed;
C.
caching
of
persistent
results
after
a
CUDA
kernel
finishes
its
execution;
D.
staging
data
for
scatter
operations
within
a
block;
E
.
staging
data
for
gather
operations
within
a
block.
7)
A
dual-boot
system
built
on
the
Unix
file-system
is
A.
one
disk
partition
with
two
bootstrap
programs,
a
super
block,
an
i-node
table
and
the
data/directory
blocks;
B.
one
disk
partition
with
multiple
bootstrap
programs,
a
super
block,
an
i-node
table,
the
device
blocks
and
data/directory
blocks;
C.
two
disk
partitions
in
which
each
partition
has
its
own
super
block,
i-node
table
and
data/directory
blocks;
D.
two
disk
partitions
in
which
each
partition
has
its
own
bootstrap
program,
super
block,
i-node
table
and
data/directory
blocks;
E.
one
disk
manager
partition
and
two
bootable
partitions
containing
its
own
process
table,
an
i-node
table,
an
v-node
table
and
the
data/directory
blocks.
8)
Device
functions
in
Numba
are
A.
created
with
the
numba.cuda.device
decorator;
B.
more
efficient
than
universal
functions
in
Numpy;
C.
requiring
all
logics
to
be
put
into
one
single
function;
D.
creating
normal
functions
to
be
only
called
from
other
functions
running
on
the
CPU;
E.
creating
normal
functions
to
be
only
called
from
other
functions
running
on
the
GPU.
9)
For
the
static
innovation
in
CORBA,
the
IDL
compiler
generates
A.
the
client
stub
and
the
server
stub;
B.
the
ORB
agent;
C.
the
client
stub
and
the
server
skeleton;
D.
the
server
object;
E
.
the
response
page
in
XML
to
communicate
with
the
server
object.
EEE/ELEC3543/
2023
Dec
|
page
7
of
8
10)
Which
of
the
following
statements
can
help
to
preserve
the
command
line
arguments
in
a
Python
program
?
A.
arg
=
sys.argv[0]
B.
arg
=
sys.argv[1:]
C.
print
(sys.argv)
D.
SyS.argv.pop()
BE.
SyS.argv.push(‘*END’
)
11)
The
times.process_time()
function
in
Python
returns
A.
the
averaged
wall-clock
execution
time
in
seconds
for
multiple
processes;
B.
the
CPU
time
in
seconds
of
the
current
process:
C.
the
CPU
and
sleep
time
in
seconds
of
the
current
process;
D.
the
CPU
time
in
nanoseconds
of
the
current
process;
E
the
CPU
time
in
microseconds
of
the
current
and
child
processes.
12)
Which
of
the
following
statements
should
be
used
to
Spawn
a
new
thread
for
invoking
a
Python
function
£
without
any
argument
?
A.
thread.start_new
thread(f,
())
-
thread.start
new
thread(f,
[])
B
C.
thread.start_new
thread(f,
{})
D.
thread.start
new
thread(f,
null)
加
.
thread.start_new_thread(f,
argv,
EMPTY
ARGS)
#%*
END
OF
PAPER
**#
EEE/ELEC3543/
2023
Dec
page
8
of
8