468,491 Members | 2,024 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

fseek-fread error

Hi;

I have a c program that uses mpi library to run on parallel arhitecture. First i coded serial program and it worked perfectly. But the parallel one did not run. I found the error but could not solve it.

The error is: the "fseek" and "fread" functions does not return the correct values.
Expand|Select|Wrap|Line Numbers
  1. fseek(wav_fp,40L,SEEK_SET);fread(&str,4,1,wav_fp);
this code must return "str" = "81913" but i get "-442495"

Thanks.
Jan 6 '08 #1
7 5644
weaknessforcats
9,207 Expert Mod 8TB
Are you reading as text or as binary??
Jan 7 '08 #2
Are you reading as text or as binary??
As binary..

In serial version of this code runs true as parallel program with mpi library can not get the right result.
Jan 8 '08 #3
weaknessforcats
9,207 Expert Mod 8TB
Then you have a multithreading race operating.

If this file is a shared resource, you may have to access it within a critical section.
Jan 8 '08 #4
no, it is not multithreading program, it is a parallel program, the fseek's offset value is long type and this is causing segmentation fault problem.
Jan 9 '08 #5
weaknessforcats
9,207 Expert Mod 8TB
I'm sorry but what is the difference between a parallel program and a multi-threaded one??
Jan 9 '08 #6
in parallel programing a processor executes a part of the job, but in multi-thread programming whole job is done by one processor.
Jan 10 '08 #7
weaknessforcats
9,207 Expert Mod 8TB
in parallel programing a processor executes a part of the job, but in multi-thread programming whole job is done by one processor.
This statement is absolutely false.

A parallel program is a program where sections are run in parallel in real time. This requires multiple processors. Each processor runs a section. Each section is called a thread.

A multi-threaded program is a program that can be run as a parallel program. It can also be run using one processsor but only one thread executes at a time. The operating system will multi-task to make it appear that there is more than one processor giving the illusion that the threads are running in parallel.

You have to be certain that any data shared between threads is protected by a critical section, mutex, sempaphore, spin-lock or something that prevents two threads from writing simultaneously to the same resource.
Jan 10 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Leslaw Bieniasz | last post: by
62 posts views Thread by Christopher Benson-Manica | last post: by
15 posts views Thread by TJ Walls | last post: by
20 posts views Thread by Xenos | last post: by
2 posts views Thread by cedarson | last post: by
10 posts views Thread by Kenneth Brody | last post: by
23 posts views Thread by Dmitry Belous | last post: by
6 posts views Thread by ericunfuk | last post: by
13 posts views Thread by thomas.mertes | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.