CriticalSection Count-Variables inconsistent? - deadlock

This was a manual dump. Some people claim that there was a deadlock.
1) !locks says that the OwningThread of my critical section is 19a0, but that thread doesnt even exist? (look at ~ output)
2) EntryCount is 0, so the only thread that ever called EnterCriticalSection was 19a0. ContentionCount is cd(205), which would mean mean that other threads did try to EnterCriticalSection? Are these 2 things not contradictory?
3) RecursionCount is 1, meaning that the thread 19a0 called EnterCriticalSection once initialy, leading to LockCount:0 and RecursionCount:1. How did LockCount reach 8, if RecursionCount is still 1? It would have to be 8 and 9, since i know that EntryCount is 0, which means that only the thread 19a0 called EnterCriticalSection those 8 times?
4) 8 different threads show in their kb output:
02 00007ff8`500af83f : 00000146`**ed3502a0** 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlpWaitOnAddress+0xb2.
So how can EntryCount be 0 here? Does WaitOnAdress matter? Or only EnterCriticalSection/EnterCriticalSectionContended?
5) A general explanation of what might have happened in this critical section would be helpful.
0:021> !locks
CritSec +ed3502a0 at 00000146ed3502a0
WaiterWoken No
LockCount 8
RecursionCount 1
OwningThread 19a0
EntryCount 0
ContentionCount cd
*** Locked
0:021> ~
# 0 Id: 10f40.ca10 Suspend: 0 Teb: 00000031`d9312000 Unfrozen
1 Id: 10f40.bcc4 Suspend: 0 Teb: 00000031`d931a000 Unfrozen
2 Id: 10f40.4de4 Suspend: 0 Teb: 00000031`d931c000 Unfrozen
3 Id: 10f40.4b9c Suspend: 0 Teb: 00000031`d931e000 Unfrozen
4 Id: 10f40.b34 Suspend: 0 Teb: 00000031`d9320000 Unfrozen
5 Id: 10f40.12680 Suspend: 0 Teb: 00000031`d9328000 Unfrozen
6 Id: 10f40.f420 Suspend: 0 Teb: 00000031`d932a000 Unfrozen
7 Id: 10f40.7d5c Suspend: 0 Teb: 00000031`d932c000 Unfrozen
8 Id: 10f40.f544 Suspend: 0 Teb: 00000031`d932e000 Unfrozen
9 Id: 10f40.7774 Suspend: 0 Teb: 00000031`d9330000 Unfrozen
10 Id: 10f40.101a0 Suspend: 0 Teb: 00000031`d9332000 Unfrozen
11 Id: 10f40.104e8 Suspend: 0 Teb: 00000031`d9336000 Unfrozen
12 Id: 10f40.135e8 Suspend: 0 Teb: 00000031`d9338000 Unfrozen
13 Id: 10f40.7ad0 Suspend: 0 Teb: 00000031`d9342000 Unfrozen
14 Id: 10f40.113ec Suspend: 0 Teb: 00000031`d9344000 Unfrozen
15 Id: 10f40.7a7c Suspend: 0 Teb: 00000031`d9346000 Unfrozen
16 Id: 10f40.6b18 Suspend: 0 Teb: 00000031`d9354000 Unfrozen
17 Id: 10f40.a414 Suspend: 0 Teb: 00000031`d9356000 Unfrozen
18 Id: 10f40.133b4 Suspend: 0 Teb: 00000031`d935a000 Unfrozen
19 Id: 10f40.11794 Suspend: 0 Teb: 00000031`d935c000 Unfrozen
20 Id: 10f40.4e40 Suspend: 0 Teb: 00000031`d935e000 Unfrozen
. 21 Id: 10f40.8b5c Suspend: 0 Teb: 00000031`d9360000 Unfrozen
22 Id: 10f40.115b4 Suspend: 0 Teb: 00000031`d9362000 Unfrozen
23 Id: 10f40.1f38 Suspend: 0 Teb: 00000031`d9364000 Unfrozen
24 Id: 10f40.e560 Suspend: 0 Teb: 00000031`d9368000 Unfrozen
25 Id: 10f40.1047c Suspend: 0 Teb: 00000031`d92c2000 Unfrozen
26 Id: 10f40.ad40 Suspend: 0 Teb: 00000031`d9214000 Unfrozen
27 Id: 10f40.8e00 Suspend: 0 Teb: 00000031`d9208000 Unfrozen
28 Id: 10f40.af38 Suspend: 0 Teb: 00000031`d9220000 Unfrozen
29 Id: 10f40.c6a4 Suspend: 0 Teb: 00000031`d9222000 Unfrozen
30 Id: 10f40.14114 Suspend: 0 Teb: 00000031`d9224000 Unfrozen

For 1): that thread may have been terminated by an exception or finished normally and someone forgot to implement LeaveCriticalSection.
For 2):
EntryCount is incremented when other threads call EnterCriticalSection()
EntryCount and ContentionCount are never decremented
as documented.
For 3):
The field LockCount is not a true lock count any more, as explained in
this answer. Relevant part:
In Microsoft Windows Server 2003 Service Pack 1 and later versions of Windows, the LockCount field is parsed as follows:
The lowest bit shows the lock status. If this bit is 0, the critical section is locked; if it is 1, the critical section is not locked.
The next bit shows whether a thread has been woken for this lock. If this bit is 0, then a thread has been woken for this lock; if it is 1, no thread has been woken.
The remaining bits are the ones-complement of the number of threads waiting for the lock.
For 4): RtlpWaitOnAddress IMHO is not so useful. There should be some RtlpEnterCriticalSection on the call stack as well. The argument there can be used for the !cs command.
For 5): One of my demos is the following code. It uses an event instead of a critical section, but the result is the same:
#include "stdafx.h"
#include <Windows.h>
#include <process.h>
#include <stdio.h>
#include <iostream>
HANDLE threadA;
HANDLE threadB;
HANDLE eventB;
class WorkItem
{
public:
virtual void Initialize()
{
}
};
unsigned int __stdcall initializeWorkitems(void* param)
{
try
{
// Initialize workitems
WorkItem **items = new WorkItem*[2];
items[0] = new WorkItem();
items[1] = NULL;
for (int i = 0; i<2; i++)
{
items[i]->Initialize();
}
// Signal event for second thread to work on work items
SetEvent(eventB);
}
catch(...)
{
// Don't do this
}
return 0;
}
unsigned int __stdcall processWorkitems(void* param)
{
// Wait for work item initialization to complete
WaitForSingleObject(eventB, INFINITE);
// Work on workitems
Sleep(100);
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
eventB = CreateEvent(0, 0, 0, 0);
threadA = (HANDLE)_beginthreadex(0, 0, &initializeWorkitems, (void*)0, 0, 0);
threadB = (HANDLE)_beginthreadex(0, 0, &processWorkitems, (void*)0, 0, 0);
WaitForSingleObject(threadA, INFINITE);
WaitForSingleObject(threadB, INFINITE);
CloseHandle(threadA);
CloseHandle(threadB);
CloseHandle(eventB);
return 0;
}

Related

QML how to use a dynamic topmargin correctly

I want to enlarge or reduce a button depending on the presence of an icon. The buttons are in a rectangle and I would like to realize it with the top margin, because the buttons also have rounded corners and only the top corners should be visible.
The goal is a representation like this
If I set the topmargin fix to 10 it looks good
If I calculate the value depending on whether an icon is present, the buttons without icon are correctly displayed deeper, but the buttons with icon sit too deep
Like the picture before the topmargin for the icon buttons is 10 but they are moved lower.
Any idea - the code for display.qml is reduced and does not show all the properties. if they are needed i will add them.
FooterButton.qml
Rectangle {
id: button
property string p_identity
property string p_icon
property string p_source
property string p_backgroundColor
property int p_topmargin: 10
height: 70
width: 80
Layout.leftMargin: 25
Layout.topMargin: p_topmargin
color: p_backgroundColor
radius: 10
border.color: "black"
border.width: 0
Connections {
target: m_screen;
onScreenChanged: {
p_icon = m_screen.getButtonIcon(p_identity)
p_source = (!p_icon || p_icon.length === 0) ? "" : "image://iconprovider/" + p_icon)
// p_topmargin = 10
p_topmargin = (!p_icon || p_icon.length === 0) ? 45 : 10
}
}
Footer.qml
Item {
id: footer
property string p_footerBackgroundColor: "yellow" //m_config.getColor(Colors.FooterBackground)
property string p_buttonBackgroundColor: m_config.getColor(Colors.ButtonBackground)
Rectangle { anchors.fill: parent; x: footer.x; y: footer.y; width: footer.width; height: footer.height; color: p_footerBackgroundColor
RowLayout{ anchors.fill: parent
FooterButton{ p_identity: "FB1"; p_backgroundColor: p_buttonBackgroundColor }
FooterButton{ p_identity: "FB2"; p_backgroundColor: p_buttonBackgroundColor }
FooterButton{ p_identity: "FB3"; p_backgroundColor: p_buttonBackgroundColor }
FooterButton{ p_identity: "FB4"; p_backgroundColor: p_buttonBackgroundColor }
FooterButton{ p_identity: "FB5"; p_backgroundColor: p_buttonBackgroundColor }
}
}
Display.qml
Item {
id: display
Header { x: 0; y: 0; width: display.width; height: p_headerHeight; visible: p_headerVisible; color: p_backgroundColor; p_buttonColor: p_buttonBackgroundColor }
Left { x: 0; y: p_headerHeight; width: p_borderWidth; height: p_contentHeight; color: "blue" }
Right { x: display.width - p_encoderWidth; y: p_headerHeight; width: p_encoderWidth; height: p_contentHeight; p_color: "magenta" }
Footer { x: 0; y: display.height - p_footerHeight; width: display.width; height: p_footerHeight; visible: p_footerVisible }
just making sure you're not over-engineering your problem, but, I want to point out that the standard Button has both icon support and the ability to change the background to a rounded Rectangle:
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Page {
footer: Frame {
background: Rectangle {
color: "yellow"
}
RowLayout {
anchors.horizontalCenter: parent.horizontalCenter
spacing: 20
AppButton {
//icon.source: "hammer.svg"
}
AppButton {
//icon.source: "hammer.svg"
}
AppButton {
icon.source: "hammer.svg"
}
AppButton {
//icon.source: "hammer.svg"
}
AppButton {
icon.source: "check.svg"
}
}
}
}
// AppButton.qml
import QtQuick
import QtQuick.Controls
Button {
width: 100
height: 100
background: Rectangle {
color: pressed ? palette.mid : palette.button
radius: 20
}
icon.source: "blank.svg"
icon.width: 64
icon.height: 64
}
// blank.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
</svg>
// hammer.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M29.64 25.462c-1.186-1.62-3.535-4.176-6.254-7.136-2.657-2.893-5.671-6.173-8.066-9.11a3.883 3.883 0 0 1-1.044-1.531 6.899 6.899 0 0 0-.215-1.271 3.427 3.427 0 0 1-.08-.348 7.985 7.985 0 0 1 3.153-1.61 25.43 25.43 0 0 1 4.095-.527l1.08-.043-1.14-1.239-.148-.035a24.293 24.293 0 0 0-5.123-.606A13.096 13.096 0 0 0 7.53 4.82c-.225.2-1.433 1.478-1.338 2.334.078.73-.212.949-.792 1.383a8.35 8.35 0 0 0-.558.444c-1.468-.125-1.92.252-3.014 1.16l-.39.32-.095.105a1.472 1.472 0 0 0-.277 1.24 7.214 7.214 0 0 0 2.294 3.029 2.25 2.25 0 0 0 2.404-.483 18.003 18.003 0 0 0 1.577-2.018 2.67 2.67 0 0 1 1.633-1.26 12.815 12.815 0 0 1 2.588.88c.11.046.2.077.277.104.05.018.111.032.116.036 4.108 5.004 6.896 8.936 8.93 11.807 1.401 1.976 2.413 3.404 3.3 4.412l.912 1.038a1.935 1.935 0 0 0 1.362.651l.078.001a1.939 1.939 0 0 0 1.334-.534l1.548-1.486a1.927 1.927 0 0 0 .22-2.52zM12.059 11.028l-.029.034c-.03-.012-.052-.018-.088-.033a10.285 10.285 0 0 0-3-.954 3.577 3.577 0 0 0-2.454 1.738 21.031 21.031 0 0 1-1.375 1.786c-.605.434-.936.519-1.313.338a6.931 6.931 0 0 1-1.792-2.446.85.85 0 0 1 .125-.305l.334-.275c1.045-.867 1.228-1.021 2.299-.933a1.02 1.02 0 0 0 .738-.247A7.72 7.72 0 0 1 6 9.337a2.27 2.27 0 0 0 1.186-2.288A3.785 3.785 0 0 1 8.19 5.571a12.232 12.232 0 0 1 7.706-2.565 20.9 20.9 0 0 1 2.624.178c-.523.076-1.076.173-1.614.298A9.024 9.024 0 0 0 13.34 5.3a1.176 1.176 0 0 0-.25 1.356 5.831 5.831 0 0 1 .19 1.1 3.345 3.345 0 0 0 .842 1.625 9.48 9.48 0 0 0-.994.683 7.036 7.036 0 0 0-1.068.964zm16.668 16.234l-1.547 1.485a.945.945 0 0 1-.678.256.924.924 0 0 1-.652-.312l-.912-1.038c-.853-.97-1.905-2.452-3.236-4.33-2.018-2.848-4.78-6.742-8.838-11.696a6.433 6.433 0 0 1 .875-.772 8.145 8.145 0 0 1 .964-.66l.09-.05C17.14 13 20.06 16.182 22.65 19.001c2.7 2.939 5.032 5.477 6.184 7.051a.923.923 0 0 1-.106 1.209z"/><path fill="none" d="M0 0h32v32H0z"/></svg>
// check.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M13.5 22.142L7.59 16.42l.636-.636L13.5 20.87 26.721 7.8l.637.637z"/><path fill="none" d="M0 0h32v32H0z"/></svg>
You can Try it Online!

GridLayout in QML how to constraint Rectangle in a cell

I am using the below code hoping to set my Rectangle in the top middle of the Item.
import QtQuick 2.0
import QtQuick.Layouts 1.3
Item {
GridLayout {
id: gridLayout
anchors.fill: parent
columns: 5
rows: 7
Rectangle {
id: rectangle
Layout.fillHeight: true
Layout.fillWidth: true
Layout.row: 0
Layout.column: 2
Layout.rowSpan: 1
Layout.columnSpan: 2
color: "#ffffff"
}
}
}
Instead the Rectangle is filling the whole item.
I see so everything is relative in GridLayout and if things don't properly take a specified span then it's a "manure" show.
The following works for me.
import QtQuick 2.0
import QtQuick.Layouts 1.3
Item {
GridLayout {
id: gridLayout
anchors.fill: parent
Rectangle {
id: top_center
Layout.fillHeight: true
Layout.fillWidth: true
Layout.row: 0
Layout.column: 2
Layout.rowSpan: 1
Layout.columnSpan: 1
color: "#ffffff"
}
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.row: 1
Layout.column: 0
Layout.rowSpan: 3
Layout.columnSpan: 1
color: "lightblue"
}
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.row: 1
Layout.column: 1
Layout.rowSpan: 3
Layout.columnSpan: 6
color: "white"
}
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.row: 4
Layout.column: 0
Layout.rowSpan: 1
Layout.columnSpan: 6
color: "lightblue"
}
}
}

What does IM0/1 mean in z80.info decoding?

I am in the process of writing (yet another) Z80 simulator.
I am using the decoding page on the z80.info site.
In the section with the lookup/disssambly tables it says that for index 1 and 5 the Interrupt Mode is IM0/1. This table is referred to from the IM instruction (ED) X=1, Z=6.
What does IM0/1 mean exactly?
I know it's not an official instruction but I am also trying to support undocumented instructions.
As found here, quoting from Gerton Lunter:
The instructions ED 4E and ED 6E are IM 0 equivalents: when FF was put on the bus
(physically) at interrupt time, the Spectrum continued to execute normally, whereas
when an EF (RST 28h) was put on the bus it crashed, just as it does in that case when
the Z80 is in the official interrupt mode 0. In IM 1 the Z80 just executes a RST 38h
(opcode FF) no matter what is on the bus.
So it pretty much means IM 0, and I'm not sure where the commonly seen /1 comes from.
IM0/1/2 are instructions setting the Z80 CPU int interrupt mode 0/1/2. Each mode handles the maskable interrupts differently. Its years I use those but IIRC:
IM0
executes opc placed on databus by external HW
IM1
calls fixed ISR at 38h
IM2
calls ISR from ISR entry point table which is placed where i register points
Here relevant interrupt C++ code extracted from my emulator:
//---------------------------------------------------------------------------
void Z80::_reset()
{
im=0;
iff1=0;
iff2=0;
reg.r16.pc =0x0000;
reg.r16.af =0xFFFF;
reg.r16.bc =0xFFFF;
reg.r16.de =0xFFFF;
reg.r16.hl =0xFFFF;
reg.r16.ix =0xFFFF;
reg.r16.iy =0xFFFF;
reg.r16.ir =0xFFFF;
reg.r16.sp =0xFFFF;
reg.r16._af=0xFFFF;
reg.r16._bc=0xFFFF;
reg.r16._de=0xFFFF;
reg.r16._hl=0xFFFF;
reg.r16.alu=0xFFFF;
reg.r16.mem=0xFFFF;
reg.r16.io =0xFFFF;
reg.r16.nn =0xFFFF;
time=0; time0=0; dtime=0;
busrq=false;
busack=false;
}
//---------------------------------------------------------------------------
void Z80::_int()
{
if (!_enable_int) return;
if (!iff1) return;
if (actual->ins==_z80_ins_HALT) reg.r16.pc+=actual->size;
if ((actual->ins==_z80_ins_EI)||(actual->ins==_z80_ins_DI)) execute();
iff1=0;
iff2=0;
if (im==0)
{
// execute instruction on databus db from peripherials
mc=0;
actual=&ins_int0;
time+=actual->mc[mc]; mc++; // fetch INT
BYTE db[4];
db[0]=db8;
db[1]=db8;
db[2]=db8;
db[3]=db8;
execute(db);
}
else if (im==1)
{
mc=0;
actual=&ins_int1;
time+=actual->mc[mc]; mc++; // fetch INT
_push(reg.r16.pc);
reg.r16.pc=0x0038; // fixed vector 38h
}
else if (im==2)
{
mc=0;
actual=&ins_int2;
time+=actual->mc[mc]; mc++; // fetch INT
_push(reg.r16.pc);
union { BYTE db[2]; WORD dw; } ubw;
ubw.db[1]=reg.r8.i; // H
ubw.db[0]=db8; // L
reg.r16.pc=_readw(ubw.dw); // vector from mem[i+db8]
}
}
//---------------------------------------------------------------------------
void Z80::_nmi()
{
if (actual->ins==_z80_ins_HALT) reg.r16.pc+=actual->size;
if ((actual->ins==_z80_ins_EI)||(actual->ins==_z80_ins_DI)) execute();
iff2=iff1; // iff2 ide do flagov po ld a,i alebo ld a,r
iff1=0;
mc=0;
actual=&ins_nmi;
time+=actual->mc[mc]; mc++; // fetch NMI
_push(reg.r16.pc);
reg.r16.pc=0x0066; // fixed vector 66h
}
//---------------------------------------------------------------------------
Here all the IM instructions in order extracted from here What's the proper implementation for hardware emulation?:
opc T0 T1 MC1 MC2 MC3 MC4 MC5 MC6 MC7 mnemonic
ED46 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM0
ED4E 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM0
ED56 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM1
ED5E 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM2
ED66 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM0
ED6E 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM0
ED76 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM1
ED7E 08 00 M1R 4 M1R 4 ... 0 ... 0 ... 0 ... 0 ... 0 IM2
As you can see its:
IM value: 0 0 1 2 0 0 1 2
And your linked page:
IM value: 0 0/1 1 2 0 0/1 1 2
so I expect it just mean how the opc is encoded but you right the tables there are not very obvious.
The IM0/1 are duplicates of IM0 so I am guessing they were not in original documentation and was discovered only latter ... without the exact behavior knowledge at that time your table was created... There are a lot of originally undocumented (secret) instructions so if your source of info does not contain them accurately maybe you should not use it and move to better docs to avoid problems and incompatibilities in future...

MPI: MPI_Get not working

The following code creates a window in process 0 (master) and the other processes put some values in it and I'm trying to get the window of the master from other processes each time to print it but I'm getting totally confusing results. Here's the code:
int main ( int argc, char *argv[] )
{
int id;
MPI_Init ( &argc, &argv );
MPI_Comm_rank ( MPI_COMM_WORLD, &id );
MPI_Win win;
if (id == 0)
{
int *arr;
int in = 0;
MPI_Alloc_mem(10 * sizeof(int), MPI_INFO_NULL, &arr);
for(in = 1; in < 10; in++)
{
arr[in] = -1;
}
arr[0] = 0;
MPI_Win_create(arr, 10 * sizeof(int), sizeof(int), MPI_INFO_NULL,MPI_COMM_WORLD, &win);
int ready = 0;
while (!ready)
{
MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
ready = fini(arr);
MPI_Win_unlock(0, win);
}
printf("All workers checked in using RMA\n");
MPI_Win_free(&win);
MPI_Free_mem(arr);
printf("Master done\n");
}
else
{
int one = id;
int *local;
int i = 0;
MPI_Alloc_mem(sizeof(int)*10, MPI_INFO_NULL, &local);
MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
for(i = 0; i < 10; i++)
{
MPI_Get(&local[i], 1, MPI_INT, 0, i,1, MPI_INT, win);
}
printf("Worker before %d: ", id);
pt(local); //Printing array "local"
MPI_Put(&one, 1, MPI_INT, 0, id, 1, MPI_INT, win);
for(i = 0; i < 10; i++)
{
MPI_Get(&local[i], 1, MPI_INT, 0, i,1, MPI_INT, win);
}
printf("Worker %d done: ", id);
pt(local);
MPI_Win_unlock(0, win);
MPI_Win_free(&win);
}
MPI_Finalize ( );
return 0;
}
int fini ( int table[] )
{
int i = 0;
while(i < 10)
{
if(table[i] == -1) return 0;
i++;
}
return 1;
}
void pt(int t[])
{
int i = 0;
while(i < 10)
{
printf("%d ",t[i]);
i++;
}
printf("\n");
}
This actually gives me the following result:
Worker before 4: 1152288776 32731 1152288776 32731 4 0 0 0 48 0
Worker 4 done: 1152288776 32731 1152288776 32731 4 0 0 0 48 0
Worker before 1: 1525372936 32743 1525372936 32743 4 0 0 0 48 0
Worker 1 done: 1525372936 32743 1525372936 32743 4 0 0 0 48 0
Worker before 3: 1422645256 32661 1422645256 32661 4 0 0 0 48 0
Worker 3 done: 1422645256 32661 1422645256 32661 4 0 0 0 48 0
Worker before 6: 1553508328 32675 34348016 0 0 0 33 0 1553508280 32675
Worker 6 done: 1553508328 32675 34348016 0 0 0 33 0 1553508280 32675
Worker before 5: -1745405976 32676 33995760 0 0 0 33 0 -1745406024 32676
Worker 5 done: -1745405976 32676 33995760 0 0 0 33 0 -1745406024 32676
Worker before 9: -990742552 32568 20737008 0 0 0 33 0 -990742600 32568
Worker 9 done: -990742552 32568 20737008 0 0 0 33 0 -990742600 32568
Worker before 2: 1455122440 32635 1455122440 32635 4 0 0 0 48 0
Worker 2 done: 1455122440 32635 1455122440 32635 4 0 0 0 48 0
Worker before 7: -1086933016 32650 18463728 0 0 0 33 0 -1086933064 32650
Worker 7 done: -1086933016 32650 18463728 0 0 0 33 0 -1086933064 32650
Worker before 8: 1328670696 32548 24464368 0 0 0 33 0 1328670648 32548
Worker 8 done: 1328670696 32548 24464368 0 0 0 33 0 1328670648 32548
Can you please help me figure out what's wrong with my code ? Thanks.
edit : Apparently the problem is that MPI_Get doesn't fill the "local" buffer...

QML fit screen on all resolutions

Hi all I have problem with my QML code.
I made mistake and I went to put certain size to elements and now I have problem when putting app on other devices.
I will paste you my code where I have width and height so you can change it to show me how to work with dynamic resizeing.
I need to say that I am calling qml file from qt with this code:
QDeclarativeView *view= new QDeclarativeView;
ui->setupUi(this);
setCentralWidget(view);
QDeclarativeContext *ctxt = view->rootContext();
ctxt->setContextProperty("funkcije",this);
ctxt->setContextProperty("myModel", QVariant::fromValue(MainWindow::dataList));
view->setSource(QUrl("qrc:/gui.qml"));
view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
showFullScreen();
And here goes my QML code:
Rectangle {
id:window
width: 602
height: 1000
anchors.fill: parent
radius: 0
.....
ListView {
id: listview1
x: 0
y: 219
// width: 574
// height: 967
width: window.width
height: window.height
visible: true
keyNavigationWraps: false
boundsBehavior: Flickable.DragAndOvershootBounds
opacity: 1
maximumFlickVelocity: 2500
anchors.leftMargin: 0
highlightMoveSpeed: 489
contentWidth: 0
preferredHighlightEnd: 2
spacing: 5
highlightRangeMode: ListView.NoHighlightRange
snapMode: ListView.SnapToItem
anchors.bottomMargin: 0
anchors.rightMargin: 0
anchors.topMargin: 219
anchors.fill: parent
model: myModel
delegate:Component {
//id: contactDelegate
Item {
id:it;
property variant myData: model
width: 574; height: 220
Column {
id:col
x: 12
y: 0
width: 561
height: 164
smooth: true
anchors.rightMargin: 0
anchors.bottomMargin: 7
anchors.leftMargin: 13
anchors.topMargin: 7
anchors.fill: parent
spacing: 15
......
highlight: Rectangle
{
width: 600
height: 222
color:"black"; radius: 5; opacity: 0.7
focus: true
}
}
Rectangle {
id: rectangle1
x: 0
y: 0
width: 602
height: 219
......
//dodaj korisnika
Flipable {
id: flipable
x: 6
y: 32
width: 173
height: 179
.......
MouseArea {
x: 10
y: 9
width: 146
height: 150
anchors.rightMargin: 7
anchors.leftMargin: 10
anchors.topMargin: 9
anchors.bottomMargin: 9
hoverEnabled: false
anchors.fill: parent
........
//Brisanje korisnika
Flipable {
id: flipable1
x: 408
y: 32
width: 175
height: 179
.......
MouseArea {
x: 7
y: 9
width: 153
height: 151
anchors.rightMargin: 8
anchors.leftMargin: 7
anchors.topMargin: 9
anchors.bottomMargin: 8
hoverEnabled: false
anchors.fill: parent
.......
//promjeni korisnika
Flipable {
id: flipable2
x: 208
y: 32
width: 176
height: 179
.......
MouseArea {
x: 7
y: 9
width: 73
height: 76
anchors.rightMargin: 7
anchors.leftMargin: 7
anchors.topMargin: 9
anchors.bottomMargin: 9
hoverEnabled: false
anchors.fill: parent
.......
Text {
id: text1
x: 200
y: 212
font.pixelSize: 12
opacity: 0
}
Rectangle {
id: rectangle2
x: 259
y: 510
width: 200
height: 200
color: "#ffffff"
opacity: 0
}
TextInput {
id: text_input1
x: 331
y: 233
width: 80
height: 20
font.pixelSize: 12
opacity: 0
}
Text {
id: text2
x: 136
y: 228
font.pixelSize: 12
opacity: 0
}
Text {
id: text3
x: 152
y: 314
font.pixelSize: 12
opacity: 0
}
Rectangle {
id: rectangle3
x: 256
y: 293
width: 200
height: 200
color: "#ffffff"
opacity: 0
}
Rectangle {
id: rectangle4
x: 339
y: 787
width: 200
height: 200
color: "#ffffff"
opacity: 0
}
Rectangle {
id: rectangle5
x: 270
y: 456
width: 200
height: 200
color: "#ffffff"
opacity: 0
}
TextInput {
id: text_input2
x: 269
y: 316
width: 80
height: 20
font.pixelSize: 12
opacity: 0
}
TextInput {
id: text_input3
x: 269
y: 401
width: 80
height: 20
font.pixelSize: 12
opacity: 0
}
TextInput {
id: text_input4
x: 269
y: 495
width: 80
height: 20
font.pixelSize: 12
opacity: 0
}
TextInput {
id: text_input5
x: 143
y: 465
width: 80
height: 20
text: qsTr("text")
font.pixelSize: 12
opacity: 0
}
states: [
State {
name: "State1"
PropertyChanges {
target: listview1
x: 0
y: 1049
width: 574
height: 967
visible: false
anchors.topMargin: 1049
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
}
PropertyChanges {
target: rectangle1
x: 0
y: 0
width: 602
height: 253
visible: true
}
PropertyChanges {
target: text1
x: 187
y: 253
width: 247
height: 71
color: "#c48d17"
text: qsTr("Unesite novog korisnika")
styleColor: "#e61717"
style: "Raised"
font.pixelSize: 31
font.family: "Lucida Handwriting"
verticalAlignment: "AlignVCenter"
horizontalAlignment: "AlignHCenter"
opacity: 1
}
PropertyChanges {
target: rectangle2
x: 251
y: 353
width: 258
height: 42
color: "#777e79"
radius: 15
smooth: true
opacity: 1
}
PropertyChanges {
target: text_input1
x: 251
y: 360
width: 258
height: 29
font.pixelSize: 17
font.family: "Lucida Handwriting"
horizontalAlignment: "AlignHCenter"
opacity: 1
}
PropertyChanges {
target: text2
x: 127
y: 362
width: 101
height: 25
color: "#fd0606"
text: qsTr("Ime")
style: "Raised"
font.family: "Lucida Handwriting"
font.pixelSize: 22
verticalAlignment: "AlignVCenter"
horizontalAlignment: "AlignHCenter"
opacity: 1
}
PropertyChanges {
target: text3
x: 119
y: 519
color: "#f70606"
text: qsTr("Prezime")
style: "Raised"
font.pixelSize: 20
font.family: "Lucida Handwriting"
verticalAlignment: "AlignVCenter"
horizontalAlignment: "AlignHCenter"
opacity: 1
}
PropertyChanges {
target: rectangle3
x: 251
y: 514
width: 258
height: 40
color: "#777e79"
radius: 15
opacity: 1
}
PropertyChanges {
target: rectangle4
x: 251
y: 669
width: 258
height: 38
color: "#777e79"
radius: 15
opacity: 1
}
PropertyChanges {
target: rectangle5
x: 251
y: 823
width: 258
height: 36
color: "#777e79"
radius: 15
opacity: 1
}
PropertyChanges {
target: text_input2
x: 251
y: 519
width: 258
height: 29
font.family: "Lucida Handwriting"
font.pixelSize: 17
horizontalAlignment: "AlignHCenter"
opacity: 1
}
PropertyChanges {
target: text_input3
x: 251
y: 674
width: 258
height: 29
horizontalAlignment: "AlignHCenter"
font.pixelSize: 17
font.family: "Lucida Handwriting"
opacity: 1
}
PropertyChanges {
target: text_input4
x: 251
y: 827
width: 258
height: 29
font.family: "Lucida Handwriting"
font.pixelSize: 17
horizontalAlignment: "AlignHCenter"
opacity: 1
}
PropertyChanges {
target: text4
x: 127
y: 669
width: 85
height: 31
color: "#f70606"
text: qsTr("Broj")
style: "Raised"
font.family: "Lucida Handwriting"
font.pixelSize: 20
horizontalAlignment: "AlignHCenter"
verticalAlignment: "AlignVCenter"
opacity: 1
}
]
}
I have put all the code with width and height so you can see what I have done wrong. And please if someone can say me how to make it dynamically fill.
It's unfortunately tricky to get perfect, as it's likely that as the screen size shrinks you might actually want the buttons to be bigger and to drop content from the screen to ensure the user can access and read everything ok.
But the general approach is actually to set a scale factor in the C++ side:
ctxt->setContextProperty("scale", /* put calculated scale factor here */);
And then on the QML side, use that everyone to scale all the objects:
Rectangle {
id:window
width: 602 * scale
height: 1000 * scale
That way you can adjust the scale variable to change everything's size. Having said that, many people end up with different QML files depending on the platform size though.
I recommend you read the Scalability page in the current Qt (4.8) documentation: it is on exactly this topic.
It recommends these techniques (I'm quoting the page here), and then supplies much more detail.
Create separate top-level layout definitions for each form factor.
Keep the layouts small and let components scale relative to their
immediate parent.
Define device independent measurements, such as dp (device
independent pixels), and use these to scale components and for layout
measurement.
Define layouts in a proportional way using the built-in layout
features of QML.
Update 2014-11-18 This and video article looks very useful indeed:
Supporting Multiple Screen Sizes & Screen Densities with Qt and V-Play
Update 2017-01-24 There is an updated Qt 5.8 version of the Scalability page mentioned above.
Changing the device, you are actually changing the screen pixel density. If you have a device with low quality display it will have lower number of pixels per inch or pixels per centimeter than a device with high quality display.
Understanding this we can easily devise a method to scale our content according to the pixel density. For example in my case I have a laptop on which I use Qt creator. It has pixel density of 4. But my android phone is of high quality which has density of 16(4 times more than my Laptop). It means if an item has a width 'X' and height 'Y' when displaying on my Laptop, on my phone it will appear with a width 'X'/4 and height 'Y'/4 . Thus I have to scale height and width by 4.
Now, How to implement this? In QML we have a property "pixelDensity" under object Screen which will give you the pixel density of the screen where you are running your application. Dividing this by the screen density of screen where you tested your application will give you the scale factor. So now you don't need to worry about other devices you have just find the pixel density of screen you are currently working on.
Following code works perfectly for me.
property int default_pix_density: 4 //pixel density of my current screen
property int scale_factor: Screen.pixelDensity/default_pix_density
Rectangle
{
width: 50*scale_factor
height: 20*scale_factor
}

Resources